Convert postprocessordirectives into preprocessordirectives, so they are
expanded before markdown. Consequences: - No need to worry about markdown messing with parameters of preprocessordirectives. (If you had to escape stuff in one before, you'll need to undo that escaping now.) - No need for ugly </p> hacks before inlined subpages. Instead, subpages are wrapped in a <div>, and this prevents markdown from touching them. (This can also be used to add style to subpages.) - rss generation is less of a hack.master
parent
ca57400d53
commit
7a5ae22e5a
|
@ -86,12 +86,11 @@ sub rsspage ($) { #{{{
|
||||||
return $page.".rss";
|
return $page.".rss";
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub postprocess { #{{{
|
sub preprocess ($$) { #{{{
|
||||||
# Takes content to postprocess followed by a list of postprocessor
|
|
||||||
# commands and subroutine references to run for the commands.
|
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
my $content=shift;
|
my $content=shift;
|
||||||
my %commands=@_;
|
|
||||||
|
my %commands=(inline => \&preprocess_inline);
|
||||||
|
|
||||||
my $handle=sub {
|
my $handle=sub {
|
||||||
my $escape=shift;
|
my $escape=shift;
|
||||||
|
@ -146,7 +145,7 @@ sub get_inline_content ($$) { #{{{
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub postprocess_html_inline { #{{{
|
sub preprocess_inline ($@) { #{{{
|
||||||
my $parentpage=shift;
|
my $parentpage=shift;
|
||||||
my %params=@_;
|
my %params=@_;
|
||||||
|
|
||||||
|
@ -177,8 +176,10 @@ sub postprocess_html_inline { #{{{
|
||||||
? "$config{templatedir}/inlinepage.tmpl"
|
? "$config{templatedir}/inlinepage.tmpl"
|
||||||
: "$config{templatedir}/inlinepagetitle.tmpl"));
|
: "$config{templatedir}/inlinepagetitle.tmpl"));
|
||||||
|
|
||||||
|
my @pages;
|
||||||
foreach my $page (blog_list($params{pages}, $params{show})) {
|
foreach my $page (blog_list($params{pages}, $params{show})) {
|
||||||
next if $page eq $parentpage;
|
next if $page eq $parentpage;
|
||||||
|
push @pages, $page;
|
||||||
$template->param(pagelink => htmllink($parentpage, $page));
|
$template->param(pagelink => htmllink($parentpage, $page));
|
||||||
$template->param(content => get_inline_content($parentpage, $page))
|
$template->param(content => get_inline_content($parentpage, $page))
|
||||||
if $params{archive} eq "no";
|
if $params{archive} eq "no";
|
||||||
|
@ -186,7 +187,15 @@ sub postprocess_html_inline { #{{{
|
||||||
$ret.=$template->output;
|
$ret.=$template->output;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "</p>$ret<p>";
|
# TODO: should really add this to renderedfiles and call
|
||||||
|
# check_overwrite, but currently renderedfiles
|
||||||
|
# only supports listing one file per page.
|
||||||
|
if ($config{rss}) {
|
||||||
|
writefile(rsspage($parentpage), $config{destdir},
|
||||||
|
genrss($parentpage, @pages));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub genpage ($$$) { #{{{
|
sub genpage ($$$) { #{{{
|
||||||
|
@ -194,8 +203,6 @@ sub genpage ($$$) { #{{{
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
my $mtime=shift;
|
my $mtime=shift;
|
||||||
|
|
||||||
$content = postprocess($page, $content, inline => \&postprocess_html_inline);
|
|
||||||
|
|
||||||
my $title=pagetitle(basename($page));
|
my $title=pagetitle(basename($page));
|
||||||
|
|
||||||
my $template=HTML::Template->new(blind_cache => 1,
|
my $template=HTML::Template->new(blind_cache => 1,
|
||||||
|
@ -255,10 +262,9 @@ sub absolute_urls ($$) { #{{{
|
||||||
return $content;
|
return $content;
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub genrss ($$$) { #{{{
|
sub genrss ($@) { #{{{
|
||||||
my $content=shift;
|
|
||||||
my $page=shift;
|
my $page=shift;
|
||||||
my $mtime=shift;
|
my @pages=@_;
|
||||||
|
|
||||||
my $url="$config{url}/".htmlpage($page);
|
my $url="$config{url}/".htmlpage($page);
|
||||||
|
|
||||||
|
@ -266,34 +272,15 @@ sub genrss ($$$) { #{{{
|
||||||
filename => "$config{templatedir}/rsspage.tmpl");
|
filename => "$config{templatedir}/rsspage.tmpl");
|
||||||
|
|
||||||
my @items;
|
my @items;
|
||||||
my $isblog=0;
|
foreach my $p (@pages) {
|
||||||
my $gen_blog=sub {
|
|
||||||
my $parentpage=shift;
|
|
||||||
my %params=@_;
|
|
||||||
|
|
||||||
if (! exists $params{show}) {
|
|
||||||
$params{show}=10;
|
|
||||||
}
|
|
||||||
if (! exists $params{pages}) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
$isblog=1;
|
|
||||||
foreach my $page (blog_list($params{pages}, $params{show})) {
|
|
||||||
next if $page eq $parentpage;
|
|
||||||
push @items, {
|
push @items, {
|
||||||
itemtitle => pagetitle(basename($page)),
|
itemtitle => pagetitle(basename($p)),
|
||||||
itemurl => "$config{url}/$renderedfiles{$page}",
|
itemurl => "$config{url}/$renderedfiles{$p}",
|
||||||
itempubdate => date_822($pagectime{$page}),
|
itempubdate => date_822($pagectime{$p}),
|
||||||
itemcontent => absolute_urls(get_inline_content($parentpage, $page), $url),
|
itemcontent => absolute_urls(get_inline_content($page, $p), $url),
|
||||||
} if exists $renderedfiles{$page};
|
} if exists $renderedfiles{$p};
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
|
||||||
};
|
|
||||||
|
|
||||||
$content = postprocess($page, $content, inline => $gen_blog);
|
|
||||||
|
|
||||||
$template->param(
|
$template->param(
|
||||||
title => $config{wikiname},
|
title => $config{wikiname},
|
||||||
pageurl => $url,
|
pageurl => $url,
|
||||||
|
@ -349,6 +336,7 @@ sub render ($) { #{{{
|
||||||
delete $inlinepages{$page};
|
delete $inlinepages{$page};
|
||||||
|
|
||||||
$content=linkify($content, $page);
|
$content=linkify($content, $page);
|
||||||
|
$content=preprocess($page, $content);
|
||||||
$content=htmlize($type, $content);
|
$content=htmlize($type, $content);
|
||||||
|
|
||||||
check_overwrite("$config{destdir}/".htmlpage($page), $page);
|
check_overwrite("$config{destdir}/".htmlpage($page), $page);
|
||||||
|
@ -356,14 +344,6 @@ sub render ($) { #{{{
|
||||||
genpage($content, $page, mtime($srcfile)));
|
genpage($content, $page, mtime($srcfile)));
|
||||||
$oldpagemtime{$page}=time;
|
$oldpagemtime{$page}=time;
|
||||||
$renderedfiles{$page}=htmlpage($page);
|
$renderedfiles{$page}=htmlpage($page);
|
||||||
|
|
||||||
# TODO: should really add this to renderedfiles and call
|
|
||||||
# check_overwrite, as above, but currently renderedfiles
|
|
||||||
# only supports listing one file per page.
|
|
||||||
if ($config{rss} && exists $inlinepages{$page}) {
|
|
||||||
writefile(rsspage($page), $config{destdir},
|
|
||||||
genrss($content, $page, mtime($srcfile)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $content=readfile($srcfile, 1);
|
my $content=readfile($srcfile, 1);
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
Postprocessor directives are similar to a [[WikiLink]] in form, except they
|
|
||||||
contain spaces and parameters. The general form is:
|
|
||||||
|
|
||||||
\\[[directive param="value" param="value"]]
|
|
||||||
|
|
||||||
This gets expanded after the rest of the page is processed, and can be used
|
|
||||||
to transform the page in various ways.
|
|
||||||
|
|
||||||
Currently, these postprocessor directives are available:
|
|
||||||
|
|
||||||
* "inline" to make a [[blog]]
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
Preprocessor directives are similar to a [[WikiLink]] in form, except they
|
||||||
|
contain spaces and parameters. The general form is:
|
||||||
|
|
||||||
|
\\[[directive param="value" param="value"]]
|
||||||
|
|
||||||
|
This gets expanded before the rest of the page is processed, and can be used
|
||||||
|
to transform the page in various ways.
|
||||||
|
|
||||||
|
Currently, these preprocessor directives are available:
|
||||||
|
|
||||||
|
* "inline" to make a [[blog]]
|
|
@ -31,8 +31,5 @@
|
||||||
* If a file in the srcdir is removed, exposing a file in the underlaydir,
|
* If a file in the srcdir is removed, exposing a file in the underlaydir,
|
||||||
ikiwiki will not notice the change and rebuild it until the file in the
|
ikiwiki will not notice the change and rebuild it until the file in the
|
||||||
underlaydir gets a mtime newer than the mtime the removed file had.
|
underlaydir gets a mtime newer than the mtime the removed file had.
|
||||||
* Markdown will try to expand stuff inside postprocessordirectives. For
|
|
||||||
example, if there are two *'s, it will turn them to html em's, which
|
|
||||||
breaks things unexpectedly and requires escaping.
|
|
||||||
* ikiwiki will generate html formatted error messages to the command
|
* ikiwiki will generate html formatted error messages to the command
|
||||||
line if --cgi is set, even if it's not yet running as a cgi
|
line if --cgi is set, even if it's not yet running as a cgi
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
* Doctype is XHTML 1.0 Strict
|
||||||
|
|
||||||
|
One consideration of course is that regular users might embed html
|
||||||
|
that uses deprecated presentational elements like <center>. At
|
||||||
|
least firefox seems to handle that mixture ok.
|
||||||
|
--[[Joey]]
|
||||||
|
|
||||||
|
* [ [inlinepage] ] gets wrapped in <p>...</p> which has a high chance of invalidating the page.
|
||||||
|
|
||||||
|
Since markdown does this, the only way I can think to fix it is to
|
||||||
|
make the inlined page text start with </p> and end with
|
||||||
|
<p>. Ugly, and of course there could be problems with
|
||||||
|
markdown enclosing it in other spanning tags in some cases.
|
||||||
|
I've implemented this hack now. :-/ --[[Joey]]
|
||||||
|
|
||||||
|
I used this 'hack' myself, but yesterday I came up with a better idea:
|
||||||
|
<div class="inlinepage">
|
||||||
|
[ [inlinepage] ]
|
||||||
|
</div>
|
||||||
|
This prevents markdown enclosing and even adds a useful css identifier. Problem is that this should be added to every page and not in the template(s). --[[JeroenSchot]]
|
||||||
|
|
||||||
|
I can make ikiwiki add that around every inlined page easily
|
||||||
|
enough. However, where is it documented? Came up dry on google.
|
||||||
|
--[[Joey]]
|
||||||
|
|
||||||
|
From <http://daringfireball.net/projects/markdown/syntax#html>:
|
||||||
|
> The only restrictions are that block-level HTML elements e.g. <div>, <table>, <pre>, <p>, etc. must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces. Markdown is smart enough not to add extra (unwanted) <p> tags around HTML block-level tags. [snip]
|
||||||
|
> Note that Markdown formatting syntax is not processed within
|
||||||
|
> block-level HTML tags. E.g., you can't use Markdown-style \*emphasis\* inside an HTML block.
|
||||||
|
|
||||||
|
Because [ [inlinepage] ] isn't separated by a blank line it gets treated as a block-level element. Hmm, will this stop all formatting, including *'s to em-tags? --[[JeroenSchot]]
|
||||||
|
|
||||||
|
Ah didn't realize you meant it fixed it at the markdown level. I'll
|
||||||
|
think about making [[postprocessordirective]]s into
|
||||||
|
[[preprocessordirective]]s instead, then I could use that fix (but I'm not
|
||||||
|
sure how feasible it is to do that). --[[Joey]]
|
||||||
|
|
||||||
|
Done.. inlining is now a preprocessor directive, happens before
|
||||||
|
markdown, and the inlinepage template uses div as suggested, this does
|
||||||
|
prevent markdown from doing any annoying escaping of the preprocessor
|
||||||
|
directives, as well as preventing it wrapping subpages in <p>.
|
||||||
|
--[[Joey]]
|
||||||
|
|
||||||
|
This page is now valid.
|
||||||
|
Test: [validate this page](http://validator.w3.org/check?url=referer)
|
|
@ -3,44 +3,3 @@ formatting, and images to indicate web vs svn commits and to link to diffs.
|
||||||
|
|
||||||
All of this should be doable w/o touching a single line of code, just
|
All of this should be doable w/o touching a single line of code, just
|
||||||
editing the [[templates]] and/or editing [[style.css]] BTW.
|
editing the [[templates]] and/or editing [[style.css]] BTW.
|
||||||
|
|
||||||
## html validation
|
|
||||||
|
|
||||||
* Doctype is XHTML 1.0 Strict
|
|
||||||
|
|
||||||
One consideration of course is that regular users might embed html
|
|
||||||
that uses deprecated presentational elements like <center>. At
|
|
||||||
least firefox seems to handle that mixture ok.
|
|
||||||
--[[Joey]]
|
|
||||||
|
|
||||||
* [ [inlinepage] ] gets wrapped in <p>...</p> which has a high chance of invalidating the page.
|
|
||||||
|
|
||||||
Since markdown does this, the only way I can think to fix it is to
|
|
||||||
make the inlined page text start with </p> and end with
|
|
||||||
<p>. Ugly, and of course there could be problems with
|
|
||||||
markdown enclosing it in other spanning tags in some cases.
|
|
||||||
I've implemented this hack now. :-/ --[[Joey]]
|
|
||||||
|
|
||||||
I used this 'hack' myself, but yesterday I came up with a better idea:
|
|
||||||
<div class="inlinepage">
|
|
||||||
[ [inlinepage] ]
|
|
||||||
</div>
|
|
||||||
This prevents markdown enclosing and even adds a useful css identifier. Problem is that this should be added to every page and not in the template(s). --[[JeroenSchot]]
|
|
||||||
|
|
||||||
I can make ikiwiki add that around every inlined page easily
|
|
||||||
enough. However, where is it documented? Came up dry on google.
|
|
||||||
--[[Joey]]
|
|
||||||
|
|
||||||
From <http://daringfireball.net/projects/markdown/syntax#html>:
|
|
||||||
> The only restrictions are that block-level HTML elements — e.g. <div>, <table>, <pre>, <p>, etc. — must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces. Markdown is smart enough not to add extra (unwanted) <p> tags around HTML block-level tags. [snip]
|
|
||||||
> Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can’t use Markdown-style \*emphasis\* inside an HTML block.
|
|
||||||
|
|
||||||
Because [ [inlinepage] ] isn't separated by a blank line it gets treated as a block-level element. Hmm, will this stop all formatting, including *'s to em-tags? --[[JeroenSchot]]
|
|
||||||
|
|
||||||
Ah didn't realize you meant it fixed it at the markdown level. I'll
|
|
||||||
think about making [[postprocessordirective]]s into
|
|
||||||
preprocessordirectives instead, then I could use that fix (but I'm not
|
|
||||||
sure how feasible it is to do that). --[[Joey]]
|
|
||||||
|
|
||||||
This page is now valid.
|
|
||||||
Test: [validate this page](http://validator.w3.org/check?url=referer)
|
|
||||||
|
|
|
@ -23,5 +23,3 @@ The following problems have been observed when running ikiwiki this way:
|
||||||
|
|
||||||
In this example, a literal 0x97 character had gotten into a markdown
|
In this example, a literal 0x97 character had gotten into a markdown
|
||||||
file.
|
file.
|
||||||
|
|
||||||
Here, let's put one in this file: "—"
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
<div class="inlinepage">
|
||||||
<h1><TMPL_VAR PAGELINK></h1>
|
<h1><TMPL_VAR PAGELINK></h1>
|
||||||
|
|
||||||
<TMPL_VAR CONTENT>
|
<TMPL_VAR CONTENT>
|
||||||
|
@ -5,3 +6,4 @@
|
||||||
<p>
|
<p>
|
||||||
<i>(posted <TMPL_VAR CTIME>)</i>
|
<i>(posted <TMPL_VAR CTIME>)</i>
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue