git.iko.soy/typeable/pandoc
on master help sign in
DokuWiki writer: Remove broken formatting from headings (#1398)
commitc7431283d673829741cbfdcd5d5e548077648e5b authorClare Macrae <github@cfmacrae.fastmail.co.uk> dateTue 8 Jul 2014, 22:05 (12 years ago) parent5769f17
2 files changed+14−4
src/Text/Pandoc/Writers/DokuWiki.hs+11−1 tests/writer.dokuwiki+3−3
src/Text/Pandoc/Writers/DokuWiki.hs+11−1
@@ -44,6 +44,7 @@ import Text.Pandoc.Options
4444import Text.Pandoc.Shared
4545import Text.Pandoc.Writers.Shared
4646import Text.Pandoc.Templates (renderTemplate')
47+import Text.Pandoc.Walk (query)
4748import Data.List ( intersect, intercalate )
4849import Network.URI ( isURI )
4950import Control.Monad.State
@@ -85,6 +86,15 @@ pandocToDokuWiki opts (Pandoc meta blocks) = do
8586escapeString :: String -> String
8687escapeString str = substitute "__" "%%__%%" ( substitute "**" "%%**%%" ( substitute "//" "%%//%%" str ) )
8788
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+
8898-- | Convert Pandoc block element to DokuWiki.
8999blockToDokuWiki :: WriterOptions -- ^ Options
90100 -> Block -- ^ Block element
@@ -126,7 +136,7 @@ blockToDokuWiki _ (RawBlock f str)
126136blockToDokuWiki _ HorizontalRule = return "\n----\n"
127137
128138blockToDokuWiki opts (Header level _ inlines) = do
129− contents <- inlineListToDokuWiki opts inlines
139+ contents <- inlineListToDokuWiki opts ( unfancy inlines )
130140 let eqs = replicate ( 7 - level ) '='
131141 return $ eqs ++ " " ++ contents ++ " " ++ eqs ++ "\n"
132142
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
55
66====== Headers ======
77
8−===== Level 2 with an [[url|embedded link]] =====
8+===== Level 2 with an embedded link =====
99
10−==== Level 3 with //emphasis// ====
10+==== Level 3 with emphasis ====
1111
1212=== Level 4 ===
1313
@@ -15,7 +15,7 @@ This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
1515
1616====== Level 1 ======
1717
18−===== Level 2 with //emphasis// =====
18+===== Level 2 with emphasis =====
1919
2020==== Level 3 ====
2121