summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Leung <29217594+leungbk@users.noreply.github.com>2022-05-02 08:25:57 -0700
committerGitHub <noreply@github.com>2022-05-02 17:25:57 +0200
commit67daf96bdd519b1e709d6ed2534d06203967bf97 (patch)
tree94a3ace6f960e26e772c00437f3ff9af7112f2b3
parent843eeae13d4cb2a7e8c1ed0d151a691c83adf72f (diff)
Org reader: allow attrs for Org tables. (#8049)
Tables with attributes are no longer wrapped in Div elements; attributes are added directly to the table element.
-rw-r--r--src/Text/Pandoc/Readers/Org/Blocks.hs22
-rw-r--r--test/Tests/Readers/Org/Block/Table.hs23
-rw-r--r--test/command/3706.md135
-rw-r--r--test/command/6441.md22
4 files changed, 113 insertions, 89 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs
index f9fc4ce68..fbc5e6182 100644
--- a/src/Text/Pandoc/Readers/Org/Blocks.hs
+++ b/src/Text/Pandoc/Readers/Org/Blocks.hs
@@ -634,25 +634,23 @@ orgTable = try $ do
let caption = fromMaybe mempty (blockAttrCaption blockAttrs)
let orgTbl = normalizeTable <$> rowsToTable rows
- -- wrap table in div if a name or label is given
let identMb = blockAttrName blockAttrs `mplus` blockAttrLabel blockAttrs
- let wrap = case identMb of
- Just ident -> B.divWith (ident, mempty, mempty)
- Nothing -> id
- return . fmap wrap $ (orgToPandocTable <$> orgTbl <*> caption)
+ let attr = (fromMaybe mempty identMb, [], blockAttrKeyValues blockAttrs)
+ return $ orgToPandocTable attr <$> orgTbl <*> caption
-orgToPandocTable :: OrgTable
+orgToPandocTable :: Attr
+ -> OrgTable
-> Inlines
-> Blocks
-orgToPandocTable (OrgTable colProps heads lns) caption =
+orgToPandocTable attr (OrgTable colProps heads lns) caption =
let totalWidth = if any (isJust . columnRelWidth) colProps
then Just . sum $ map (fromMaybe 1 . columnRelWidth) colProps
else Nothing
- in B.table (B.simpleCaption $ B.plain caption)
- (map (convertColProp totalWidth) colProps)
- (TableHead nullAttr $ toHeaderRow heads)
- [TableBody nullAttr 0 [] $ map toRow lns]
- (TableFoot nullAttr [])
+ in B.tableWith attr (B.simpleCaption $ B.plain caption)
+ (map (convertColProp totalWidth) colProps)
+ (TableHead nullAttr $ toHeaderRow heads)
+ [TableBody nullAttr 0 [] $ map toRow lns]
+ (TableFoot nullAttr [])
where
toRow = Row nullAttr . map B.simpleCell
toHeaderRow l = [toRow l | not (null l)]
diff --git a/test/Tests/Readers/Org/Block/Table.hs b/test/Tests/Readers/Org/Block/Table.hs
index 5a9320b4a..f6b99a5c1 100644
--- a/test/Tests/Readers/Org/Block/Table.hs
+++ b/test/Tests/Readers/Org/Block/Table.hs
@@ -25,12 +25,16 @@ simpleTable' :: Int
simpleTable' n = simpleTable'' emptyCaption $ replicate n (AlignDefault, ColWidthDefault)
simpleTable'' :: Caption -> [ColSpec] -> [Blocks] -> [[Blocks]] -> Blocks
-simpleTable'' capt spec headers rows
- = table capt
- spec
- (TableHead nullAttr $ toHeaderRow headers)
- [TableBody nullAttr 0 [] $ map toRow rows]
- (TableFoot nullAttr [])
+simpleTable'' = simpleTableWith'' (mempty, [], [])
+
+simpleTableWith'' :: Attr -> Caption -> [ColSpec] -> [Blocks] -> [[Blocks]] -> Blocks
+simpleTableWith'' attr capt spec headers rows
+ = tableWith attr
+ capt
+ spec
+ (TableHead nullAttr $ toHeaderRow headers)
+ [TableBody nullAttr 0 [] $ map toRow rows]
+ (TableFoot nullAttr [])
where
toRow = Row nullAttr . map simpleCell
toHeaderRow l = [toRow l | not (null l)]
@@ -181,6 +185,9 @@ tests =
T.unlines [ "#+name: x-marks-the-spot"
, "| x |"
] =?>
- divWith ("x-marks-the-spot", mempty, mempty)
- (simpleTable' 1 mempty [ [ plain "x" ] ])
+ simpleTableWith'' ("x-marks-the-spot", mempty, mempty)
+ emptyCaption
+ (replicate 1 (AlignDefault, ColWidthDefault))
+ mempty
+ [ [ plain "x" ] ]
]
diff --git a/test/command/3706.md b/test/command/3706.md
index fcd95dfdd..025de1364 100644
--- a/test/command/3706.md
+++ b/test/command/3706.md
@@ -15,85 +15,82 @@ Results marker can be hidden in block attributes (#3706)
| 2 | La |
| 3 | La |
^D
-[ Div
+[ Table
( "tab" , [] , [] )
- [ Table
- ( "" , [] , [] )
- (Caption Nothing [ Plain [ Str "Lalelu." ] ])
- [ ( AlignDefault , ColWidthDefault )
- , ( AlignDefault , ColWidthDefault )
- ]
- (TableHead
+ (Caption Nothing [ Plain [ Str "Lalelu." ] ])
+ [ ( AlignDefault , ColWidthDefault )
+ , ( AlignDefault , ColWidthDefault )
+ ]
+ (TableHead
+ ( "" , [] , [] )
+ [ Row
( "" , [] , [] )
- [ Row
+ [ Cell
( "" , [] , [] )
- [ Cell
- ( "" , [] , [] )
- AlignDefault
- (RowSpan 1)
- (ColSpan 1)
- [ Plain [ Str "Id" ] ]
- , Cell
- ( "" , [] , [] )
- AlignDefault
- (RowSpan 1)
- (ColSpan 1)
- [ Plain [ Str "Desc" ] ]
- ]
- ])
- [ TableBody
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "Id" ] ]
+ , Cell
+ ( "" , [] , [] )
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "Desc" ] ]
+ ]
+ ])
+ [ TableBody
+ ( "" , [] , [] )
+ (RowHeadColumns 0)
+ []
+ [ Row
+ ( "" , [] , [] )
+ [ Cell
+ ( "" , [] , [] )
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "1" ] ]
+ , Cell
+ ( "" , [] , [] )
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "La" ] ]
+ ]
+ , Row
( "" , [] , [] )
- (RowHeadColumns 0)
- []
- [ Row
+ [ Cell
( "" , [] , [] )
- [ Cell
- ( "" , [] , [] )
- AlignDefault
- (RowSpan 1)
- (ColSpan 1)
- [ Plain [ Str "1" ] ]
- , Cell
- ( "" , [] , [] )
- AlignDefault
- (RowSpan 1)
- (ColSpan 1)
- [ Plain [ Str "La" ] ]
- ]
- , Row
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "2" ] ]
+ , Cell
+ ( "" , [] , [] )
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "La" ] ]
+ ]
+ , Row
+ ( "" , [] , [] )
+ [ Cell
( "" , [] , [] )
- [ Cell
- ( "" , [] , [] )
- AlignDefault
- (RowSpan 1)
- (ColSpan 1)
- [ Plain [ Str "2" ] ]
- , Cell
- ( "" , [] , [] )
- AlignDefault
- (RowSpan 1)
- (ColSpan 1)
- [ Plain [ Str "La" ] ]
- ]
- , Row
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "3" ] ]
+ , Cell
( "" , [] , [] )
- [ Cell
- ( "" , [] , [] )
- AlignDefault
- (RowSpan 1)
- (ColSpan 1)
- [ Plain [ Str "3" ] ]
- , Cell
- ( "" , [] , [] )
- AlignDefault
- (RowSpan 1)
- (ColSpan 1)
- [ Plain [ Str "La" ] ]
- ]
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "La" ] ]
]
]
- (TableFoot ( "" , [] , [] ) [])
]
+ (TableFoot ( "" , [] , [] ) [])
]
```
diff --git a/test/command/6441.md b/test/command/6441.md
new file mode 100644
index 000000000..d0488767c
--- /dev/null
+++ b/test/command/6441.md
@@ -0,0 +1,22 @@
+```
+% pandoc -f org -t html
+#+ATTR_HTML: :class table-dark
+| h1 | h2 |
+|----|----|
+| c1 | c2 |
+^D
+<table class="table-dark">
+<thead>
+<tr class="header">
+<th>h1</th>
+<th>h2</th>
+</tr>
+</thead>
+<tbody>
+<tr class="odd">
+<td>c1</td>
+<td>c2</td>
+</tr>
+</tbody>
+</table>
+```