1 Since some preprocessor directives insert raw HTML, it would be good to
2 specify, per-format, how to pass HTML so that it goes through the format
3 OK. With Markdown we cross our fingers; with reST we use the "raw"
6 I added an extra named parameter to the htmlize hook, which feels sort of
7 wrong, since none of the other hooks take parameters. Let me know what
10 Seems fairly reasonable, actually. Shouldn't the `$type` come from `$page`
11 instead of `$destpage` though? Only other obvious change is to make the
12 escape parameter optional, and only call it if set. --[[Joey]]
14 > I couldn't figure out what to make it from, but thinking it through,
15 > yeah, it should be $page. Revised patch follows. --Ethan
17 >> I've updated the patch some more, but I think it's incomplete. ikiwiki
18 >> emits raw html when expanding WikiLinks too, and it would need to escape
19 >> those. Assuming that escaping html embedded in the middle of a sentence
22 >>> Revised again. I get around this by making another hook, htmlescapelink,
23 >>> which is called to generate links in whatever language. In addition, it
24 >>> doesn't (can't?) generate
25 >>> spans, and it doesn't handle inlineable image links. If these were
26 >>> desired, the approach to take would probably be to use substitution
27 >>> definitions, which would require generating two bits of code for each
28 >>> link/html snippet, and putting one at the end of the paragraph (or maybe
30 >>> To specify that (for example) Discussion links are meant to be HTML and
31 >>> not rst or whatever, I added a "genhtml" parameter to htmllink. It seems
32 >>> to work -- see <http://ikidev.betacantrips.com/blah.html> for an example.
38 Index: debian/changelog
39 ===================================================================
40 --- debian/changelog (revision 3197)
41 +++ debian/changelog (working copy)
43 than just a suggests, since OpenID is enabled by default.
44 * Fix a bug that caused link(foo) to succeed if page foo did not exist.
45 * Fix tags to page names that contain special characters.
46 + * Based on a patch by Ethan, add a new htmlescape hook, that is called
47 + when a preprocssor directive emits inline html. The rst plugin uses this
48 + hook to support inlined raw html.
51 * Use pngcrush and optipng on all PNG files.
52 Index: IkiWiki/Render.pm
53 ===================================================================
54 --- IkiWiki/Render.pm (revision 3197)
55 +++ IkiWiki/Render.pm (working copy)
57 if ($page !~ /.*\/\Q$discussionlink\E$/ &&
58 (length $config{cgiurl} ||
59 exists $links{$page."/".$discussionlink})) {
60 - $template->param(discussionlink => htmllink($page, $page, gettext("Discussion"), noimageinline => 1, forcesubpage => 1));
61 + $template->param(discussionlink => htmllink($page, $page, gettext("Discussion"), noimageinline => 1, forcesubpage => 1, genhtml => 1));
65 Index: IkiWiki/Plugin/rst.pm
66 ===================================================================
67 --- IkiWiki/Plugin/rst.pm (revision 3197)
68 +++ IkiWiki/Plugin/rst.pm (working copy)
70 html = publish_string(stdin.read(), writer_name='html',
71 settings_overrides = { 'halt_level': 6,
72 'file_insertion_enabled': 0,
76 print html[html.find('<body>')+6:html.find('</body>')].strip();
80 hook(type => "htmlize", id => "rst", call => \&htmlize);
81 + hook(type => "htmlescape", id => "rst", call => \&htmlescape);
82 + hook(type => "htmlescapelink", id => "rst", call => \&htmlescapelink);
85 +sub htmlescapelink ($$;@) { #{{{
90 + if ($params{broken}){
91 + return "`? <$url>`_\ $text";
94 + return "`$text <$url>`_";
98 +sub htmlescape ($) { #{{{
101 + return ".. raw:: html\n\n".$html;
104 sub htmlize (@) { #{{{
106 my $content=$params{content};
107 Index: doc/plugins/write.mdwn
108 ===================================================================
109 --- doc/plugins/write.mdwn (revision 3197)
110 +++ doc/plugins/write.mdwn (working copy)
112 The function is passed named parameters: "page" and "content" and should
113 return the htmlized content.
117 + hook(type => "htmlescape", id => "ext", call => \&htmlescape);
119 +Some markup languages do not allow raw html to be mixed in with the markup
120 +language, and need it to be escaped in some way. This hook is a companion
121 +to the htmlize hook, and is called when ikiwiki detects that a preprocessor
122 +directive is inserting raw html. It is passed the chunk of html in
123 +question, and should return the escaped chunk.
127 + hook(type => "htmlescapelink", id => "ext", call => \&htmlescapelink);
129 +Some markup languages have special syntax to link to other pages. This hook
130 +is a companion to the htmlize and htmlescape hooks, and it is called when a
131 +link is inserted. It is passed the target of the link and the text of the
132 +link, and an optional named parameter "broken" if a broken link is being
133 +generated. It should return the correctly-formatted link.
137 hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);
139 * forcesubpage - set to force a link to a subpage
140 * linktext - set to force the link text to something
141 * anchor - set to make the link include an anchor
142 +* genhtml - set to generate HTML and not escape for correct format
146 Index: doc/plugins/rst.mdwn
147 ===================================================================
148 --- doc/plugins/rst.mdwn (revision 3197)
149 +++ doc/plugins/rst.mdwn (working copy)
151 Note that this plugin does not interoperate very well with the rest of
152 ikiwiki. Limitations include:
154 -* reStructuredText does not allow raw html to be inserted into
155 - documents, but ikiwiki does so in many cases, including
156 - [[WikiLinks|WikiLink]] and many
157 - [[PreprocessorDirectives|PreprocessorDirective]].
158 +* Some bits of ikiwiki may still assume that markdown is used or embed html
159 + in ways that break reStructuredText. (Report bugs if you find any.)
160 * It's slow; it forks a copy of python for each page. While there is a
161 perl version of the reStructuredText processor, it is not being kept in
162 sync with the standard version, so is not used.
164 ===================================================================
165 --- IkiWiki.pm (revision 3197)
166 +++ IkiWiki.pm (working copy)
168 my $page=shift; # the page that will contain the link (different for inline)
171 + # we are processing $lpage and so we need to format things in accordance
172 + # with the formatting language of $lpage. inline generates HTML so links
173 + # will be escaped seperately.
174 + my $type=pagetype($pagesources{$lpage});
177 if (! $opts{forcesubpage}) {
178 @@ -494,12 +498,17 @@
180 if (! grep { $_ eq $bestlink } map { @{$_} } values %renderedfiles) {
181 return $linktext unless length $config{cgiurl};
182 - return "<span><a href=\"".
185 - page => pagetitle(lc($link), 1),
190 + page => pagetitle(lc($link), 1),
194 + if ($hooks{htmlescapelink}{$type} && ! $opts{genhtml}){
195 + return $hooks{htmlescapelink}{$type}{call}->($url, $linktext,
198 + return "<span><a href=\"". $url.
199 "\">?</a>$linktext</span>"
203 $bestlink.="#".$opts{anchor};
206 + if ($hooks{htmlescapelink}{$type} && !$opts{genhtml}) {
207 + return $hooks{htmlescapelink}{$type}{call}->($bestlink, $linktext);
209 return "<a href=\"$bestlink\">$linktext</a>";
213 preview => $preprocess_preview,
215 $preprocessing{$page}--;
217 + # Handle escaping html if the htmlizer needs it.
218 + if ($ret =~ /[<>]/ && $pagesources{$page}) {
219 + my $type=pagetype($pagesources{$page});
220 + if ($hooks{htmlescape}{$type}) {
221 + return $hooks{htmlescape}{$type}{call}->($ret);