git.iko.soy/typeable/pandoc
on master help sign in
Org reader: wrap named table in div, using name as id

Closes: #5984

commit5bd2d28b1946baf37ba880578b3b01d9b36a36d3 authorAlbert Krewinkel <albert@zeitkraut.de> dateWed 18 Dec 2019, 21:57 (7 years ago) parent89bbfa1
3 files changed+27−21
src/Text/Pandoc/Readers/Org/Blocks.hs+10−12 test/Tests/Readers/Org/Block/Table.hs+7 test/command/3706.md+10−9
src/Text/Pandoc/Readers/Org/Blocks.hs+10−12
@@ -613,18 +613,16 @@ orgTable = try $ do
613613 guard =<< not . isFirstInListItem <$> getState
614614 blockAttrs <- blockAttributes
615615 lookAhead tableStart
616− do
617− rows <- tableRows
618− let captionMb = blockAttrCaption blockAttrs
619− -- amend caption with span as ID tag iff both are present
620− let amendedCaption = do
621− caption' <- captionMb
622− name <- blockAttrName blockAttrs `mplus` blockAttrLabel blockAttrs
623− let tag = B.spanWith (name, mempty, mempty) mempty
624− return $ fmap (tag <>) caption'
625− let caption = fromMaybe mempty (amendedCaption `mplus` captionMb)
626− return $ (<$> caption) . orgToPandocTable . normalizeTable
627− =<< rowsToTable rows
616+ rows <- tableRows
617+
618+ let caption = fromMaybe mempty (blockAttrCaption blockAttrs)
619+ let orgTbl = normalizeTable <$> rowsToTable rows
620+ -- wrap table in div if a name or label is given
621+ let identMb = blockAttrName blockAttrs `mplus` blockAttrLabel blockAttrs
622+ let wrap = case identMb of
623+ Just ident -> B.divWith (ident, mempty, mempty)
624+ Nothing -> id
625+ return . fmap wrap $ (orgToPandocTable <$> orgTbl <*> caption)
628626
629627orgToPandocTable :: OrgTable
630628 -> Inlines
test/Tests/Readers/Org/Block/Table.hs+7
@@ -160,4 +160,11 @@ tests =
160160 [ [ plain "x", plain "6" ]
161161 , [ plain "9", plain "42" ]
162162 ]
163+
164+ , "named table" =:
165+ T.unlines [ "#+NAME: x-marks-the-spot"
166+ , "| x |"
167+ ] =?>
168+ divWith ("x-marks-the-spot", mempty, mempty)
169+ (simpleTable' 1 mempty [ [ plain "x" ] ])
163170 ]
test/command/3706.md+10−9
@@ -15,15 +15,16 @@ pandoc -f org -t native
1515| 2 | La |
1616| 3 | La |
1717^D
18−[Table [Span ("tab",[],[]) [],Str "Lalelu."] [AlignDefault,AlignDefault] [0.0,0.0]
19− [[Plain [Str "Id"]]
20− ,[Plain [Str "Desc"]]]
21− [[[Plain [Str "1"]]
22− ,[Plain [Str "La"]]]
23− ,[[Plain [Str "2"]]
24− ,[Plain [Str "La"]]]
25− ,[[Plain [Str "3"]]
26− ,[Plain [Str "La"]]]]]
18+[Div ("tab",[],[])
19+ [Table [Str "Lalelu."] [AlignDefault,AlignDefault] [0.0,0.0]
20+ [[Plain [Str "Id"]]
21+ ,[Plain [Str "Desc"]]]
22+ [[[Plain [Str "1"]]
23+ ,[Plain [Str "La"]]]
24+ ,[[Plain [Str "2"]]
25+ ,[Plain [Str "La"]]]
26+ ,[[Plain [Str "3"]]
27+ ,[Plain [Str "La"]]]]]]
2728```
2829
2930```