MediaWiki reader: Handle templates, variables as raw mediawiki.
Also check for column 1 in preformatted text.
This commit is contained in:
parent
4e1a45467c
commit
3fe6ea4c41
3 changed files with 34 additions and 6 deletions
|
@ -38,7 +38,6 @@ _ support external links (partially implemented)
|
|||
_ support images http://www.mediawiki.org/wiki/Help:Images
|
||||
_ support tables http://www.mediawiki.org/wiki/Help:Tables
|
||||
_ gallery tag?
|
||||
_ tests for templates (should be -> raw mediawiki)
|
||||
-}
|
||||
module Text.Pandoc.Readers.MediaWiki ( readMediaWiki ) where
|
||||
|
||||
|
@ -130,16 +129,17 @@ block = mempty <$ skipMany1 blankline
|
|||
<|> blockTag
|
||||
<|> pTag
|
||||
<|> blockHtml
|
||||
<|> rawMediaWiki
|
||||
<|> template
|
||||
<|> para
|
||||
|
||||
para :: MWParser Blocks
|
||||
para = B.para . trimInlines . mconcat <$> many1 inline
|
||||
|
||||
rawMediaWiki :: MWParser Blocks
|
||||
rawMediaWiki = B.rawBlock "mediawiki" <$> doublebrackets
|
||||
template :: MWParser Blocks
|
||||
template = B.rawBlock "mediawiki" <$> doublebrackets
|
||||
where doublebrackets = try $ do
|
||||
string "{{"
|
||||
notFollowedBy (char '{')
|
||||
contents <- manyTill anyChar (try $ string "}}")
|
||||
return $ "{{" ++ contents ++ "}}"
|
||||
|
||||
|
@ -180,7 +180,8 @@ hrule :: MWParser Blocks
|
|||
hrule = B.horizontalRule <$ try (string "----" *> many (char '-') *> newline)
|
||||
|
||||
preformatted :: MWParser Blocks
|
||||
preformatted = do
|
||||
preformatted = try $ do
|
||||
getPosition >>= \pos -> guard (sourceColumn pos == 1)
|
||||
char ' '
|
||||
let endline' = B.linebreak <$ (try $ newline <* char ' ')
|
||||
let whitespace' = B.str <$> many1 ('\160' <$ spaceChar)
|
||||
|
@ -280,11 +281,19 @@ inline = whitespace
|
|||
<|> inlineTag
|
||||
<|> B.singleton <$> charRef
|
||||
<|> inlineHtml
|
||||
<|> variable
|
||||
<|> special
|
||||
|
||||
str :: MWParser Inlines
|
||||
str = B.str <$> many1 (noneOf $ specialChars ++ spaceChars)
|
||||
|
||||
variable :: MWParser Inlines
|
||||
variable = B.rawInline "mediawiki" <$> triplebrackets
|
||||
where triplebrackets = try $ do
|
||||
string "{{{"
|
||||
contents <- manyTill anyChar (try $ string "}}}")
|
||||
return $ "{{{" ++ contents ++ "}}}"
|
||||
|
||||
inlineTag :: MWParser Inlines
|
||||
inlineTag = do
|
||||
(TagOpen t _, raw) <- htmlTag (\x -> isInlineTag x && isTagOpen x)
|
||||
|
|
|
@ -135,4 +135,12 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
|
|||
,Header 2 [Str "preformatted",Space,Str "blocks"]
|
||||
,Para [Code ("",[],[]) "Start\160each\160line\160with\160a\160space.",LineBreak,Code ("",[],[]) "Text\160is\160",Strong [Code ("",[],[]) "preformatted"],Code ("",[],[]) "\160and",LineBreak,Emph [Code ("",[],[]) "markups"],Code ("",[],[]) "\160",Strong [Emph [Code ("",[],[]) "can"]],Code ("",[],[]) "\160be\160done."]
|
||||
,Para [Code ("",[],[]) "\160hell\160\160\160\160\160\160yeah"]
|
||||
,Para [Code ("",[],[]) "Start\160with\160a\160space\160in\160the\160first\160column,",LineBreak,Code ("",[],[]) "(before\160the\160<nowiki>).",LineBreak,Code ("",[],[]) "",LineBreak,Code ("",[],[]) "Then\160your\160block\160format\160will\160be",LineBreak,Code ("",[],[]) "\160\160\160\160maintained.",LineBreak,Code ("",[],[]) "",LineBreak,Code ("",[],[]) "This\160is\160good\160for\160copying\160in\160code\160blocks:",LineBreak,Code ("",[],[]) "",LineBreak,Code ("",[],[]) "def\160function():",LineBreak,Code ("",[],[]) "\160\160\160\160\"\"\"documentation\160string\"\"\"",LineBreak,Code ("",[],[]) "",LineBreak,Code ("",[],[]) "\160\160\160\160if\160True:",LineBreak,Code ("",[],[]) "\160\160\160\160\160\160\160\160print\160True",LineBreak,Code ("",[],[]) "\160\160\160\160else:",LineBreak,Code ("",[],[]) "\160\160\160\160\160\160\160\160print\160False"]]
|
||||
,Para [Code ("",[],[]) "Start\160with\160a\160space\160in\160the\160first\160column,",LineBreak,Code ("",[],[]) "(before\160the\160<nowiki>).",LineBreak,Code ("",[],[]) "",LineBreak,Code ("",[],[]) "Then\160your\160block\160format\160will\160be",LineBreak,Code ("",[],[]) "\160\160\160\160maintained.",LineBreak,Code ("",[],[]) "",LineBreak,Code ("",[],[]) "This\160is\160good\160for\160copying\160in\160code\160blocks:",LineBreak,Code ("",[],[]) "",LineBreak,Code ("",[],[]) "def\160function():",LineBreak,Code ("",[],[]) "\160\160\160\160\"\"\"documentation\160string\"\"\"",LineBreak,Code ("",[],[]) "",LineBreak,Code ("",[],[]) "\160\160\160\160if\160True:",LineBreak,Code ("",[],[]) "\160\160\160\160\160\160\160\160print\160True",LineBreak,Code ("",[],[]) "\160\160\160\160else:",LineBreak,Code ("",[],[]) "\160\160\160\160\160\160\160\160print\160False"]
|
||||
,Para [Str "Not"]
|
||||
,RawBlock "html" "<hr/>"
|
||||
,Para [Str "preformatted"]
|
||||
,Header 2 [Str "templates"]
|
||||
,RawBlock "mediawiki" "{{Welcome}}"
|
||||
,RawBlock "mediawiki" "{{Foo:Bar}}"
|
||||
,RawBlock "mediawiki" "{{Thankyou|all your effort|Me}}"
|
||||
,Para [Str "Written",Space,RawInline "mediawiki" "{{{date}}}",Space,Str "by",Space,RawInline "mediawiki" "{{{name}}}",Str "."]]
|
||||
|
|
|
@ -217,4 +217,15 @@ def function():
|
|||
else:
|
||||
print False</nowiki>
|
||||
|
||||
Not<hr/> preformatted
|
||||
|
||||
== templates ==
|
||||
|
||||
{{Welcome}}
|
||||
|
||||
{{Foo:Bar}}
|
||||
|
||||
{{Thankyou|all your effort|Me}}
|
||||
|
||||
Written {{{date}}} by {{{name}}}.
|
||||
|
||||
|
|
Loading…
Reference in a new issue