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