]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/format_escape.mdwn
web commit by http://ethan.betacantrips.com/: towards reST
[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 <pre>
11 diff -urX ignorepats clean-ikidev/IkiWiki/Plugin/mdwn.pm ikidev/IkiWiki/Plugin/mdwn.pm
12 --- clean-ikidev/IkiWiki/Plugin/mdwn.pm 2007-02-25 12:26:54.031200000 -0800
13 +++ ikidev/IkiWiki/Plugin/mdwn.pm       2007-02-27 21:26:43.556095000 -0800
14 @@ -7,7 +7,12 @@
15  use IkiWiki;
16
17  sub import { #{{{
18 -       hook(type => "htmlize", id => "mdwn", call => \&htmlize);
19 +       hook(type => "htmlize", id => "mdwn", call => \&htmlize, escape => \&escape);
20 +} # }}}
21 +
22 +sub escape ($) { #{{{
23 +       my $html = shift;
24 +       return $html;
25  } # }}}
26
27  my $markdown_sub;
28 diff -urX ignorepats clean-ikidev/IkiWiki/Plugin/rst.pm ikidev/IkiWiki/Plugin/rst.pm
29 --- clean-ikidev/IkiWiki/Plugin/rst.pm  2007-02-25 12:26:54.501830000 -0800
30 +++ ikidev/IkiWiki/Plugin/rst.pm        2007-02-27 22:44:11.040042000 -0800
31 @@ -25,13 +25,19 @@
32  html = publish_string(stdin.read(), writer_name='html',
33         settings_overrides = { 'halt_level': 6,
34                                'file_insertion_enabled': 0,
35 -                              'raw_enabled': 0 }
36 +                              'raw_enabled': 1 }
37  );
38  print html[html.find('<body>')+6:html.find('</body>')].strip();
39  ";
40
41  sub import { #{{{
42 -       hook(type => "htmlize", id => "rst", call => \&htmlize);
43 +       hook(type => "htmlize", id => "rst", call => \&htmlize, escape => \&escape);
44 +} # }}}
45 +
46 +sub escape ($) { #{{{
47 +       my $html = shift;
48 +       $html =~ s/^/  /mg;
49 +       return ".. raw:: html\n\n".$html;
50  } # }}}
51
52  sub htmlize (@) { #{{{
53 diff -urX ignorepats clean-ikidev/IkiWiki/Plugin/shortcut.pm ikidev/IkiWiki/Plugin/shortcut.pm
54 --- clean-ikidev/IkiWiki/Plugin/shortcut.pm     2007-02-25 12:26:54.538830000 -0800
55 +++ ikidev/IkiWiki/Plugin/shortcut.pm   2007-02-27 22:09:31.536088000 -0800
56 @@ -13,6 +13,7 @@
57  sub checkconfig () { #{{{
58         # Preprocess the shortcuts page to get all the available shortcuts
59         # defined before other pages are rendered.
60 +       $pagesources{"shortcuts"} = "shortcuts.mdwn";
61         IkiWiki::preprocess("shortcuts", "shortcuts",
62                 readfile(srcfile("shortcuts.mdwn")));
63  } # }}}
64 diff -urX ignorepats clean-ikidev/IkiWiki.pm ikidev/IkiWiki.pm
65 --- clean-ikidev/IkiWiki.pm     2007-02-25 12:26:58.812850000 -0800
66 +++ ikidev/IkiWiki.pm   2007-02-27 22:09:28.149568000 -0800
67 @@ -568,6 +577,13 @@
68                                 destpage => $destpage,
69                         );
70                         $preprocessing{$page}--;
71 +                       if ($ret =~ /[<>]/){
72 +                               my $type=pagetype($pagesources{$destpage});
73 +                               $ret = $hooks{htmlize}{$type}{escape}->(
74 +                                       $ret,
75 +                               );
76 +                       }
77 +
78                         return $ret;
79                 }
80                 else {
81 </pre>