git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Allow block-level content in notes (ref).
35b66a7John MacFarlane
src/Text/Pandoc/Readers/MediaWiki.hs+9−1
@@ -112,12 +112,14 @@ newBlockTags = ["haskell","syntaxhighlight","source","gallery","references"]
112isBlockTag' :: Tag Text -> Bool
112isBlockTag' :: Tag Text -> Bool
113isBlockTag' tag@(TagOpen t _) = (isBlockTag tag || t `elem` newBlockTags) &&
113isBlockTag' tag@(TagOpen t _) = (isBlockTag tag || t `elem` newBlockTags) &&
114 t `notElem` eitherBlockOrInline
114 t `notElem` eitherBlockOrInline
115+isBlockTag' (TagClose "ref") = True -- needed so 'special' doesn't parse it
115isBlockTag' tag@(TagClose t) = (isBlockTag tag || t `elem` newBlockTags) &&
116isBlockTag' tag@(TagClose t) = (isBlockTag tag || t `elem` newBlockTags) &&
116 t `notElem` eitherBlockOrInline
117 t `notElem` eitherBlockOrInline
117isBlockTag' tag = isBlockTag tag
118isBlockTag' tag = isBlockTag tag
118
119
119isInlineTag' :: Tag Text -> Bool
120isInlineTag' :: Tag Text -> Bool
120isInlineTag' (TagComment _) = True
121isInlineTag' (TagComment _) = True
122+isInlineTag' (TagClose "ref") = False -- see below inlineTag
121isInlineTag' t = not (isBlockTag' t)
123isInlineTag' t = not (isBlockTag' t)
122
124
123eitherBlockOrInline :: [Text]
125eitherBlockOrInline :: [Text]
@@ -554,11 +556,17 @@ variable = try $ do
554 contents <- manyTillChar anyChar (try $ string "}}}")
556 contents <- manyTillChar anyChar (try $ string "}}}")
555 return $ "{{{" <> contents <> "}}}"
557 return $ "{{{" <> contents <> "}}}"
556
558
559+singleParaToPlain :: Blocks -> Blocks
560+singleParaToPlain bs =
561+ case B.toList bs of
562+ [Para ils] -> B.fromList [Plain ils]
563+ _ -> bs
564+
557inlineTag :: PandocMonad m => MWParser m Inlines
565inlineTag :: PandocMonad m => MWParser m Inlines
558inlineTag = do
566inlineTag = do
559 (tag, _) <- lookAhead $ htmlTag isInlineTag'
567 (tag, _) <- lookAhead $ htmlTag isInlineTag'
560 case tag of
568 case tag of
561− TagOpen "ref" _ -> B.note . B.plain <$> inlinesInTags "ref"
569+ TagOpen "ref" _ -> B.note . singleParaToPlain <$> blocksInTags "ref"
562 TagOpen "nowiki" _ -> try $ do
570 TagOpen "nowiki" _ -> try $ do
563 (_,raw) <- htmlTag (~== tag)
571 (_,raw) <- htmlTag (~== tag)
564 if T.any (== '/') raw
572 if T.any (== '/') raw
test/command/7145.mdnew file+12
@@ -0,0 +1,12 @@
1+```
2+% pandoc -f mediawiki -t native
3+Maecenas at sapien tempor, pretium turpis ut, imperdiet augue.<ref>This is a multiline
4+
5+reference
6+<i>with</i>
7+empty
8+
9+linebreaks</ref> Nulla ut massa eget ex venenatis lobortis id in eros.
10+^D
11+[Para [Str "Maecenas",Space,Str "at",Space,Str "sapien",Space,Str "tempor,",Space,Str "pretium",Space,Str "turpis",Space,Str "ut,",Space,Str "imperdiet",Space,Str "augue.",Note [Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "multiline"],Para [Str "reference",SoftBreak,RawInline (Format "html") "<i>",Str "with",RawInline (Format "html") "</i>",SoftBreak,Str "empty"],Para [Str "linebreaks"]],Space,Str "Nulla",Space,Str "ut",Space,Str "massa",Space,Str "eget",Space,Str "ex",Space,Str "venenatis",Space,Str "lobortis",Space,Str "id",Space,Str "in",Space,Str "eros."]]
12+```