]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/format_escape.mdwn
7d96d762f17a02d72bd391d0ff746fcc80463467
[ikiwiki.git] / doc / patchqueue / format_escape.mdwn
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" 
4 directive.
5
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 
8 you think. --Ethan
9
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]]
13
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
16
17 <pre>
18 diff -urNX ignorepats ikiwiki/IkiWiki/Plugin/rst.pm ikidev/IkiWiki/Plugin/rst.pm
19 --- ikiwiki/IkiWiki/Plugin/rst.pm       2006-09-25 14:30:40.000000000 -0700
20 +++ ikidev/IkiWiki/Plugin/rst.pm        2007-02-27 22:44:11.040042000 -0800
21 @@ -25,13 +25,19 @@
22  html = publish_string(stdin.read(), writer_name='html',
23         settings_overrides = { 'halt_level': 6,
24                                'file_insertion_enabled': 0,
25 -                              'raw_enabled': 0 }
26 +                              'raw_enabled': 1 }
27  );
28  print html[html.find('<body>')+6:html.find('</body>')].strip();
29  ";
30
31  sub import { #{{{
32 -       hook(type => "htmlize", id => "rst", call => \&htmlize);
33 +       hook(type => "htmlize", id => "rst", call => \&htmlize, escape => \&escape);
34 +} # }}}
35 +
36 +sub escape ($) { #{{{
37 +       my $html = shift;
38 +       $html =~ s/^/  /mg;
39 +       return ".. raw:: html\n\n".$html;
40  } # }}}
41
42  sub htmlize (@) { #{{{
43 diff -urNX ignorepats ikiwiki/IkiWiki/Plugin/shortcut.pm ikidev/IkiWiki/Plugin/shortcut.pm
44 --- ikiwiki/IkiWiki/Plugin/shortcut.pm  2007-02-15 00:38:48.000000000 -0800
45 +++ ikidev/IkiWiki/Plugin/shortcut.pm   2007-02-27 22:09:31.536088000 -0800
46 @@ -13,6 +13,7 @@
47  sub checkconfig () { #{{{
48         # Preprocess the shortcuts page to get all the available shortcuts
49         # defined before other pages are rendered.
50 +       $pagesources{"shortcuts"} = "shortcuts.mdwn";
51         IkiWiki::preprocess("shortcuts", "shortcuts",
52                 readfile(srcfile("shortcuts.mdwn")));
53  } # }}}
54 diff -urNX ignorepats ikiwiki/IkiWiki.pm ikidev/IkiWiki.pm
55 --- ikiwiki/IkiWiki.pm  2007-02-25 15:01:27.211170000 -0800
56 +++ ikidev/IkiWiki.pm   2007-03-01 18:20:39.910925000 -0800
57 @@ -580,6 +577,17 @@
58                                 destpage => $destpage,
59                         );
60                         $preprocessing{$page}--;
61 +                       if ($ret =~ /[<>]/){
62 +                               if ($pagesources{$page}) {
63 +                                       my $type=pagetype($pagesources{$page});
64 +                                       if ($hooks{htmlize}{$type}{escape}) {
65 +                                               $ret = $hooks{htmlize}{$type}{escape}->(
66 +                                                       $ret,
67 +                                               );
68 +                                       }
69 +                               }
70 +                       }
71 +
72                         return $ret;
73                 }
74                 else {
75 </pre>