git.iko.soy/typeable/pandoc
on master help sign in
Muse: move inline list normalization to writer
commit0cfd764d27bc03b59871e477d6bfd7341f4916b0 authorAlexander Krotov <ilabdsf@gmail.com> dateFri 24 Nov 2017, 12:17 (9 years ago) parentcd85c73
4 files changed+14−21
src/Text/Pandoc/Readers/Muse.hs+4−18 src/Text/Pandoc/Writers/Muse.hs+9−1 test/Tests/Readers/Muse.hs−2 test/Tests/Writers/Muse.hs+1
src/Text/Pandoc/Readers/Muse.hs+4−18
@@ -139,20 +139,6 @@ parseHtmlContentWithAttrs tag parser = do
139139parseHtmlContent :: PandocMonad m => String -> MuseParser m a -> MuseParser m [a]
140140parseHtmlContent tag p = fmap snd (parseHtmlContentWithAttrs tag p)
141141
142−normalizeInlineList :: [Inline] -> [Inline]
143−normalizeInlineList (Code a1 x1 : Code a2 x2 : ils) | a1 == a2
144− = normalizeInlineList $ Code a1 (x1 ++ x2) : ils
145−normalizeInlineList (RawInline f1 x1 : RawInline f2 x2 : ils) | f1 == f2
146− = normalizeInlineList $ RawInline f1 (x1 ++ x2) : ils
147−normalizeInlineList (x:xs) = x : normalizeInlineList xs
148−normalizeInlineList [] = []
149−
150−normalizeInlines :: Inlines -> Inlines
151−normalizeInlines = B.fromList . normalizeInlineList . B.toList . B.trimInlines
152−
153−normalizeInlinesF :: Future s Inlines -> Future s Inlines
154−normalizeInlinesF = liftM normalizeInlines
155−
156142--
157143-- directive parsers
158144--
@@ -164,7 +150,7 @@ parseDirective = do
164150 space
165151 spaces
166152 raw <- manyTill anyChar eol
167− value <- parseFromString (normalizeInlinesF . mconcat <$> many inline) raw
153+ value <- parseFromString (trimInlinesF . mconcat <$> many inline) raw
168154 return (key, value)
169155
170156directive :: PandocMonad m => MuseParser m ()
@@ -231,7 +217,7 @@ header = try $ do
231217 level <- fmap length $ many1 $ char '*'
232218 guard $ level <= 5
233219 spaceChar
234− content <- normalizeInlinesF . mconcat <$> manyTill inline eol
220+ content <- trimInlinesF . mconcat <$> manyTill inline eol
235221 attr <- registerHeader ("", [], []) (runF content defaultParserState)
236222 return $ B.headerWith attr level <$> content
237223
@@ -300,7 +286,7 @@ verseLines :: PandocMonad m => MuseParser m (F Blocks)
300286verseLines = do
301287 optionMaybe blankline -- Skip blankline after opening tag on separate line
302288 lns <- many verseLine
303− lns' <- mapM (parseFromString' (normalizeInlinesF . mconcat <$> many inline)) lns
289+ lns' <- mapM (parseFromString' (trimInlinesF . mconcat <$> many inline)) lns
304290 return $ B.lineBlock <$> sequence lns'
305291
306292verseTag :: PandocMonad m => MuseParser m (F Blocks)
@@ -317,7 +303,7 @@ para = do
317303 indent <- length <$> many spaceChar
318304 st <- stateParserContext <$> getState
319305 let f = if st /= ListItemState && indent >= 2 && indent < 6 then B.blockQuote else id
320− fmap (f . B.para) . normalizeInlinesF . mconcat <$> many1Till inline endOfParaElement
306+ fmap (f . B.para) . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
321307 where
322308 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
323309 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
src/Text/Pandoc/Writers/Muse.hs+9−1
@@ -291,11 +291,19 @@ conditionalEscapeString s =
291291 then escapeString s
292292 else s
293293
294+normalizeInlineList :: [Inline] -> [Inline]
295+normalizeInlineList (Code a1 x1 : Code a2 x2 : ils) | a1 == a2
296+ = normalizeInlineList $ Code a1 (x1 ++ x2) : ils
297+normalizeInlineList (RawInline f1 x1 : RawInline f2 x2 : ils) | f1 == f2
298+ = normalizeInlineList $ RawInline f1 (x1 ++ x2) : ils
299+normalizeInlineList (x:xs) = x : normalizeInlineList xs
300+normalizeInlineList [] = []
301+
294302-- | Convert list of Pandoc inline elements to Muse.
295303inlineListToMuse :: PandocMonad m
296304 => [Inline]
297305 -> StateT WriterState m Doc
298−inlineListToMuse lst = liftM hcat (mapM inlineToMuse lst)
306+inlineListToMuse lst = liftM hcat (mapM inlineToMuse (normalizeInlineList lst))
299307
300308-- | Convert Pandoc inline element to Muse.
301309inlineToMuse :: PandocMonad m
test/Tests/Readers/Muse.hs−2
@@ -125,8 +125,6 @@ tests =
125125
126126 , "Verbatim inside code" =: "<code><verbatim>foo</verbatim></code>" =?> para (code "<verbatim>foo</verbatim>")
127127
128− , "Code normalization" =: "<code><code><</code><code>/code></code>" =?> para (code "<code></code>")
129−
130128 , testGroup "Links"
131129 [ "Link without description" =:
132130 "[[https://amusewiki.org/]]" =?>
test/Tests/Writers/Muse.hs+1
@@ -300,6 +300,7 @@ tests = [ testGroup "block elements"
300300 , testGroup "code"
301301 [ "simple" =: code "foo" =?> "<code>foo</code>"
302302 , "escape tag" =: code "<code>foo = bar</code> baz" =?> "<code><code>foo = bar<</code><code>/code> baz</code>"
303+ , "normalization" =: code "</co" <> code "de>" =?> "<code><</code><code>/code></code>"
303304 ]
304305 , testGroup "spaces"
305306 [ "space" =: text "a" <> space <> text "b" =?> "a b"