git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Allow block-level content in notes (ref).

Closes #7145.

commit35b66a76718205c303f416bf0afc01c098e8a171 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 13 Mar 2021, 12:50 (6 years ago) parenteed18d2
2 files changed+21−1
src/Text/Pandoc/Readers/MediaWiki.hs+9−1 test/command/7145.md+12
src/Text/Pandoc/Readers/MediaWiki.hs+9−1
@@ -112,12 +112,14 @@ newBlockTags = ["haskell","syntaxhighlight","source","gallery","references"]
112112isBlockTag' :: Tag Text -> Bool
113113isBlockTag' tag@(TagOpen t _) = (isBlockTag tag || t `elem` newBlockTags) &&
114114 t `notElem` eitherBlockOrInline
115+isBlockTag' (TagClose "ref") = True -- needed so 'special' doesn't parse it
115116isBlockTag' tag@(TagClose t) = (isBlockTag tag || t `elem` newBlockTags) &&
116117 t `notElem` eitherBlockOrInline
117118isBlockTag' tag = isBlockTag tag
118119
119120isInlineTag' :: Tag Text -> Bool
120121isInlineTag' (TagComment _) = True
122+isInlineTag' (TagClose "ref") = False -- see below inlineTag
121123isInlineTag' t = not (isBlockTag' t)
122124
123125eitherBlockOrInline :: [Text]
@@ -554,11 +556,17 @@ variable = try $ do
554556 contents <- manyTillChar anyChar (try $ string "}}}")
555557 return $ "{{{" <> contents <> "}}}"
556558
559+singleParaToPlain :: Blocks -> Blocks
560+singleParaToPlain bs =
561+ case B.toList bs of
562+ [Para ils] -> B.fromList [Plain ils]
563+ _ -> bs
564+
557565inlineTag :: PandocMonad m => MWParser m Inlines
558566inlineTag = do
559567 (tag, _) <- lookAhead $ htmlTag isInlineTag'
560568 case tag of
561− TagOpen "ref" _ -> B.note . B.plain <$> inlinesInTags "ref"
569+ TagOpen "ref" _ -> B.note . singleParaToPlain <$> blocksInTags "ref"
562570 TagOpen "nowiki" _ -> try $ do
563571 (_,raw) <- htmlTag (~== tag)
564572 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+```