* mdwn: When htmlizing text, if it's a single line with no newline,

remove the enclosing paragraph and newline markdown wraps it in.
  This allows removing several hacks around this markdown behavior from
  other plugins that htmlize fragements of pages.
master
Joey Hess 2008-01-09 14:35:23 -05:00
parent ed30330ac2
commit 2b9ce0129b
5 changed files with 22 additions and 25 deletions

View File

@ -41,6 +41,8 @@ sub htmlize (@) { #{{{
require Encode; require Encode;
} }
my $oneline = $content !~ /\n/;
# Workaround for perl bug (#376329) # Workaround for perl bug (#376329)
$content=Encode::encode_utf8($content); $content=Encode::encode_utf8($content);
eval {$content=&$markdown_sub($content)}; eval {$content=&$markdown_sub($content)};
@ -50,6 +52,13 @@ sub htmlize (@) { #{{{
} }
$content=Encode::decode_utf8($content); $content=Encode::decode_utf8($content);
if ($oneline) {
# hack to get rid of enclosing junk added by markdown
$content=~s!^<p>!!;
$content=~s!</p>$!!;
chomp $content;
}
return $content; return $content;
} # }}} } # }}}

View File

@ -46,18 +46,10 @@ sub scrub ($) { #{{{
sub htmlize ($$$) { #{{{ sub htmlize ($$$) { #{{{
my $page = shift; my $page = shift;
my $destpage = shift; my $destpage = shift;
my $text = shift;
$text=IkiWiki::htmlize($page, pagetype($pagesources{$page}), return IkiWiki::htmlize($page, pagetype($pagesources{$page}),
IkiWiki::linkify($page, $destpage, IkiWiki::linkify($page, $destpage,
IkiWiki::preprocess($page, $destpage, $text))); IkiWiki::preprocess($page, $destpage, shift)));
# hack to get rid of enclosing junk added by markdown
$text=~s!^<p>!!;
$text=~s!</p>$!!;
chomp $text;
return $text;
} }
sub preprocess (@) { #{{{ sub preprocess (@) { #{{{
@ -184,7 +176,7 @@ sub preprocess (@) { #{{{
} }
elsif ($key eq 'link') { elsif ($key eq 'link') {
if (%params) { if (%params) {
$meta{$page}.=scrub("<link href=\"".encode_entities($value)."\" ". push @{$meta{$page}}, scrub("<link href=\"".encode_entities($value)."\" ".
join(" ", map { join(" ", map {
encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\""
} keys %params). } keys %params).

View File

@ -174,17 +174,9 @@ sub genrow ($$$@) { #{{{
sub htmlize ($$$) { #{{{ sub htmlize ($$$) { #{{{
my $page = shift; my $page = shift;
my $destpage = shift; my $destpage = shift;
my $text = shift;
$text=IkiWiki::htmlize($page, pagetype($pagesources{$page}), return IkiWiki::htmlize($page, pagetype($pagesources{$page}),
IkiWiki::preprocess($page, $destpage, $text)); IkiWiki::preprocess($page, $destpage, shift));
# hack to get rid of enclosing junk added by markdown
$text=~s!^<p>!!;
$text=~s!</p>$!!;
chomp $text;
return $text;
} }
1 1

4
debian/changelog vendored
View File

@ -17,6 +17,10 @@ ikiwiki (2.20) UNRELEASED; urgency=low
* template: Remove bogus htmlize pass added in 2.16. * template: Remove bogus htmlize pass added in 2.16.
* template: Htmlize template variables, but also provide a raw version * template: Htmlize template variables, but also provide a raw version
via `<TMPL_VAR raw_variable>`. via `<TMPL_VAR raw_variable>`.
* mdwn: When htmlizing text, if it's a single line with no newline,
remove the enclosing paragraph and newline markdown wraps it in.
This allows removing several hacks around this markdown behavior from
other plugins that htmlize fragements of pages.
-- Joey Hess <joeyh@debian.org> Wed, 09 Jan 2008 00:34:46 -0500 -- Joey Hess <joeyh@debian.org> Wed, 09 Jan 2008 00:34:46 -0500

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-01-09 14:04-0500\n" "POT-Creation-Date: 2008-01-09 14:31-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -240,15 +240,15 @@ msgstr ""
msgid "failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)" msgid "failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/meta.pm:132 #: ../IkiWiki/Plugin/meta.pm:124
msgid "stylesheet not found" msgid "stylesheet not found"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/meta.pm:156 #: ../IkiWiki/Plugin/meta.pm:148
msgid "redir page not found" msgid "redir page not found"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/meta.pm:169 #: ../IkiWiki/Plugin/meta.pm:161
msgid "redir cycle is not allowed" msgid "redir cycle is not allowed"
msgstr "" msgstr ""