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