git.iko.soy/typeable/pandoc
on master help sign in
DokuWiki writer: Remove broken formatting from headings (#1398)
c743128Clare Macrae
src/Text/Pandoc/Writers/DokuWiki.hs+11−1
@@ -44,6 +44,7 @@ import Text.Pandoc.Options
44import Text.Pandoc.Shared
44import Text.Pandoc.Shared
45import Text.Pandoc.Writers.Shared
45import Text.Pandoc.Writers.Shared
46import Text.Pandoc.Templates (renderTemplate')
46import Text.Pandoc.Templates (renderTemplate')
47+import Text.Pandoc.Walk (query)
47import Data.List ( intersect, intercalate )
48import Data.List ( intersect, intercalate )
48import Network.URI ( isURI )
49import Network.URI ( isURI )
49import Control.Monad.State
50import Control.Monad.State
@@ -85,6 +86,15 @@ pandocToDokuWiki opts (Pandoc meta blocks) = do
85escapeString :: String -> String
86escapeString :: String -> String
86escapeString str = substitute "__" "%%__%%" ( substitute "**" "%%**%%" ( substitute "//" "%%//%%" str ) )
87escapeString str = substitute "__" "%%__%%" ( substitute "**" "%%**%%" ( substitute "//" "%%//%%" str ) )
87
88
89+-- | Remove unsupported formatting from headings
90+unfancy :: [Inline] -> [Inline]
91+unfancy = query plainContent
92+
93+plainContent :: Inline -> [Inline]
94+plainContent (Str x) = [Str x]
95+plainContent Space = [Space]
96+plainContent _ = []
97+
88-- | Convert Pandoc block element to DokuWiki.
98-- | Convert Pandoc block element to DokuWiki.
89blockToDokuWiki :: WriterOptions -- ^ Options
99blockToDokuWiki :: WriterOptions -- ^ Options
90 -> Block -- ^ Block element
100 -> Block -- ^ Block element
@@ -126,7 +136,7 @@ blockToDokuWiki _ (RawBlock f str)
126blockToDokuWiki _ HorizontalRule = return "\n----\n"
136blockToDokuWiki _ HorizontalRule = return "\n----\n"
127
137
128blockToDokuWiki opts (Header level _ inlines) = do
138blockToDokuWiki opts (Header level _ inlines) = do
129− contents <- inlineListToDokuWiki opts inlines
139+ contents <- inlineListToDokuWiki opts ( unfancy inlines )
130 let eqs = replicate ( 7 - level ) '='
140 let eqs = replicate ( 7 - level ) '='
131 return $ eqs ++ " " ++ contents ++ " " ++ eqs ++ "\n"
141 return $ eqs ++ " " ++ contents ++ " " ++ eqs ++ "\n"
132
142
tests/writer.dokuwiki+3−3
@@ -5,9 +5,9 @@ This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
5
5
6====== Headers ======
6====== Headers ======
7
7
8−===== Level 2 with an [[url|embedded link]] =====
8+===== Level 2 with an embedded link =====
9
9
10−==== Level 3 with //emphasis// ====
10+==== Level 3 with emphasis ====
11
11
12=== Level 4 ===
12=== Level 4 ===
13
13
@@ -15,7 +15,7 @@ This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
15
15
16====== Level 1 ======
16====== Level 1 ======
17
17
18−===== Level 2 with //emphasis// =====
18+===== Level 2 with emphasis =====
19
19
20==== Level 3 ====
20==== Level 3 ====
21
21