MediaWiki writer: use syntaxhighlight tag...

instead of deprecated source, for highlighted code.

Also support `startFrom` attribute and `numberLines`.

Closes #6810.
This commit is contained in:
John MacFarlane 2020-11-04 21:20:41 -08:00
parent b5e9c2a7a6
commit 08134388ad

View file

@ -135,15 +135,22 @@ blockToMediaWiki (Header level _ inlines) = do
let eqs = T.replicate level "="
return $ eqs <> " " <> contents <> " " <> eqs <> "\n"
blockToMediaWiki (CodeBlock (_,classes,_) str) = do
blockToMediaWiki (CodeBlock (_,classes,keyvals) str) = do
let at = Set.fromList classes `Set.intersection` highlightingLangs
let numberLines = any (`elem` ["number","numberLines", "number-lines"])
classes
let start = lookup "startFrom" keyvals
return $
case Set.toList at of
[] -> "<pre" <> (if null classes
then ">"
else " class=\"" <> T.unwords classes <> "\">") <>
escapeText str <> "</pre>"
(l:_) -> "<source lang=\"" <> l <> "\">" <> str <> "</source>"
(l:_) -> "<syntaxhighlight lang=\"" <> l <> "\"" <>
(if numberLines then " line" else "") <>
maybe "" (\x -> " start=\"" <> x <> "\"") start <>
">" <> str <>
"</syntaxhighlight>"
-- note: no escape! even for <!
blockToMediaWiki (BlockQuote blocks) = do