git.iko.soy/typeable/pandoc
on master help sign in
DokuWiki writer: translate language names for code elements...

...and improve whitespace. Closes #6807.

commitefe74746d881828723d2af79d1097794a21aee54 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 4 Nov 2020, 22:38 (6 years ago) parent0813438
3 files changed+36−14
src/Text/Pandoc/Writers/DokuWiki.hs+24−14 test/command/3824.md+1 test/writer.dokuwiki+11
src/Text/Pandoc/Writers/DokuWiki.hs+24−14
@@ -26,7 +26,7 @@ import Control.Monad (zipWithM)
2626import Control.Monad.Reader (ReaderT, asks, local, runReaderT)
2727import Control.Monad.State.Strict (StateT, evalStateT)
2828import Data.Default (Default (..))
29−import Data.List (intersect, transpose)
29+import Data.List (transpose)
3030import Data.Text (Text)
3131import qualified Data.Text as T
3232import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
@@ -39,6 +39,7 @@ import Text.Pandoc.Shared (camelCaseToHyphenated, escapeURI, isURI, linesToPara,
3939import Text.Pandoc.Templates (renderTemplate)
4040import Text.DocLayout (render, literal)
4141import Text.Pandoc.Writers.Shared (defField, metaToContext, toLegacyTable)
42+import qualified Data.Map as M
4243
4344data WriterState = WriterState {
4445 }
@@ -145,20 +146,13 @@ blockToDokuWiki opts (Header level _ inlines) = do
145146 let eqs = T.replicate ( 7 - level ) "="
146147 return $ eqs <> " " <> contents <> " " <> eqs <> "\n"
147148
148−blockToDokuWiki _ (CodeBlock (_,classes,_) str) = do
149− let at = classes `intersect` ["actionscript", "ada", "apache", "applescript", "asm", "asp",
150− "autoit", "bash", "blitzbasic", "bnf", "c", "c_mac", "caddcl", "cadlisp", "cfdg", "cfm",
151− "cpp", "cpp-qt", "csharp", "css", "d", "delphi", "diff", "div", "dos", "eiffel", "fortran",
152− "freebasic", "gml", "groovy", "html4strict", "idl", "ini", "inno", "io", "java", "java5",
153− "javascript", "latex", "lisp", "lua", "matlab", "mirc", "mpasm", "mysql", "nsis", "objc",
154− "ocaml", "ocaml-brief", "oobas", "oracle8", "pascal", "perl", "php", "php-brief", "plsql",
155− "python", "qbasic", "rails", "reg", "robots", "ruby", "sas", "scheme", "sdlbasic",
156− "smalltalk", "smarty", "sql", "tcl", "", "thinbasic", "tsql", "vb", "vbnet", "vhdl",
157− "visualfoxpro", "winbatch", "xml", "xpp", "z80"]
149+blockToDokuWiki _ (CodeBlock (_,classes,_) str) =
158150 return $ "<code" <>
159− (case at of
160− [] -> ">\n"
161− (x:_) -> " " <> x <> ">\n") <> str <> "\n</code>"
151+ (case classes of
152+ [] -> ""
153+ (x:_) -> " " <> maybe x id (M.lookup x languageNames)) <>
154+ ">\n" <> str <>
155+ (if "\n" `T.isSuffixOf` str then "" else "\n") <> "</code>\n"
162156
163157blockToDokuWiki opts (BlockQuote blocks) = do
164158 contents <- blockListToDokuWiki opts blocks
@@ -507,3 +501,19 @@ imageDims opts attr = go (toPx $ dimension Width attr) (toPx $ dimension Height
507501 go (Just w) (Just h) = "?" <> w <> "x" <> h
508502 go Nothing (Just h) = "?0x" <> h
509503 go Nothing Nothing = ""
504+
505+languageNames :: M.Map Text Text
506+languageNames = M.fromList $
507+ [("cs", "csharp")
508+ ,("coffee", "cofeescript")
509+ ,("commonlisp", "lisp")
510+ ,("gcc", "c")
511+ ,("html", "html5")
512+ ,("makefile", "make")
513+ ,("objectivec", "objc")
514+ ,("r", "rsplus")
515+ ,("sqlmysql", "mysql")
516+ ,("sqlpostgresql", "postgresql")
517+ ,("sci", "scilab")
518+ ,("xorg", "xorgconf")
519+ ]
test/command/3824.md+1
@@ -8,6 +8,7 @@
88 * hi<code>
99 there
1010</code>
11+
1112 * ok
1213
1314```
test/writer.dokuwiki+11
@@ -56,6 +56,7 @@ sub status {
5656 print "working";
5757}
5858</code>
59+
5960A list:
6061
6162 - item one
@@ -87,6 +88,7 @@ sub status {
8788
8889this code block is indented by one tab
8990</code>
91+
9092And:
9193
9294<code>
@@ -95,6 +97,7 @@ And:
9597These should not be escaped: \$ \\ \> \[ \{
9698</code>
9799
100+
98101----
99102
100103====== Lists ======
@@ -277,6 +280,7 @@ Multiple blocks with italics:
277280<code>
278281{ orange code block }
279282</code>
283+
280284> <HTML><p></HTML>orange block quote<HTML></p></HTML>
281285<HTML></dd></HTML><HTML></dl></HTML>
282286
@@ -343,11 +347,13 @@ This should be a code block, though:
343347 foo
344348</div>
345349</code>
350+
346351As should this:
347352
348353<code>
349354<div>foo</div>
350355</code>
356+
351357Now, nested:
352358
353359foo
@@ -375,6 +381,7 @@ Code block:
375381<code>
376382<!-- Comment -->
377383</code>
384+
378385Just plain comment, with trailing spaces on the line:
379386
380387<HTML>
@@ -385,6 +392,7 @@ Code:
385392<code>
386393<hr />
387394</code>
395+
388396Hr’s:
389397
390398<HTML>
@@ -571,6 +579,7 @@ This should [not][] be a link.
571579<code>
572580[not]: /url
573581</code>
582+
574583Foo [[url/|bar]].
575584
576585Foo [[url/|biz]].
@@ -603,6 +612,7 @@ Auto-links should not occur here: ''%%<http://example.com/>%%''
603612or here: <http://example.com/>
604613</code>
605614
615+
606616----
607617
608618====== Images ======
@@ -626,6 +636,7 @@ Subsequent blocks are indented to show that they belong to the footnote (as with
626636<code>
627637 { <code> }
628638</code>
639+
629640If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.
630641)) This should //not// be a footnote reference, because it contains a space.[^my note] Here is an inline note.((This is //easier// to type. Inline notes may contain [[http://google.com|links]] and ''%%]%%'' verbatim characters, as well as [bracketed text].
631642))