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. This patch is
24 >>> completely untested, sorry. In addition, it 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
33 Index: debian/changelog
34 ===================================================================
35 --- debian/changelog (revision 3182)
36 +++ debian/changelog (working copy)
38 * Fix smiley plugin to scan smileys.mdwn after it's updated, which fixes
39 a bug caused by committing changes to smilies.mdwn.
40 * Fix display of escaped wikilinks containing anchors.
41 + * Based on a patch by Ethan, add a new htmlescape hook, that is called
42 + when a preprocssor directive emits inline html. The rst plugin uses this
43 + hook to support inlined raw html.
46 * Remove stray semicolon in linkmap.pm.
48 -- Joey Hess <joeyh@debian.org> Fri, 06 Apr 2007 17:28:22 -0700
50 Index: IkiWiki/Plugin/rst.pm
51 ===================================================================
52 --- IkiWiki/Plugin/rst.pm (revision 3182)
53 +++ IkiWiki/Plugin/rst.pm (working copy)
55 html = publish_string(stdin.read(), writer_name='html',
56 settings_overrides = { 'halt_level': 6,
57 'file_insertion_enabled': 0,
61 print html[html.find('<body>')+6:html.find('</body>')].strip();
65 hook(type => "htmlize", id => "rst", call => \&htmlize);
66 + hook(type => "htmlescape", id => "rst", call => \&htmlecape);
67 + hook(type => "htmlescapelink", id => "rst", call => \&htmllink);
70 +sub htmllink ($$;@) { #{{{
75 + if ($params{broken}){
76 + return "`? <$url>`_\ $text";
79 + return "`$text <$url>`_";
83 +sub htmlescape ($) { #{{{
86 + return ".. raw:: html\n\n".$html;
89 sub htmlize (@) { #{{{
91 my $content=$params{content};
92 Index: doc/plugins/write.mdwn
93 ===================================================================
94 --- doc/plugins/write.mdwn (revision 3182)
95 +++ doc/plugins/write.mdwn (working copy)
97 The function is passed named parameters: "page" and "content" and should
98 return the htmlized content.
102 + hook(type => "htmlescape", id => "ext", call => \&htmlescape);
104 +Some markup languages do not allow raw html to be mixed in with the markup
105 +language, and need it to be escaped in some way. This hook is a companion
106 +to the htmlize hook, and is called when ikiwiki detects that a preprocessor
107 +directive is inserting raw html. It is passed the chunk of html in
108 +question, and should return the escaped chunk.
112 + hook(type => "htmlescapelink", id => "ext", call => \&htmlescapelink);
114 +Some markup languages have special syntax to link to other pages. This hook
115 +is a companion to the htmlize and htmlescape hooks, and it is called when a
116 +link is inserted. It is passed the target of the link and the text of the
117 +link, and an optional named parameter "broken" if a broken link is being
118 +generated. It should return the correctly-formatted link.
122 hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);
123 Index: doc/plugins/rst.mdwn
124 ===================================================================
125 --- doc/plugins/rst.mdwn (revision 3182)
126 +++ doc/plugins/rst.mdwn (working copy)
128 Note that this plugin does not interoperate very well with the rest of
129 ikiwiki. Limitations include:
131 -* reStructuredText does not allow raw html to be inserted into
132 - documents, but ikiwiki does so in many cases, including
133 - [[WikiLinks|WikiLink]] and many
134 - [[PreprocessorDirectives|PreprocessorDirective]].
135 +* Some bits of ikiwiki may still assume that markdown is used or embed html
136 + in ways that break reStructuredText. (Report bugs if you find any.)
137 * It's slow; it forks a copy of python for each page. While there is a
138 perl version of the reStructuredText processor, it is not being kept in
139 sync with the standard version, so is not used.
141 ===================================================================
142 --- IkiWiki.pm (revision 3182)
143 +++ IkiWiki.pm (working copy)
145 my $page=shift; # the page that will contain the link (different for inline)
148 + my $type=pagetype($pagesources{$page});
151 if (! $opts{forcesubpage}) {
152 @@ -494,12 +495,17 @@
154 if (! grep { $_ eq $bestlink } map { @{$_} } values %renderedfiles) {
155 return $linktext unless length $config{cgiurl};
156 - return "<span><a href=\"".
159 - page => pagetitle(lc($link), 1),
164 + page => pagetitle(lc($link), 1),
168 + if ($hooks{htmlescapelink}{$type}){
169 + return $hooks{htmlescapelink}{$type}->($url, $linktext,
172 + return "<span><a href=\"". $url.
173 "\">?</a>$linktext</span>"
177 $bestlink.="#".$opts{anchor};
180 + if ($hooks{htmlescapelink}{$type}) {
181 + return $hooks{htmlescapelink}{$type}->($bestlink, $linktext);
183 return "<a href=\"$bestlink\">$linktext</a>";
187 preview => $preprocess_preview,
189 $preprocessing{$page}--;
191 + # Handle escaping html if the htmlizer needs it.
192 + if ($ret =~ /[<>]/ && $pagesources{$page}) {
193 + my $type=pagetype($pagesources{$page});
194 + if ($hooks{htmlescape}{$type}) {
195 + return $ret = $hooks{htmlescape}{$type}->($ret);