From 64376955745cf4fd407947eb8022460bf498176b Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 26 Aug 2017 21:30:00 -0700 Subject: Markdown writer: don't crash on Str "". --- src/Text/Pandoc/Writers/Markdown.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 95977ce17..523dfeaed 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -931,7 +931,7 @@ avoidBadWrapsInList (s:Str cs:[]) avoidBadWrapsInList (x:xs) = x : avoidBadWrapsInList xs isOrderedListMarker :: String -> Bool -isOrderedListMarker xs = (last xs `elem` ['.',')']) && +isOrderedListMarker xs = not (null xs) && (last xs `elem` ['.',')']) && isRight (runParser (anyOrderedListMarker >> eof) defaultParserState "" xs) -- cgit v1.2.3 From 8fcf66453cc4f9d1cf9413aa466477e56290d733 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 27 Aug 2017 17:01:24 -0700 Subject: RST reader: Fixed `..include::` directive. Closes #3880. --- pandoc.cabal | 1 + src/Text/Pandoc/Readers/RST.hs | 18 +++++++++--------- test/command/3880.md | 6 ++++++ test/command/3880.txt | 1 + 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 test/command/3880.md create mode 100644 test/command/3880.txt (limited to 'src/Text') diff --git a/pandoc.cabal b/pandoc.cabal index 0907ed82f..2228c7ff5 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -138,6 +138,7 @@ Extra-Source-Files: test/*.native test/command/*.md test/command/3533-rst-csv-tables.csv + test/command/3880.txt test/command/abbrevs test/command/SVG_logo-without-xml-declaration.svg test/command/SVG_logo.svg diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 190b065fb..daaeff2f0 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -219,7 +219,6 @@ block = choice [ codeBlock , directive , anchor , comment - , include , header , hrule , lineBlock -- must go before definitionList @@ -460,16 +459,16 @@ tab-width encoding -} -include :: PandocMonad m => RSTParser m Blocks -include = try $ do - string ".. include::" - skipMany spaceChar - f <- trim <$> anyLine - fields <- many $ rawFieldListItem 3 +includeDirective :: PandocMonad m + => String -> [(String, String)] -> String + -> RSTParser m Blocks +includeDirective top fields body = do + let f = trim top + guard $ not (null f) + guard $ null (trim body) -- options let (startLine :: Maybe Int) = lookup "start-line" fields >>= safeRead let (endLine :: Maybe Int) = lookup "end-line" fields >>= safeRead - guard $ not (null f) oldPos <- getPosition oldInput <- getInput containers <- stateContainers <$> getState @@ -501,7 +500,7 @@ include = try $ do Just patt -> drop 1 . dropWhile (not . (patt `isInfixOf`)) Nothing -> id) $ contentLines' - let contents' = unlines contentLines'' + let contents' = unlines contentLines'' ++ "\n" case lookup "code" fields of Just lang -> do let numberLines = lookup "number-lines" fields @@ -687,6 +686,7 @@ directive' = do $ lookup "height" fields >>= (lengthToDim . filter (not . isSpace)) case label of + "include" -> includeDirective top fields body' "table" -> tableDirective top fields body' "list-table" -> listTableDirective top fields body' "csv-table" -> csvTableDirective top fields body' diff --git a/test/command/3880.md b/test/command/3880.md new file mode 100644 index 000000000..b8edaf08f --- /dev/null +++ b/test/command/3880.md @@ -0,0 +1,6 @@ +``` +pandoc -f rst -t native +.. include:: command/3880.txt +^D +[Para [Str "hi"]] +``` diff --git a/test/command/3880.txt b/test/command/3880.txt new file mode 100644 index 000000000..45b983be3 --- /dev/null +++ b/test/command/3880.txt @@ -0,0 +1 @@ +hi -- cgit v1.2.3 From 05bb8ef4aa6faa6a4da3c54a0483d42b846733ca Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 28 Aug 2017 17:48:46 +0300 Subject: RST reader: handle blank lines correctly in line blocks (#3881) Previously pandoc would sometimes combine two line blocks separated by blanks, and ignore trailing blank lines within the line block. Test is checked to be consisted with http://rst.ninjs.org/ --- src/Text/Pandoc/Parsing.hs | 2 +- test/Tests/Readers/RST.hs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index 9ed18d4e0..2543f11f0 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -838,7 +838,7 @@ blankLineBlockLine = try (char '|' >> blankline) lineBlockLines :: Monad m => ParserT [Char] st m [String] lineBlockLines = try $ do lines' <- many1 (lineBlockLine <|> ((:[]) <$> blankLineBlockLine)) - skipMany1 $ blankline <|> blankLineBlockLine + skipMany $ blankline return lines' -- | Parse a table using 'headerParser', 'rowParser', diff --git a/test/Tests/Readers/RST.hs b/test/Tests/Readers/RST.hs index 61a2673f5..928fc1a99 100644 --- a/test/Tests/Readers/RST.hs +++ b/test/Tests/Readers/RST.hs @@ -136,6 +136,19 @@ tests = [ "line block with blank line" =: para "but must stop here") , "line block with 3 lines" =: "| a\n| b\n| c" =?> lineBlock ["a", "b", "c"] + , "line blocks with blank lines" =: T.unlines + [ "|" + , "" + , "|" + , "| a" + , "| b" + , "|" + , "" + , "|" + ] =?> + lineBlock [""] <> + lineBlock ["", "a", "b", ""] <> + lineBlock [""] , "quoted literal block using >" =: "::\n\n> quoted\n> block\n\nOrdinary paragraph" =?> codeBlock "> quoted\n> block" <> para "Ordinary paragraph" , "quoted literal block using | (not a line block)" =: "::\n\n| quoted\n| block\n\nOrdinary paragraph" -- cgit v1.2.3 From 2e26046e1334d85efab9cfc2775cf59a66e8b459 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 28 Aug 2017 23:33:21 -0700 Subject: HTML writer: ensure we don't get two style attributes for width & height. --- src/Text/Pandoc/Writers/HTML.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 9ac37a0ba..87f61126b 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -47,7 +47,7 @@ import Control.Monad.State.Strict import Data.Char (ord, toLower) import Data.Text (Text) import qualified Data.Text.Lazy as TL -import Data.List (intersperse, isPrefixOf) +import Data.List (intersperse, isPrefixOf, partition, intercalate) import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing) import Data.Monoid ((<>)) import qualified Data.Set as Set @@ -569,8 +569,14 @@ imgAttrsToHtml opts attr = do isNotDim _ = True dimensionsToAttrList :: Attr -> [(String, String)] -dimensionsToAttrList attr = (go Width) ++ (go Height) +dimensionsToAttrList attr = consolidateStyles $ go Width ++ go Height where + consolidateStyles xs = + case partition isStyle xs of + ([], _) -> xs + (ss, rest) -> ("style", intercalate ";" $ map snd ss) : rest + isStyle ("style", _) = True + isStyle _ = False go dir = case (dimension dir attr) of (Just (Pixel a)) -> [(show dir, show a)] (Just x) -> [("style", show dir ++ ":" ++ show x)] -- cgit v1.2.3 From 22a4adf4ec172545fb1ed72bb85c30dc1186de62 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 29 Aug 2017 09:04:59 -0700 Subject: Add a type sig to satisfy ghc 7.10.3. --- src/Text/Pandoc/Writers/HTML.hs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 87f61126b..1641b991c 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -571,6 +571,7 @@ imgAttrsToHtml opts attr = do dimensionsToAttrList :: Attr -> [(String, String)] dimensionsToAttrList attr = consolidateStyles $ go Width ++ go Height where + consolidateStyles :: [(String, String)] -> [(String, String)] consolidateStyles xs = case partition isStyle xs of ([], _) -> xs -- cgit v1.2.3 From 2d936ff4e08c8b77f2dac0b278b85bb7f66658af Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 29 Aug 2017 19:15:06 +0300 Subject: hlint Muse reader (#3884) --- src/Text/Pandoc/Readers/Muse.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 77f75c8c6..2947c50d6 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -261,8 +261,7 @@ verseLines = do verseTag :: PandocMonad m => MuseParser m (F Blocks) verseTag = do (_, content) <- htmlElement "verse" - parsedContent <- parseFromString verseLines content - return parsedContent + parseFromString verseLines content commentTag :: PandocMonad m => MuseParser m (F Blocks) commentTag = parseHtmlContent "comment" anyChar >> return mempty @@ -379,8 +378,8 @@ definitionListItem = try $ do pure $ do lineContent' <- lineContent pure (B.text term, [lineContent']) where - termParser = (many1 spaceChar) >> -- Initial space as required by Amusewiki, but not Emacs Muse - (many1Till anyChar $ lookAhead (void (try (spaceChar >> string "::")) <|> void newline)) + termParser = many1 spaceChar >> -- Initial space as required by Amusewiki, but not Emacs Muse + many1Till anyChar (lookAhead (void (try (spaceChar >> string "::")) <|> void newline)) endOfInput = try $ skipMany blankline >> skipSpaces >> eof twoBlankLines = try $ blankline >> skipMany1 blankline newDefinitionListItem = try $ void termParser -- cgit v1.2.3 From 14f813c3f294739f3965058e27eb228ab3ed90d5 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 29 Aug 2017 22:40:34 +0300 Subject: Muse reader: parse verse markup (#3882) --- src/Text/Pandoc/Readers/Muse.hs | 22 +++++++++++++++++++++- test/Tests/Readers/Muse.hs | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 2947c50d6..a4512cdd7 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -32,7 +32,6 @@ TODO: - {{{ }}} syntax for - Page breaks (five "*") - Headings with anchors (make it round trip with Muse writer) -- Verse markup (">") - Org tables - table.el tables - Images with attributes (floating and width) @@ -181,6 +180,7 @@ blockElements = choice [ comment , rightTag , quoteTag , verseTag + , lineBlock , bulletList , orderedList , definitionList @@ -298,6 +298,26 @@ noteBlock = try $ do blocksTillNote = many1Till block (eof <|> () <$ lookAhead noteMarker) +-- +-- Verse markup +-- + +lineVerseLine :: PandocMonad m => MuseParser m String +lineVerseLine = try $ do + char '>' + white <- many1 (char ' ' >> pure '\160') + rest <- anyLine + return $ tail white ++ rest + +blanklineVerseLine :: PandocMonad m => MuseParser m Char +blanklineVerseLine = try $ char '>' >> blankline + +lineBlock :: PandocMonad m => MuseParser m (F Blocks) +lineBlock = try $ do + lns <- many1 (pure <$> blanklineVerseLine <|> lineVerseLine) + lns' <- mapM (parseFromString' (trimInlinesF . mconcat <$> many inline)) lns + return $ B.lineBlock <$> sequence lns' + -- -- lists -- diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs index 1f3218daf..4e5e5b606 100644 --- a/test/Tests/Readers/Muse.hs +++ b/test/Tests/Readers/Muse.hs @@ -145,6 +145,30 @@ tests = , " with a continuation" ] =?> blockQuote (para "This is a quotation with a continuation") + , "Verse" =: + T.unlines [ "> This is" + , "> First stanza" + , ">" -- Emacs produces verbatim ">" here, we follow Amusewiki + , "> And this is" + , "> Second stanza" + , ">" + , "" + , ">" + , "" + , "> Another verse" + , "> is here" + ] =?> + lineBlock [ "This is" + , "First stanza" + , "" + , "And this is" + , "\160\160Second stanza" + , "" + ] <> + lineBlock [ "" ] <> + lineBlock [ "Another verse" + , "\160\160\160is here" + ] ] , "Quote tag" =: "Hello, world" =?> blockQuote (para $ text "Hello, world") , "Verse tag" =: -- cgit v1.2.3 From 50ec64ffbc56db2c2312feb606df4bc36142b3f0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 30 Aug 2017 17:05:12 -0700 Subject: HTML reader: improved handling of figure. Previously we had a parse failure if the figure contained anything besides an image and caption. --- src/Text/Pandoc/Readers/HTML.hs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index d85488478..257c16735 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -58,7 +58,7 @@ import Data.Maybe ( fromMaybe, isJust, isNothing ) import Data.List.Split ( wordsBy ) import Data.List ( intercalate, isPrefixOf ) import Data.Char ( isDigit, isLetter, isAlphaNum ) -import Control.Monad ( guard, mzero, void, unless, mplus ) +import Control.Monad ( guard, mzero, void, unless, mplus, msum ) import Control.Arrow ((***)) import Control.Applicative ( (<|>) ) import Data.Monoid (First (..)) @@ -576,23 +576,23 @@ pPara = do return $ B.para contents pFigure :: PandocMonad m => TagParser m Blocks -pFigure = do +pFigure = try $ do TagOpen _ _ <- pSatisfy (matchTagOpen "figure" []) skipMany pBlank - let pImg = pOptInTag "p" pImage <* skipMany pBlank - pCapt = option mempty $ pInTags "figcaption" inline <* skipMany pBlank - pImgCapt = do - img <- pImg - cap <- pCapt - return (img, cap) - pCaptImg = do - cap <- pCapt - img <- pImg - return (img, cap) - (imgMany, caption) <- pImgCapt <|> pCaptImg + let pImg = (\x -> (Just x, Nothing)) <$> + (pOptInTag "p" pImage <* skipMany pBlank) + pCapt = (\x -> (Nothing, Just x)) <$> + (pInTags "figcaption" inline <* skipMany pBlank) + pSkip = (Nothing, Nothing) <$ pSatisfy (not . matchTagClose "figure") + res <- many (pImg <|> pCapt <|> pSkip) + let mbimg = msum $ map fst res + let mbcap = msum $ map snd res TagClose _ <- pSatisfy (matchTagClose "figure") - let (Image attr _ (url, tit)):_ = B.toList imgMany - return $ B.para $ B.imageWith attr url ("fig:" ++ tit) caption + let caption = fromMaybe mempty mbcap + case B.toList <$> mbimg of + Just [Image attr _ (url, tit)] -> + return $ B.para $ B.imageWith attr url ("fig:" ++ tit) caption + Nothing -> mzero pCodeBlock :: PandocMonad m => TagParser m Blocks pCodeBlock = try $ do @@ -961,7 +961,7 @@ blockHtmlTags = Set.fromList "dir", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", - "isindex", "main", "menu", "noframes", "ol", "output", "p", "pre", + "isindex", "main", "menu", "meta", "noframes", "ol", "output", "p", "pre", "section", "table", "tbody", "textarea", "thead", "tfoot", "ul", "dd", "dt", "frameset", "li", "tbody", "td", "tfoot", @@ -1048,7 +1048,7 @@ x `closes` "p" | x `elem` ["address", "article", "aside", "blockquote", "dir", "div", "dl", "fieldset", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hr", "main", "menu", "nav", "ol", "p", "pre", "section", "table", "ul"] = True -"meta" `closes` "meta" = True +_ `closes` "meta" = True "form" `closes` "form" = True "label" `closes` "label" = True "map" `closes` "map" = True -- cgit v1.2.3 From 6a6c3858b47671f02f4f50ca2d6ab97d280a0f49 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Thu, 31 Aug 2017 18:02:07 +0200 Subject: Org writer: stop using raw HTML to wrap divs Div's are difficult to translate into org syntax, as there are multiple div-like structures (drawers, special blocks, greater blocks) which all have their advantages and disadvantages. Previously pandoc would use raw HTML to preserve the full div information; this was rarely useful and resulted in visual clutter. Div-rendering was changed to discard the div's classes and key-value pairs if there is no natural way to translate the div into an org structure. Closes: #3771 --- src/Text/Pandoc/Writers/Org.hs | 63 +++++++++++++++++------------------------- test/command/3771.md | 14 ++++++++++ 2 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 test/command/3771.md (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs index 48f17c4fb..88f42acd4 100644 --- a/src/Text/Pandoc/Writers/Org.hs +++ b/src/Text/Pandoc/Writers/Org.hs @@ -129,36 +129,25 @@ blockToOrg (Div (_,classes@(cls:_),kvs) bs) | "drawer" `elem` classes = do blankline $$ contents $$ blankline $$ drawerEndTag $$ blankline -blockToOrg (Div attrs bs) = do +blockToOrg (Div (ident, classes, kv) bs) = do contents <- blockListToOrg bs + -- if one class looks like the name of a greater block then output as such: + -- The ID, if present, is added via the #+NAME keyword; other classes and + -- key-value pairs are kept as #+ATTR_HTML attributes. let isGreaterBlockClass = (`elem` ["center", "quote"]) . map toLower - return $ case attrs of - ("", [], []) -> - -- nullAttr, treat contents as if it wasn't wrapped - blankline $$ contents $$ blankline - (ident, [], []) -> - -- only an id: add id as an anchor, unwrap the rest - blankline $$ "<<" <> text ident <> ">>" $$ contents $$ blankline - (ident, classes, kv) -> - -- if one class looks like the name of a greater block then output as - -- such: The ID, if present, is added via the #+NAME keyword; other - -- classes and key-value pairs are kept as #+ATTR_HTML attributes. - let - (blockTypeCand, classes') = partition isGreaterBlockClass classes - in case blockTypeCand of - (blockType:classes'') -> - blankline $$ attrHtml (ident, classes'' <> classes', kv) $$ - "#+BEGIN_" <> text blockType $$ contents $$ - "#+END_" <> text blockType $$ blankline - _ -> - -- fallback: wrap in div tags - let - startTag = tagWithAttrs "div" attrs - endTag = text "" - in blankline $$ "#+BEGIN_HTML" $$ - nest 2 startTag $$ "#+END_HTML" $$ blankline $$ - contents $$ blankline $$ "#+BEGIN_HTML" $$ - nest 2 endTag $$ "#+END_HTML" $$ blankline + (blockTypeCand, classes') = partition isGreaterBlockClass classes + return $ case blockTypeCand of + (blockType:classes'') -> + blankline $$ attrHtml (ident, classes'' <> classes', kv) $$ + "#+BEGIN_" <> text blockType $$ contents $$ + "#+END_" <> text blockType $$ blankline + _ -> + -- fallback with id: add id as an anchor if present, discard classes and + -- key-value pairs, unwrap the content. + let contents' = if not (null ident) + then "<<" <> text ident <> ">>" $$ contents + else contents + in blankline $$ contents' $$ blankline blockToOrg (Plain inlines) = inlineListToOrg inlines -- title beginning with fig: indicates that the image is a figure blockToOrg (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do @@ -173,7 +162,7 @@ blockToOrg (Para inlines) = do blockToOrg (LineBlock lns) = do let splitStanza [] = [] splitStanza xs = case break (== mempty) xs of - (l, []) -> l : [] + (l, []) -> [l] (l, _:r) -> l : splitStanza r let joinWithLinefeeds = nowrap . mconcat . intersperse cr let joinWithBlankLines = mconcat . intersperse blankline @@ -213,7 +202,7 @@ blockToOrg (Table caption' _ _ headers rows) = do caption'' <- inlineListToOrg caption' let caption = if null caption' then empty - else ("#+CAPTION: " <> caption'') + else "#+CAPTION: " <> caption'' headers' <- mapM blockListToOrg headers rawRows <- mapM (mapM blockListToOrg) rows let numChars = maximum . map offset @@ -289,8 +278,8 @@ propertiesDrawer (ident, classes, kv) = let drawerStart = text ":PROPERTIES:" drawerEnd = text ":END:" - kv' = if (classes == mempty) then kv else ("CLASS", unwords classes):kv - kv'' = if (ident == mempty) then kv' else ("CUSTOM_ID", ident):kv' + kv' = if classes == mempty then kv else ("CLASS", unwords classes):kv + kv'' = if ident == mempty then kv' else ("CUSTOM_ID", ident):kv' properties = vcat $ map kvToOrgProperty kv'' in drawerStart <> cr <> properties <> cr <> drawerEnd @@ -303,7 +292,7 @@ attrHtml :: Attr -> Doc attrHtml ("" , [] , []) = mempty attrHtml (ident, classes, kvs) = let - name = if (null ident) then mempty else "#+NAME: " <> text ident <> cr + name = if null ident then mempty else "#+NAME: " <> text ident <> cr keyword = "#+ATTR_HTML" classKv = ("class", unwords classes) kvStrings = map (\(k,v) -> ":" <> k <> " " <> v) (classKv:kvs) @@ -370,19 +359,19 @@ inlineToOrg SoftBreak = do WrapPreserve -> return cr WrapAuto -> return space WrapNone -> return space -inlineToOrg (Link _ txt (src, _)) = do +inlineToOrg (Link _ txt (src, _)) = case txt of [Str x] | escapeURI x == src -> -- autolink - do return $ "[[" <> text (orgPath x) <> "]]" + return $ "[[" <> text (orgPath x) <> "]]" _ -> do contents <- inlineListToOrg txt return $ "[[" <> text (orgPath src) <> "][" <> contents <> "]]" -inlineToOrg (Image _ _ (source, _)) = do +inlineToOrg (Image _ _ (source, _)) = return $ "[[" <> text (orgPath source) <> "]]" inlineToOrg (Note contents) = do -- add to notes in state notes <- gets stNotes modify $ \st -> st { stNotes = contents:notes } - let ref = show $ (length notes) + 1 + let ref = show $ length notes + 1 return $ "[fn:" <> text ref <> "]" orgPath :: String -> String diff --git a/test/command/3771.md b/test/command/3771.md new file mode 100644 index 000000000..1d3a75ae1 --- /dev/null +++ b/test/command/3771.md @@ -0,0 +1,14 @@ +``` +% pandoc -f html -t org +
+ Today is a nice day. +
+
+ Tomorrow will be rainy. +
+^D +Today is a nice day. + +<> +Tomorrow will be rainy. +``` -- cgit v1.2.3 From 1d0805ce414398d5ff70c9ed3dbe1288356c7dd9 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 4 Sep 2017 18:11:26 -0700 Subject: HTML reader: Fix pattern match. --- src/Text/Pandoc/Readers/HTML.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index 257c16735..2093be19c 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -592,7 +592,7 @@ pFigure = try $ do case B.toList <$> mbimg of Just [Image attr _ (url, tit)] -> return $ B.para $ B.imageWith attr url ("fig:" ++ tit) caption - Nothing -> mzero + _ -> mzero pCodeBlock :: PandocMonad m => TagParser m Blocks pCodeBlock = try $ do -- cgit v1.2.3 From c09b586147d607f645a639a47c7781e8d8655e20 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 5 Sep 2017 07:22:40 +0300 Subject: Muse reader: parse
tag (#3888) --- src/Text/Pandoc/Readers/Muse.hs | 7 +++++++ test/Tests/Readers/Muse.hs | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index a4512cdd7..1951a47af 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -179,6 +179,7 @@ blockElements = choice [ comment , centerTag , rightTag , quoteTag + , divTag , verseTag , lineBlock , bulletList @@ -245,6 +246,12 @@ rightTag = blockTag id "right" quoteTag :: PandocMonad m => MuseParser m (F Blocks) quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote" +--
tag is supported by Emacs Muse, but not Amusewiki 2.025 +divTag :: PandocMonad m => MuseParser m (F Blocks) +divTag = do + (attrs, content) <- parseHtmlContentWithAttrs "div" block + return $ (B.divWith attrs) <$> mconcat content + verseLine :: PandocMonad m => MuseParser m String verseLine = do line <- anyLine <|> many1Till anyChar eof diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs index 4e5e5b606..714736c7f 100644 --- a/test/Tests/Readers/Muse.hs +++ b/test/Tests/Readers/Muse.hs @@ -145,6 +145,14 @@ tests = , " with a continuation" ] =?> blockQuote (para "This is a quotation with a continuation") + , testGroup "Div" + [ "Div without id" =: + "
Foo bar
" =?> + divWith nullAttr (para "Foo bar") + , "Div with id" =: + "
Foo bar
" =?> + divWith ("foo", [], []) (para "Foo bar") + ] , "Verse" =: T.unlines [ "> This is" , "> First stanza" -- cgit v1.2.3 From 9fdc089cd85e46148720f368644e8badd168f5b8 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 4 Sep 2017 21:56:06 -0700 Subject: Plain writer: don't use   to separate list and indented code. There's no need for it in this context, since this isn't to be interpreted using Markdown rules. --- src/Text/Pandoc/Writers/Markdown.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 523dfeaed..9d6064af6 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -787,6 +787,7 @@ blockListToMarkdown :: PandocMonad m -> MD m Doc blockListToMarkdown opts blocks = do inlist <- asks envInList + isPlain <- asks envPlain -- a) insert comment between list and indented code block, or the -- code block will be treated as a list continuation paragraph -- b) change Plain to Para unless it's followed by a RawBlock @@ -813,9 +814,11 @@ blockListToMarkdown opts blocks = do isListBlock (OrderedList _ _) = True isListBlock (DefinitionList _) = True isListBlock _ = False - commentSep = if isEnabled Ext_raw_html opts - then RawBlock "html" "\n" - else RawBlock "markdown" " \n" + commentSep = if isPlain + then Null + else if isEnabled Ext_raw_html opts + then RawBlock "html" "\n" + else RawBlock "markdown" " \n" mapM (blockToMarkdown opts) (fixBlocks blocks) >>= return . cat getKey :: Doc -> Key -- cgit v1.2.3 From 350c282f205f48c6d0f7a96bf349b585a16fbcf4 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 5 Sep 2017 19:41:27 +0300 Subject: Muse reader: require at least one space char after * in header (#3895) --- src/Text/Pandoc/Readers/Muse.hs | 2 +- test/Tests/Readers/Muse.hs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 1951a47af..63bdfcba7 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -213,7 +213,7 @@ header = try $ do getPosition >>= \pos -> guard (st == NullState && q == NoQuote && sourceColumn pos == 1) level <- liftM length $ many1 $ char '*' guard $ level <= 5 - skipSpaces + spaceChar content <- trimInlinesF . mconcat <$> manyTill inline newline attr <- registerHeader ("", [], []) (runF content defaultParserState) return $ B.headerWith attr level <$> content diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs index 714736c7f..d9222b1dc 100644 --- a/test/Tests/Readers/Muse.hs +++ b/test/Tests/Readers/Muse.hs @@ -224,6 +224,7 @@ tests = , "Subsubsection" =: "***** Fifth level\n" =?> header 5 "Fifth level" + , "Whitespace is required after *" =: "**Not a header\n" =?> para "**Not a header" , "No headers in footnotes" =: T.unlines [ "Foo[1]" , "[1] * Bar" -- cgit v1.2.3 From 146a10780e05006f97cd4ba3a0dd02b903533db6 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 5 Sep 2017 09:55:42 -0700 Subject: LaTeX reader: support `\k` ogonek accent. --- src/Text/Pandoc/Readers/LaTeX.hs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 06e112cef..7b7ac1c01 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -961,6 +961,10 @@ hacek 'Z' = "Ž" hacek 'z' = "ž" hacek c = [c] +ogonek :: Char -> String +ogonek 'a' = "ą" +ogonek c = [c] + breve :: Char -> String breve 'A' = "Ă" breve 'a' = "ă" @@ -1286,6 +1290,7 @@ inlineCommands = M.fromList $ , ("c", option (str "c") $ try $ tok >>= accent cedilla) , ("v", option (str "v") $ try $ tok >>= accent hacek) , ("u", option (str "u") $ try $ tok >>= accent breve) + , ("k", option (str "k") $ try $ tok >>= accent ogonek) , ("i", lit "i") , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState guard $ not inTableCell -- cgit v1.2.3 From d62c4a92470de3b0aa73ddb3fe921a1f9b154b41 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 5 Sep 2017 10:58:34 -0700 Subject: LaTeX reader: Improve handling of accents. Handle ogonek, and fall back correctly with forms like `\"{}`. --- src/Text/Pandoc/Readers/LaTeX.hs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 7b7ac1c01..b6b53e1fc 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -770,11 +770,13 @@ keyval = try $ do keyvals :: PandocMonad m => LP m [(String, String)] keyvals = try $ symbol '[' >> manyTill keyval (symbol ']') -accent :: (Char -> String) -> Inlines -> LP m Inlines -accent f ils = +accent :: PandocMonad m => Char -> (Char -> String) -> LP m Inlines +accent c f = try $ do + ils <- tok case toList ils of (Str (x:xs) : ys) -> return $ fromList (Str (f x ++ xs) : ys) - [] -> mzero + [Space] -> return $ str [c] + [] -> return $ str [c] _ -> return ils grave :: Char -> String @@ -1279,18 +1281,18 @@ inlineCommands = M.fromList $ , ("copyright", lit "©") , ("textasciicircum", lit "^") , ("textasciitilde", lit "~") - , ("H", try $ tok >>= accent hungarumlaut) - , ("`", option (str "`") $ try $ tok >>= accent grave) - , ("'", option (str "'") $ try $ tok >>= accent acute) - , ("^", option (str "^") $ try $ tok >>= accent circ) - , ("~", option (str "~") $ try $ tok >>= accent tilde) - , ("\"", option (str "\"") $ try $ tok >>= accent umlaut) - , (".", option (str ".") $ try $ tok >>= accent dot) - , ("=", option (str "=") $ try $ tok >>= accent macron) - , ("c", option (str "c") $ try $ tok >>= accent cedilla) - , ("v", option (str "v") $ try $ tok >>= accent hacek) - , ("u", option (str "u") $ try $ tok >>= accent breve) - , ("k", option (str "k") $ try $ tok >>= accent ogonek) + , ("H", accent '\779' hungarumlaut) + , ("`", accent '`' grave) + , ("'", accent '\'' acute) + , ("^", accent '^' circ) + , ("~", accent '~' tilde) + , ("\"", accent '\776' umlaut) + , (".", accent '\775' dot) + , ("=", accent '\772' macron) + , ("c", accent '\807' cedilla) + , ("v", accent 'ˇ' hacek) + , ("u", accent '\774' breve) + , ("k", accent '\808' ogonek) , ("i", lit "i") , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState guard $ not inTableCell -- cgit v1.2.3 From bc5624dac2da7674f42838db8672520e8949c9db Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 5 Sep 2017 13:46:44 -0700 Subject: Markdown writer: make Span with null attribute transparent. That is, we don't use brackets or `` tags to mark spans when there are no attributes; we simply output the contents. --- src/Text/Pandoc/Writers/Markdown.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 9d6064af6..3dbfe3f11 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -949,11 +949,10 @@ inlineToMarkdown opts (Span attrs ils) = do contents <- inlineListToMarkdown opts ils return $ case plain of True -> contents - False | isEnabled Ext_bracketed_spans opts -> + False | attrs == nullAttr -> contents + | isEnabled Ext_bracketed_spans opts -> "[" <> contents <> "]" <> - if attrs == nullAttr - then "{}" - else linkAttributes opts attrs + linkAttributes opts attrs | isEnabled Ext_raw_html opts || isEnabled Ext_native_spans opts -> tagWithAttrs "span" attrs <> contents <> text "" -- cgit v1.2.3 From 0b05222a9c915d2062e416d177d36af4b474e0c2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 5 Sep 2017 13:54:44 -0700 Subject: LaTeX reader: Better support for ogonek accents. --- src/Text/Pandoc/Readers/LaTeX.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index b6b53e1fc..d0e95bd85 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -965,6 +965,15 @@ hacek c = [c] ogonek :: Char -> String ogonek 'a' = "ą" +ogonek 'e' = "ę" +ogonek 'o' = "ǫ" +ogonek 'i' = "į" +ogonek 'u' = "ų" +ogonek 'A' = "Ą" +ogonek 'E' = "Ę" +ogonek 'I' = "Į" +ogonek 'O' = "Ǫ" +ogonek 'U' = "Ų" ogonek c = [c] breve :: Char -> String @@ -1293,6 +1302,7 @@ inlineCommands = M.fromList $ , ("v", accent 'ˇ' hacek) , ("u", accent '\774' breve) , ("k", accent '\808' ogonek) + , ("textogonekcentered", accent '\808' ogonek) , ("i", lit "i") , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState guard $ not inTableCell -- cgit v1.2.3 From 743413a5b506351499fa2fb66d4184d74e125c54 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 6 Sep 2017 18:48:06 +0300 Subject: Muse reader: Allow finishing header with EOF (#3897) --- src/Text/Pandoc/Readers/Muse.hs | 14 +++++++++----- test/Tests/Readers/Muse.hs | 12 ++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 63bdfcba7..2454057fa 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE FlexibleContexts #-} {- Copyright (C) 2017 Alexander Krotov @@ -100,6 +101,9 @@ parseBlocks = do -- utility functions -- +eol :: Stream s m Char => ParserT s st m () +eol = void newline <|> eof + nested :: PandocMonad m => MuseParser m a -> MuseParser m a nested p = do nestlevel <- stateMaxNestingLevel <$> getState @@ -195,7 +199,7 @@ comment = try $ do char ';' space many $ noneOf "\n" - void newline <|> eof + eol return mempty separator :: PandocMonad m => MuseParser m (F Blocks) @@ -203,7 +207,7 @@ separator = try $ do string "----" many $ char '-' many spaceChar - void newline <|> eof + eol return $ return B.horizontalRule header :: PandocMonad m => MuseParser m (F Blocks) @@ -214,7 +218,7 @@ header = try $ do level <- liftM length $ many1 $ char '*' guard $ level <= 5 spaceChar - content <- trimInlinesF . mconcat <$> manyTill inline newline + content <- trimInlinesF . mconcat <$> manyTill inline eol attr <- registerHeader ("", [], []) (runF content defaultParserState) return $ B.headerWith attr level <$> content @@ -464,10 +468,10 @@ museAppendElement tbl element = tableCell :: PandocMonad m => MuseParser m (F Blocks) tableCell = try $ liftM B.plain . trimInlinesF . mconcat <$> manyTill inline (lookAhead cellEnd) - where cellEnd = try $ void (many1 spaceChar >> char '|') <|> void newline <|> eof + where cellEnd = try $ void (many1 spaceChar >> char '|') <|> eol tableElements :: PandocMonad m => MuseParser m [MuseTableElement] -tableElements = tableParseElement `sepEndBy1` (void newline <|> eof) +tableElements = tableParseElement `sepEndBy1` eol elementsToTable :: [MuseTableElement] -> F MuseTable elementsToTable = foldM museAppendElement emptyTable diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs index d9222b1dc..dac167a92 100644 --- a/test/Tests/Readers/Muse.hs +++ b/test/Tests/Readers/Muse.hs @@ -210,21 +210,21 @@ tests = ] , testGroup "Headers" [ "Part" =: - "* First level\n" =?> + "* First level" =?> header 1 "First level" , "Chapter" =: - "** Second level\n" =?> + "** Second level" =?> header 2 "Second level" , "Section" =: - "*** Third level\n" =?> + "*** Third level" =?> header 3 "Third level" , "Subsection" =: - "**** Fourth level\n" =?> + "**** Fourth level" =?> header 4 "Fourth level" , "Subsubsection" =: - "***** Fifth level\n" =?> + "***** Fifth level" =?> header 5 "Fifth level" - , "Whitespace is required after *" =: "**Not a header\n" =?> para "**Not a header" + , "Whitespace is required after *" =: "**Not a header" =?> para "**Not a header" , "No headers in footnotes" =: T.unlines [ "Foo[1]" , "[1] * Bar" -- cgit v1.2.3 From a90f131937460f21005a997e0a1f10b930b203b2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 7 Sep 2017 22:05:22 -0700 Subject: LaTeX writer: use proper code for list enumerators. This should fix problems with lists that don't use arabic numerals. Closes #3891. --- src/Text/Pandoc/Writers/LaTeX.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 4a81cd245..2da087077 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -628,6 +628,7 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do put $ st {stOLLevel = oldlevel + 1} items <- mapM listItemToLaTeX lst modify (\s -> s {stOLLevel = oldlevel}) + let beamer = stBeamer st let tostyle x = case numstyle of Decimal -> "\\arabic" <> braces x UpperRoman -> "\\Roman" <> braces x @@ -641,11 +642,21 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do TwoParens -> parens x Period -> x <> "." _ -> x <> "." + let exemplar = case numstyle of + Decimal -> "1" + UpperRoman -> "I" + LowerRoman -> "i" + UpperAlpha -> "A" + LowerAlpha -> "a" + Example -> "1" + DefaultStyle -> "1" let enum = text $ "enum" ++ map toLower (toRomanNumeral oldlevel) let stylecommand = if numstyle == DefaultStyle && numdelim == DefaultDelim then empty - else "\\def" <> "\\label" <> enum <> - braces (todelim $ tostyle enum) + else if beamer + then brackets (todelim exemplar) + else "\\def" <> "\\label" <> enum <> + braces (todelim $ tostyle enum) let resetcounter = if start == 1 || oldlevel > 4 then empty else "\\setcounter" <> braces enum <> -- cgit v1.2.3 From 5fc4980216bf0a6b425827417655991859cba5ec Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 7 Sep 2017 22:10:13 -0700 Subject: Markdown writer: Escape pipe characters when `pipe_tables` enabled. Closes #3887. --- src/Text/Pandoc/Writers/Markdown.hs | 1 + test/command/3497.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 3dbfe3f11..0221ba6ef 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -288,6 +288,7 @@ escapeString opts (c:cs) = | otherwise -> ">" ++ escapeString opts cs _ | c `elem` ['\\','`','*','_','[',']','#'] -> '\\':c:escapeString opts cs + '|' | isEnabled Ext_pipe_tables opts -> '\\':'|':escapeString opts cs '^' | isEnabled Ext_superscript opts -> '\\':'^':escapeString opts cs '~' | isEnabled Ext_subscript opts -> '\\':'~':escapeString opts cs '$' | isEnabled Ext_tex_math_dollars opts -> '\\':'$':escapeString opts cs diff --git a/test/command/3497.md b/test/command/3497.md index 326817b0d..ca591cdd6 100644 --- a/test/command/3497.md +++ b/test/command/3497.md @@ -46,6 +46,6 @@ Also escape things that might become line blocks or tables: % pandoc -t markdown \| hi \| ^D -\| hi | +\| hi \| ``` -- cgit v1.2.3