1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#
# This should look for tags of the form
# Format tags
# {\i foo} - italic
# {\b foo} - bold
#
# Type tags (unlinked)
# {\func foo} - function
# {\class foo} - class
# {\enum foo} - enum
# {\macro foo} - macro
# {\type foo} - parameter type
# {\var foo} - parameter variable
# {\key foo} - keyword
#
# Link tags
# {\link foo html} - hyperlink
# {func()} - hyperlink to function func
# {class::func()} - hyperlink to function class::func
# {varaible} - hyperlink to variable
# {varaible.feild} - hyperlink to field
# {class::} - hyperlink to class
#
# {\example text} - include an example {} must match
sub plugin {
my $desc=shift;
my $obj=shift;
my @inter;
my @out;
my @stack;
$desc=~s/&/&/g;
# $desc=~s/</</g; ## mbn -- commented out because we use tags in documentation.
# $desc=~s/>/>/g;
$desc=~s/\{\\link\s+([^}]+)\s+(\S+)\s*}/<a href="$2">$1<\/a>/g;
foreach (split(/(\{[:A-Za-z_][:A-Za-z_0-9]*\(\)\})|(\{[:A-Za-z_][:.A-Za-z_0-9]*\})/,$desc) ) {
next if (/^$/);
if ( /\{([A-Za-z_][:A-Za-z_0-9]*)\(\)\}/) {
my $i=$obj->lookdown($1);
if ($i) {
push(@inter,$i->href());
} else {
my $name=$1;
if ( $name =~ /::/) {
$name=~/^(.*)::([^:]*)$/;
push(@inter,"<tt>${Html::CLASS}$1${Html::CLASS_}::${Html::FUNCTION}$2${Html::FUNCTION_}</tt>");
} else {
push(@inter,"${Html::FUNCTION}$2${Html::FUNCTION_}");
}
}
} elsif ( /\{([A-Za-z_][:A-Za-z_0-9]*)::\}/) {
my $i=$obj->lookdown($1);
if ($i) {
if ( /::/ ) {
push(@inter,$i->full_href());
} else {
push(@inter,$i->href());
}
} else {
push(@inter,"<tt>${Html::CLASS}$1${Html::CLASS_}</tt>");
}
} elsif ( /\{([A-Za-z_][:A-Za-z_0-9]*)\}/) {
push(@inter,"<tt>${Html::VARIABLE}$1${Html::VARIABLE_}</tt>");
} else {
push(@inter,$_);
}
}
$desc=join("",@inter);
@inter=("");
foreach (split(/({\\\S+\s)|({)|(})/,$desc)) {
next if (/^$/);
if ( /^{\\i\s$/ ) {
push (@inter,${Html::ITAL});
push (@stack,${Html::ITAL_});
} elsif ( /^{\\b\s$/ ) {
push (@inter,${Html::BOLD});
push (@stack,${Html::BOLD_});
} elsif ( /^{\\key\s$/ ) {
push (@inter,${Html::KEYWORD});
push (@stack,${Html::KEYWORD_});
} elsif ( /^{\\func\s$/ ) {
push (@inter,${Html::FUNC});
push (@stack,${Html::FUNC_});
} elsif ( /^{\\class\s$/ ) {
push (@inter,${Html::CLASS});
push (@stack,${Html::CLASS_});
} elsif ( /^{\\enum\s$/ ) {
push (@inter,${Html::ENUM});
push (@stack,${Html::ENUM_});
} elsif ( /^{\\macro\s$/ ) {
push (@inter,${Html::MACRO});
push (@stack,${Html::MACRO_});
} elsif ( /^{\\var\s$/ ) {
push (@inter,${Html::VARIABLE});
push (@stack,${Html::VARIABLE_});
} elsif ( /^{\\type\s$/ ) {
push (@inter,${Html::TYPE});
push (@stack,${Html::TYPE_});
} elsif ( /^{\\example\s$/ ) {
push (@inter,"<pre>");
push (@stack,"</pre>");
} elsif ( /^{\\/ ) {
print STDERR "unknown directive $_\n";
} elsif ( /^{$/ ) {
push (@inter,"{");
push (@stack,"}");
} elsif ( /^}$/ ) {
if (@stack) {
push (@inter, pop(@stack));
} else {
push(@inter, "}");
}
} else {
push (@inter,$_);
}
}
$desc=join("",@inter);
foreach (split(/\n/,$desc)) {
push (@out,$_);
}
return join("\n",@out);
}
|