DokuWiki writer: translate language names for code elements...
...and improve whitespace. Closes #6807.
This commit is contained in:
parent
08134388ad
commit
efe74746d8
3 changed files with 36 additions and 14 deletions
|
@ -26,7 +26,7 @@ import Control.Monad (zipWithM)
|
||||||
import Control.Monad.Reader (ReaderT, asks, local, runReaderT)
|
import Control.Monad.Reader (ReaderT, asks, local, runReaderT)
|
||||||
import Control.Monad.State.Strict (StateT, evalStateT)
|
import Control.Monad.State.Strict (StateT, evalStateT)
|
||||||
import Data.Default (Default (..))
|
import Data.Default (Default (..))
|
||||||
import Data.List (intersect, transpose)
|
import Data.List (transpose)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
|
import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
|
||||||
|
@ -39,6 +39,7 @@ import Text.Pandoc.Shared (camelCaseToHyphenated, escapeURI, isURI, linesToPara,
|
||||||
import Text.Pandoc.Templates (renderTemplate)
|
import Text.Pandoc.Templates (renderTemplate)
|
||||||
import Text.DocLayout (render, literal)
|
import Text.DocLayout (render, literal)
|
||||||
import Text.Pandoc.Writers.Shared (defField, metaToContext, toLegacyTable)
|
import Text.Pandoc.Writers.Shared (defField, metaToContext, toLegacyTable)
|
||||||
|
import qualified Data.Map as M
|
||||||
|
|
||||||
data WriterState = WriterState {
|
data WriterState = WriterState {
|
||||||
}
|
}
|
||||||
|
@ -145,20 +146,13 @@ blockToDokuWiki opts (Header level _ inlines) = do
|
||||||
let eqs = T.replicate ( 7 - level ) "="
|
let eqs = T.replicate ( 7 - level ) "="
|
||||||
return $ eqs <> " " <> contents <> " " <> eqs <> "\n"
|
return $ eqs <> " " <> contents <> " " <> eqs <> "\n"
|
||||||
|
|
||||||
blockToDokuWiki _ (CodeBlock (_,classes,_) str) = do
|
blockToDokuWiki _ (CodeBlock (_,classes,_) str) =
|
||||||
let at = classes `intersect` ["actionscript", "ada", "apache", "applescript", "asm", "asp",
|
|
||||||
"autoit", "bash", "blitzbasic", "bnf", "c", "c_mac", "caddcl", "cadlisp", "cfdg", "cfm",
|
|
||||||
"cpp", "cpp-qt", "csharp", "css", "d", "delphi", "diff", "div", "dos", "eiffel", "fortran",
|
|
||||||
"freebasic", "gml", "groovy", "html4strict", "idl", "ini", "inno", "io", "java", "java5",
|
|
||||||
"javascript", "latex", "lisp", "lua", "matlab", "mirc", "mpasm", "mysql", "nsis", "objc",
|
|
||||||
"ocaml", "ocaml-brief", "oobas", "oracle8", "pascal", "perl", "php", "php-brief", "plsql",
|
|
||||||
"python", "qbasic", "rails", "reg", "robots", "ruby", "sas", "scheme", "sdlbasic",
|
|
||||||
"smalltalk", "smarty", "sql", "tcl", "", "thinbasic", "tsql", "vb", "vbnet", "vhdl",
|
|
||||||
"visualfoxpro", "winbatch", "xml", "xpp", "z80"]
|
|
||||||
return $ "<code" <>
|
return $ "<code" <>
|
||||||
(case at of
|
(case classes of
|
||||||
[] -> ">\n"
|
[] -> ""
|
||||||
(x:_) -> " " <> x <> ">\n") <> str <> "\n</code>"
|
(x:_) -> " " <> maybe x id (M.lookup x languageNames)) <>
|
||||||
|
">\n" <> str <>
|
||||||
|
(if "\n" `T.isSuffixOf` str then "" else "\n") <> "</code>\n"
|
||||||
|
|
||||||
blockToDokuWiki opts (BlockQuote blocks) = do
|
blockToDokuWiki opts (BlockQuote blocks) = do
|
||||||
contents <- blockListToDokuWiki opts blocks
|
contents <- blockListToDokuWiki opts blocks
|
||||||
|
@ -507,3 +501,19 @@ imageDims opts attr = go (toPx $ dimension Width attr) (toPx $ dimension Height
|
||||||
go (Just w) (Just h) = "?" <> w <> "x" <> h
|
go (Just w) (Just h) = "?" <> w <> "x" <> h
|
||||||
go Nothing (Just h) = "?0x" <> h
|
go Nothing (Just h) = "?0x" <> h
|
||||||
go Nothing Nothing = ""
|
go Nothing Nothing = ""
|
||||||
|
|
||||||
|
languageNames :: M.Map Text Text
|
||||||
|
languageNames = M.fromList $
|
||||||
|
[("cs", "csharp")
|
||||||
|
,("coffee", "cofeescript")
|
||||||
|
,("commonlisp", "lisp")
|
||||||
|
,("gcc", "c")
|
||||||
|
,("html", "html5")
|
||||||
|
,("makefile", "make")
|
||||||
|
,("objectivec", "objc")
|
||||||
|
,("r", "rsplus")
|
||||||
|
,("sqlmysql", "mysql")
|
||||||
|
,("sqlpostgresql", "postgresql")
|
||||||
|
,("sci", "scilab")
|
||||||
|
,("xorg", "xorgconf")
|
||||||
|
]
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* hi<code>
|
* hi<code>
|
||||||
there
|
there
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
* ok
|
* ok
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -56,6 +56,7 @@ sub status {
|
||||||
print "working";
|
print "working";
|
||||||
}
|
}
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
A list:
|
A list:
|
||||||
|
|
||||||
- item one
|
- item one
|
||||||
|
@ -87,6 +88,7 @@ sub status {
|
||||||
|
|
||||||
this code block is indented by one tab
|
this code block is indented by one tab
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
And:
|
And:
|
||||||
|
|
||||||
<code>
|
<code>
|
||||||
|
@ -95,6 +97,7 @@ And:
|
||||||
These should not be escaped: \$ \\ \> \[ \{
|
These should not be escaped: \$ \\ \> \[ \{
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
====== Lists ======
|
====== Lists ======
|
||||||
|
@ -277,6 +280,7 @@ Multiple blocks with italics:
|
||||||
<code>
|
<code>
|
||||||
{ orange code block }
|
{ orange code block }
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
> <HTML><p></HTML>orange block quote<HTML></p></HTML>
|
> <HTML><p></HTML>orange block quote<HTML></p></HTML>
|
||||||
<HTML></dd></HTML><HTML></dl></HTML>
|
<HTML></dd></HTML><HTML></dl></HTML>
|
||||||
|
|
||||||
|
@ -343,11 +347,13 @@ This should be a code block, though:
|
||||||
foo
|
foo
|
||||||
</div>
|
</div>
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
As should this:
|
As should this:
|
||||||
|
|
||||||
<code>
|
<code>
|
||||||
<div>foo</div>
|
<div>foo</div>
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
Now, nested:
|
Now, nested:
|
||||||
|
|
||||||
foo
|
foo
|
||||||
|
@ -375,6 +381,7 @@ Code block:
|
||||||
<code>
|
<code>
|
||||||
<!-- Comment -->
|
<!-- Comment -->
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
Just plain comment, with trailing spaces on the line:
|
Just plain comment, with trailing spaces on the line:
|
||||||
|
|
||||||
<HTML>
|
<HTML>
|
||||||
|
@ -385,6 +392,7 @@ Code:
|
||||||
<code>
|
<code>
|
||||||
<hr />
|
<hr />
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
Hr’s:
|
Hr’s:
|
||||||
|
|
||||||
<HTML>
|
<HTML>
|
||||||
|
@ -571,6 +579,7 @@ This should [not][] be a link.
|
||||||
<code>
|
<code>
|
||||||
[not]: /url
|
[not]: /url
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
Foo [[url/|bar]].
|
Foo [[url/|bar]].
|
||||||
|
|
||||||
Foo [[url/|biz]].
|
Foo [[url/|biz]].
|
||||||
|
@ -603,6 +612,7 @@ Auto-links should not occur here: ''%%<http://example.com/>%%''
|
||||||
or here: <http://example.com/>
|
or here: <http://example.com/>
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
====== Images ======
|
====== Images ======
|
||||||
|
@ -626,6 +636,7 @@ Subsequent blocks are indented to show that they belong to the footnote (as with
|
||||||
<code>
|
<code>
|
||||||
{ <code> }
|
{ <code> }
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.
|
If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.
|
||||||
)) 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].
|
)) 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].
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Reference in a new issue