aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2019-12-18 21:57:14 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2019-12-18 22:28:26 +0100
commit5bd2d28b1946baf37ba880578b3b01d9b36a36d3 (patch)
tree57baca31e0c13515ded2dbe37ead8de599fc3bfa
parent89bbfa189199b1abd67b5ab21b967b1fa049fbb3 (diff)
downloadpandoc-5bd2d28b1946baf37ba880578b3b01d9b36a36d3.tar.gz
Org reader: wrap named table in div, using name as id
Closes: #5984
-rw-r--r--src/Text/Pandoc/Readers/Org/Blocks.hs22
-rw-r--r--test/Tests/Readers/Org/Block/Table.hs7
-rw-r--r--test/command/3706.md19
3 files changed, 27 insertions, 21 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs
index 785811da8..dc7a26aca 100644
--- a/src/Text/Pandoc/Readers/Org/Blocks.hs
+++ b/src/Text/Pandoc/Readers/Org/Blocks.hs
@@ -613,18 +613,16 @@ orgTable = try $ do
guard =<< not . isFirstInListItem <$> getState
blockAttrs <- blockAttributes
lookAhead tableStart
- do
- rows <- tableRows
- let captionMb = blockAttrCaption blockAttrs
- -- amend caption with span as ID tag iff both are present
- let amendedCaption = do
- caption' <- captionMb
- name <- blockAttrName blockAttrs `mplus` blockAttrLabel blockAttrs
- let tag = B.spanWith (name, mempty, mempty) mempty
- return $ fmap (tag <>) caption'
- let caption = fromMaybe mempty (amendedCaption `mplus` captionMb)
- return $ (<$> caption) . orgToPandocTable . normalizeTable
- =<< rowsToTable rows
+ rows <- tableRows
+
+ 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)
orgToPandocTable :: OrgTable
-> Inlines
diff --git a/test/Tests/Readers/Org/Block/Table.hs b/test/Tests/Readers/Org/Block/Table.hs
index c8b0a1375..102623735 100644
--- a/test/Tests/Readers/Org/Block/Table.hs
+++ b/test/Tests/Readers/Org/Block/Table.hs
@@ -160,4 +160,11 @@ tests =
[ [ plain "x", plain "6" ]
, [ plain "9", plain "42" ]
]
+
+ , "named table" =:
+ T.unlines [ "#+NAME: x-marks-the-spot"
+ , "| x |"
+ ] =?>
+ divWith ("x-marks-the-spot", mempty, mempty)
+ (simpleTable' 1 mempty [ [ plain "x" ] ])
]
diff --git a/test/command/3706.md b/test/command/3706.md
index 5b2e32f7f..3765372fa 100644
--- a/test/command/3706.md
+++ b/test/command/3706.md
@@ -15,15 +15,16 @@ pandoc -f org -t native
| 2 | La |
| 3 | La |
^D
-[Table [Span ("tab",[],[]) [],Str "Lalelu."] [AlignDefault,AlignDefault] [0.0,0.0]
- [[Plain [Str "Id"]]
- ,[Plain [Str "Desc"]]]
- [[[Plain [Str "1"]]
- ,[Plain [Str "La"]]]
- ,[[Plain [Str "2"]]
- ,[Plain [Str "La"]]]
- ,[[Plain [Str "3"]]
- ,[Plain [Str "La"]]]]]
+[Div ("tab",[],[])
+ [Table [Str "Lalelu."] [AlignDefault,AlignDefault] [0.0,0.0]
+ [[Plain [Str "Id"]]
+ ,[Plain [Str "Desc"]]]
+ [[[Plain [Str "1"]]
+ ,[Plain [Str "La"]]]
+ ,[[Plain [Str "2"]]
+ ,[Plain [Str "La"]]]
+ ,[[Plain [Str "3"]]
+ ,[Plain [Str "La"]]]]]]
```
```