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.State.Strict (StateT, evalStateT)
|
||||
import Data.Default (Default (..))
|
||||
import Data.List (intersect, transpose)
|
||||
import Data.List (transpose)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
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.DocLayout (render, literal)
|
||||
import Text.Pandoc.Writers.Shared (defField, metaToContext, toLegacyTable)
|
||||
import qualified Data.Map as M
|
||||
|
||||
data WriterState = WriterState {
|
||||
}
|
||||
|
@ -145,20 +146,13 @@ blockToDokuWiki opts (Header level _ inlines) = do
|
|||
let eqs = T.replicate ( 7 - level ) "="
|
||||
return $ eqs <> " " <> contents <> " " <> eqs <> "\n"
|
||||
|
||||
blockToDokuWiki _ (CodeBlock (_,classes,_) str) = do
|
||||
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"]
|
||||
blockToDokuWiki _ (CodeBlock (_,classes,_) str) =
|
||||
return $ "<code" <>
|
||||
(case at of
|
||||
[] -> ">\n"
|
||||
(x:_) -> " " <> x <> ">\n") <> str <> "\n</code>"
|
||||
(case classes of
|
||||
[] -> ""
|
||||
(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
|
||||
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 Nothing (Just h) = "?0x" <> h
|
||||
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>
|
||||
there
|
||||
</code>
|
||||
|
||||
* ok
|
||||
|
||||
```
|
||||
|
|
|
@ -56,6 +56,7 @@ sub status {
|
|||
print "working";
|
||||
}
|
||||
</code>
|
||||
|
||||
A list:
|
||||
|
||||
- item one
|
||||
|
@ -87,6 +88,7 @@ sub status {
|
|||
|
||||
this code block is indented by one tab
|
||||
</code>
|
||||
|
||||
And:
|
||||
|
||||
<code>
|
||||
|
@ -95,6 +97,7 @@ And:
|
|||
These should not be escaped: \$ \\ \> \[ \{
|
||||
</code>
|
||||
|
||||
|
||||
----
|
||||
|
||||
====== Lists ======
|
||||
|
@ -277,6 +280,7 @@ Multiple blocks with italics:
|
|||
<code>
|
||||
{ orange code block }
|
||||
</code>
|
||||
|
||||
> <HTML><p></HTML>orange block quote<HTML></p></HTML>
|
||||
<HTML></dd></HTML><HTML></dl></HTML>
|
||||
|
||||
|
@ -343,11 +347,13 @@ This should be a code block, though:
|
|||
foo
|
||||
</div>
|
||||
</code>
|
||||
|
||||
As should this:
|
||||
|
||||
<code>
|
||||
<div>foo</div>
|
||||
</code>
|
||||
|
||||
Now, nested:
|
||||
|
||||
foo
|
||||
|
@ -375,6 +381,7 @@ Code block:
|
|||
<code>
|
||||
<!-- Comment -->
|
||||
</code>
|
||||
|
||||
Just plain comment, with trailing spaces on the line:
|
||||
|
||||
<HTML>
|
||||
|
@ -385,6 +392,7 @@ Code:
|
|||
<code>
|
||||
<hr />
|
||||
</code>
|
||||
|
||||
Hr’s:
|
||||
|
||||
<HTML>
|
||||
|
@ -571,6 +579,7 @@ This should [not][] be a link.
|
|||
<code>
|
||||
[not]: /url
|
||||
</code>
|
||||
|
||||
Foo [[url/|bar]].
|
||||
|
||||
Foo [[url/|biz]].
|
||||
|
@ -603,6 +612,7 @@ Auto-links should not occur here: ''%%<http://example.com/>%%''
|
|||
or here: <http://example.com/>
|
||||
</code>
|
||||
|
||||
|
||||
----
|
||||
|
||||
====== Images ======
|
||||
|
@ -626,6 +636,7 @@ Subsequent blocks are indented to show that they belong to the footnote (as with
|
|||
<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.
|
||||
)) 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…
Reference in a new issue