diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2017-05-03 22:43:34 +0200 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2017-05-03 22:43:34 +0200 |
commit | 57cba3f1d5aa682df4ca8aafc3bc1d2ed4ead911 (patch) | |
tree | cb0c3f72d1663eb8ef3c92567dfa9c626c0b9369 | |
parent | df23d96c8991b215ead8ceb11607c5bebfb1f6db (diff) | |
download | pandoc-57cba3f1d5aa682df4ca8aafc3bc1d2ed4ead911.tar.gz |
Org reader: support table.el tables
Closes #3314
-rw-r--r-- | src/Text/Pandoc/Readers/Org/BlockStarts.hs | 5 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Org/Blocks.hs | 20 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Org/Parsing.hs | 1 | ||||
-rw-r--r-- | test/command/3314.md | 34 |
4 files changed, 52 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/Org/BlockStarts.hs b/src/Text/Pandoc/Readers/Org/BlockStarts.hs index cc2e82d5b..f05725f16 100644 --- a/src/Text/Pandoc/Readers/Org/BlockStarts.hs +++ b/src/Text/Pandoc/Readers/Org/BlockStarts.hs @@ -61,6 +61,10 @@ headerStart = try $ tableStart :: Monad m => OrgParser m Char tableStart = try $ skipSpaces *> char '|' +gridTableStart :: Monad m => OrgParser m () +gridTableStart = try $ skipSpaces <* char '+' <* char '-' + + latexEnvStart :: Monad m => OrgParser m String latexEnvStart = try $ do skipSpaces *> string "\\begin{" @@ -126,6 +130,7 @@ endOfBlock = lookAhead . try $ do , hline , metaLineStart , commentLineStart + , gridTableStart , void noteMarker , void tableStart , void drawerStart diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs index b0a19b833..89c076869 100644 --- a/src/Text/Pandoc/Readers/Org/Blocks.hs +++ b/src/Text/Pandoc/Readers/Org/Blocks.hs @@ -755,7 +755,11 @@ data OrgTable = OrgTable } table :: PandocMonad m => OrgParser m (F Blocks) -table = try $ do +table = gridTableWith blocks True <|> orgTable + +-- | A normal org table +orgTable :: PandocMonad m => OrgParser m (F Blocks) +orgTable = try $ do -- don't allow a table on the first line of a list item; org requires that -- tables start at first non-space character on the line let isFirstInListItem st = (orgStateParserContext st == ListItemState) && @@ -854,28 +858,28 @@ normalizeTable (OrgTable colProps heads rows) = rowToContent :: OrgTable -> OrgTableRow -> F OrgTable -rowToContent orgTable row = +rowToContent tbl row = case row of OrgHlineRow -> return singleRowPromotedToHeader OrgAlignRow props -> return . setProperties $ props OrgContentRow cs -> appendToBody cs where singleRowPromotedToHeader :: OrgTable - singleRowPromotedToHeader = case orgTable of + singleRowPromotedToHeader = case tbl of OrgTable{ orgTableHeader = [], orgTableRows = b:[] } -> - orgTable{ orgTableHeader = b , orgTableRows = [] } - _ -> orgTable + tbl{ orgTableHeader = b , orgTableRows = [] } + _ -> tbl setProperties :: [ColumnProperty] -> OrgTable - setProperties ps = orgTable{ orgTableColumnProperties = ps } + setProperties ps = tbl{ orgTableColumnProperties = ps } appendToBody :: F [Blocks] -> F OrgTable appendToBody frow = do newRow <- frow - let oldRows = orgTableRows orgTable + let oldRows = orgTableRows tbl -- NOTE: This is an inefficient O(n) operation. This should be changed -- if performance ever becomes a problem. - return orgTable{ orgTableRows = oldRows ++ [newRow] } + return tbl{ orgTableRows = oldRows ++ [newRow] } -- diff --git a/src/Text/Pandoc/Readers/Org/Parsing.hs b/src/Text/Pandoc/Readers/Org/Parsing.hs index 464ef9ca6..aa3a08279 100644 --- a/src/Text/Pandoc/Readers/Org/Parsing.hs +++ b/src/Text/Pandoc/Readers/Org/Parsing.hs @@ -70,6 +70,7 @@ module Text.Pandoc.Readers.Org.Parsing , dash , ellipses , citeKey + , gridTableWith -- * Re-exports from Text.Pandoc.Parsec , runParser , runParserT diff --git a/test/command/3314.md b/test/command/3314.md new file mode 100644 index 000000000..064b04cbd --- /dev/null +++ b/test/command/3314.md @@ -0,0 +1,34 @@ +See #3315 and <http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#simple-tables>. + +``` +% pandoc -f org -t html5 ++-----------+-------+----------+ +| First | 12.0 | Example | +| | | row | +| | | spanning | +| | | lines | ++-----------+-------+----------+ +| Second | 5.0 | Another | ++-----------+-------+----------+ +^D +<table style="width:43%;"> +<colgroup> +<col style="width: 16%" /> +<col style="width: 11%" /> +<col style="width: 15%" /> +</colgroup> +<tbody> +<tr class="odd"> +<td>First</td> +<td>12.0</td> +<td>Example row spanning lines</td> +</tr> +<tr class="even"> +<td>Second</td> +<td>5.0</td> +<td>Another</td> +</tr> +</tbody> +</table> +``` + |