git.iko.soy/typeable/pandoc
on master help sign in
DokuWiki writer: translate language names for code elements...
efe7474John MacFarlane
src/Text/Pandoc/Writers/DokuWiki.hs+24−14
@@ -26,7 +26,7 @@ import Control.Monad (zipWithM)
26import Control.Monad.Reader (ReaderT, asks, local, runReaderT)
26import Control.Monad.Reader (ReaderT, asks, local, runReaderT)
27import Control.Monad.State.Strict (StateT, evalStateT)
27import Control.Monad.State.Strict (StateT, evalStateT)
28import Data.Default (Default (..))
28import Data.Default (Default (..))
29−import Data.List (intersect, transpose)
29+import Data.List (transpose)
30import Data.Text (Text)
30import Data.Text (Text)
31import qualified Data.Text as T
31import qualified Data.Text as T
32import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
32import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
@@ -39,6 +39,7 @@ import Text.Pandoc.Shared (camelCaseToHyphenated, escapeURI, isURI, linesToPara,
39import Text.Pandoc.Templates (renderTemplate)
39import Text.Pandoc.Templates (renderTemplate)
40import Text.DocLayout (render, literal)
40import Text.DocLayout (render, literal)
41import Text.Pandoc.Writers.Shared (defField, metaToContext, toLegacyTable)
41import Text.Pandoc.Writers.Shared (defField, metaToContext, toLegacyTable)
42+import qualified Data.Map as M
42
43
43data WriterState = WriterState {
44data WriterState = WriterState {
44 }
45 }
@@ -145,20 +146,13 @@ blockToDokuWiki opts (Header level _ inlines) = do
145 let eqs = T.replicate ( 7 - level ) "="
146 let eqs = T.replicate ( 7 - level ) "="
146 return $ eqs <> " " <> contents <> " " <> eqs <> "\n"
147 return $ eqs <> " " <> contents <> " " <> eqs <> "\n"
147
148
148−blockToDokuWiki _ (CodeBlock (_,classes,_) str) = do
149+blockToDokuWiki _ (CodeBlock (_,classes,_) str) =
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"]
158 return $ "<code" <>
150 return $ "<code" <>
159− (case at of
151+ (case classes of
160− [] -> ">\n"
152+ [] -> ""
153+ (x:_) -> " " <> maybe x id (M.lookup x languageNames)) <>
161− (x:_) -> " " <> x <> ">\n") <> str <> "\n</code>"
154+ ">\n" <> str <>
155+ (if "\n" `T.isSuffixOf` str then "" else "\n") <> "</code>\n"
162
156
163blockToDokuWiki opts (BlockQuote blocks) = do
157blockToDokuWiki opts (BlockQuote blocks) = do
164 contents <- blockListToDokuWiki opts blocks
158 contents <- blockListToDokuWiki opts blocks
@@ -507,3 +501,19 @@ imageDims opts attr = go (toPx $ dimension Width attr) (toPx $ dimension Height
507 go (Just w) (Just h) = "?" <> w <> "x" <> h
501 go (Just w) (Just h) = "?" <> w <> "x" <> h
508 go Nothing (Just h) = "?0x" <> h
502 go Nothing (Just h) = "?0x" <> h
509 go Nothing Nothing = ""
503 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 @@
8 * hi<code>
8 * hi<code>
9 there
9 there
10</code>
10</code>
11+
11 * ok
12 * ok
12
13
13```
14```
test/writer.dokuwiki+11
@@ -56,6 +56,7 @@ sub status {
56 print "working";
56 print "working";
57}
57}
58</code>
58</code>
59+
59A list:
60A list:
60
61
61 - item one
62 - item one
@@ -87,6 +88,7 @@ sub status {
87
88
88this code block is indented by one tab
89this code block is indented by one tab
89</code>
90</code>
91+
90And:
92And:
91
93
92<code>
94<code>
@@ -95,6 +97,7 @@ And:
95These should not be escaped: \$ \\ \> \[ \{
97These should not be escaped: \$ \\ \> \[ \{
96</code>
98</code>
97
99
100+
98----
101----
99
102
100====== Lists ======
103====== Lists ======
@@ -277,6 +280,7 @@ Multiple blocks with italics:
277<code>
280<code>
278{ orange code block }
281{ orange code block }
279</code>
282</code>
283+
280> <HTML><p></HTML>orange block quote<HTML></p></HTML>
284> <HTML><p></HTML>orange block quote<HTML></p></HTML>
281<HTML></dd></HTML><HTML></dl></HTML>
285<HTML></dd></HTML><HTML></dl></HTML>
282
286
@@ -343,11 +347,13 @@ This should be a code block, though:
343 foo
347 foo
344</div>
348</div>
345</code>
349</code>
350+
346As should this:
351As should this:
347
352
348<code>
353<code>
349<div>foo</div>
354<div>foo</div>
350</code>
355</code>
356+
351Now, nested:
357Now, nested:
352
358
353foo
359foo
@@ -375,6 +381,7 @@ Code block:
375<code>
381<code>
376<!-- Comment -->
382<!-- Comment -->
377</code>
383</code>
384+
378Just plain comment, with trailing spaces on the line:
385Just plain comment, with trailing spaces on the line:
379
386
380<HTML>
387<HTML>
@@ -385,6 +392,7 @@ Code:
385<code>
392<code>
386<hr />
393<hr />
387</code>
394</code>
395+
388Hr’s:
396Hr’s:
389
397
390<HTML>
398<HTML>
@@ -571,6 +579,7 @@ This should [not][] be a link.
571<code>
579<code>
572[not]: /url
580[not]: /url
573</code>
581</code>
582+
574Foo [[url/|bar]].
583Foo [[url/|bar]].
575
584
576Foo [[url/|biz]].
585Foo [[url/|biz]].
@@ -603,6 +612,7 @@ Auto-links should not occur here: ''%%<http://example.com/>%%''
603or here: <http://example.com/>
612or here: <http://example.com/>
604</code>
613</code>
605
614
615+
606----
616----
607
617
608====== Images ======
618====== Images ======
@@ -626,6 +636,7 @@ Subsequent blocks are indented to show that they belong to the footnote (as with
626<code>
636<code>
627 { <code> }
637 { <code> }
628</code>
638</code>
639+
629If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.
640If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.
630)) 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].
641)) 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].
631))
642))