diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-11-04 21:20:41 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-11-04 21:20:41 -0800 |
commit | 08134388ad94a9652050f416287dbcaaf2962114 (patch) | |
tree | b46a3b7bb84e9655b987a6839b925f1871004c3d /src/Text | |
parent | b5e9c2a7a644409c4ba9fb6bb429e9c9524cfb01 (diff) | |
download | pandoc-08134388ad94a9652050f416287dbcaaf2962114.tar.gz |
MediaWiki writer: use syntaxhighlight tag...
instead of deprecated source, for highlighted code.
Also support `startFrom` attribute and `numberLines`.
Closes #6810.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Writers/MediaWiki.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/MediaWiki.hs b/src/Text/Pandoc/Writers/MediaWiki.hs index 513693389..d1912caa6 100644 --- a/src/Text/Pandoc/Writers/MediaWiki.hs +++ b/src/Text/Pandoc/Writers/MediaWiki.hs @@ -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 |