aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-12-15 12:38:36 -0800
committerJohn MacFarlane <[email protected]>2022-12-15 12:38:36 -0800
commit1698af8885d1d8a4e4ed9cdd03274c0e7446acd0 (patch)
treedf37b8dffb699e699daa31cf7e570c948fdff803
parent200ad70d9d9e7963e710525481cc32d16177c636 (diff)
Textile reader: handle empty paragraphs.
Also, if attributes are added explicitly to a paragraph, put it in a Div with the attributes. Closes #8487.
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs29
-rw-r--r--test/command/8487.md14
-rw-r--r--test/textile-reader.native27
3 files changed, 45 insertions, 25 deletions
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs
index e28ac52f6..9b325ce0f 100644
--- a/src/Text/Pandoc/Readers/Textile.hs
+++ b/src/Text/Pandoc/Readers/Textile.hs
@@ -121,7 +121,8 @@ blockParsers = [ codeBlock
, rawHtmlBlock
, rawLaTeXBlock'
, table
- , maybeExplicitBlock "p" para
+ , explicitBlock "p" (para <|> pure (B.para mempty))
+ , para
, mempty <$ blanklines
]
@@ -148,7 +149,7 @@ codeBlockTextile = try $ do
char ' '
let starts = ["p", "table", "bq", "bc", "pre", "h1", "h2", "h3",
"h4", "h5", "h6", "pre", "###", "notextile"]
- let ender = choice $ map explicitBlockStart starts
+ let ender = () <$ choice (map explicitBlockStart starts)
contents <- if extended
then do
f <- anyLine
@@ -436,25 +437,27 @@ ignorableRow = try $ do
_ <- anyLine
return ()
-explicitBlockStart :: PandocMonad m => Text -> TextileParser m ()
+explicitBlockStart :: PandocMonad m => Text -> TextileParser m Attr
explicitBlockStart name = try $ do
string (T.unpack name)
- attributes
+ attr <- attributes
char '.'
optional whitespace
optional endline
+ return attr
-- | Blocks like 'p' and 'table' do not need explicit block tag.
-- However, they can be used to set HTML/CSS attributes when needed.
-maybeExplicitBlock :: PandocMonad m
- => Text -- ^ block tag name
- -> TextileParser m Blocks -- ^ implicit block
- -> TextileParser m Blocks
-maybeExplicitBlock name blk = try $ do
- optional $ explicitBlockStart name
- blk
-
-
+explicitBlock :: PandocMonad m
+ => Text -- ^ block tag name
+ -> TextileParser m Blocks -- ^ implicit block
+ -> TextileParser m Blocks
+explicitBlock name blk = try $ do
+ attr <- explicitBlockStart name
+ contents <- blk
+ return $ if attr == nullAttr
+ then contents
+ else B.divWith attr contents
----------
-- Inlines
diff --git a/test/command/8487.md b/test/command/8487.md
new file mode 100644
index 000000000..7cd3e486f
--- /dev/null
+++ b/test/command/8487.md
@@ -0,0 +1,14 @@
+```
+% pandoc -f textile -t native
+p>.
+
+p=. Links:
+^D
+[ Div
+ ( "" , [] , [ ( "style" , "text-align:right;" ) ] )
+ [ Para [] ]
+, Div
+ ( "" , [] , [ ( "style" , "text-align:center;" ) ] )
+ [ Para [ Str "Links:" ] ]
+]
+```
diff --git a/test/textile-reader.native b/test/textile-reader.native
index a9c78ec8f..184c1da90 100644
--- a/test/textile-reader.native
+++ b/test/textile-reader.native
@@ -1072,18 +1072,21 @@ Pandoc
( "" , [] , [ ( "style" , "color:red;" ) ] )
[ Str "all" , Space , Str "kind" ]
]
- , Para
- [ Str "and"
- , Space
- , Str "paragraph"
- , Space
- , Str "attributes,"
- , Space
- , Str "and"
- , Space
- , Str "table"
- , Space
- , Str "attributes."
+ , Div
+ ( "" , [] , [ ( "style" , "color:green;" ) ] )
+ [ Para
+ [ Str "and"
+ , Space
+ , Str "paragraph"
+ , Space
+ , Str "attributes,"
+ , Space
+ , Str "and"
+ , Space
+ , Str "table"
+ , Space
+ , Str "attributes."
+ ]
]
, Table
( "" , [] , [] )