diff options
author | Nils Carlson <nils@nilscarlson.se> | 2020-09-25 00:43:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-24 17:43:43 -0700 |
commit | 1ad7a047d58a629ab7d29ea74dcb752d82d3dc11 (patch) | |
tree | e719a3919ba1354fc46a53194f16a1be48baaf7b | |
parent | a331c69b4935b03d42f88f5346b700c795e09346 (diff) | |
download | pandoc-1ad7a047d58a629ab7d29ea74dcb752d82d3dc11.tar.gz |
DocBook reader: Implement table cell alignment (#6698)
-rw-r--r-- | src/Text/Pandoc/Readers/DocBook.hs | 17 | ||||
-rw-r--r-- | test/command/table-with-cell-align.md | 37 | ||||
-rw-r--r-- | test/command/table-with-column-span.md | 80 |
3 files changed, 88 insertions, 46 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index 5c9687f94..0635884ad 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -943,11 +943,6 @@ parseBlock (Elem e) = $ filterChildren isRow b Nothing -> mapM (parseRow colnames) $ filterChildren isRow e' - let toAlignment c = case findAttr (unqual "align") c of - Just "left" -> AlignLeft - Just "right" -> AlignRight - Just "center" -> AlignCenter - _ -> AlignDefault let toWidth c = do w <- findAttr (unqual "colwidth") c n <- safeRead $ "0" <> T.filter (\x -> @@ -1005,6 +1000,14 @@ parseBlock (Elem e) = -- we also attach the label as a class, so it can be styled properly return $ divWith (attrValue "id" e,[label],[]) (title <> b) +toAlignment :: Element -> Alignment +toAlignment c = case findAttr (unqual "align") c of + Just "left" -> AlignLeft + Just "right" -> AlignRight + Just "center" -> AlignCenter + _ -> AlignDefault + + parseMixed :: PandocMonad m => (Inlines -> Blocks) -> [Content] -> DB m Blocks parseMixed container conts = do let (ils,rest) = break isBlockElement conts @@ -1036,7 +1039,9 @@ parseEntry cn el = do case (mStrt, mEnd) of (Just start, Just end) -> colDistance start end _ -> 1 - (fmap (cell AlignDefault 1 (toColSpan el)) . parseMixed plain . elContent) el + let colSpan = toColSpan el + let align = toAlignment el + (fmap (cell align 1 colSpan) . (parseMixed plain) . elContent) el getInlines :: PandocMonad m => Element -> DB m Inlines getInlines e' = trimInlines . mconcat <$> diff --git a/test/command/table-with-cell-align.md b/test/command/table-with-cell-align.md new file mode 100644 index 000000000..d4ee72975 --- /dev/null +++ b/test/command/table-with-cell-align.md @@ -0,0 +1,37 @@ +``` +% pandoc -f docbook -t native --quiet +<informaltable frame="all" rowsep="1" colsep="1"> +<tgroup cols="16"> +<tbody> +<row> +<entry align="center" valign="top"><simpara>1</simpara></entry> +<entry align="left" valign="top"><simpara>2</simpara></entry> +<entry align="right" valign="top"><simpara>3</simpara></entry> +<entry align="justify" valign="top"><simpara>4</simpara></entry> +</row> +</tbody> +</tgroup> +</informaltable> +^D +[Table ("",[],[]) (Caption Nothing + []) + [(AlignDefault,ColWidthDefault) + ,(AlignDefault,ColWidthDefault) + ,(AlignDefault,ColWidthDefault) + ,(AlignDefault,ColWidthDefault)] + (TableHead ("",[],[]) + []) + [(TableBody ("",[],[]) (RowHeadColumns 0) + [] + [Row ("",[],[]) + [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + [Para [Str "1"]] + ,Cell ("",[],[]) AlignLeft (RowSpan 1) (ColSpan 1) + [Para [Str "2"]] + ,Cell ("",[],[]) AlignRight (RowSpan 1) (ColSpan 1) + [Para [Str "3"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + [Para [Str "4"]]]])] + (TableFoot ("",[],[]) + [])] +``` diff --git a/test/command/table-with-column-span.md b/test/command/table-with-column-span.md index a0824b5a1..f12319452 100644 --- a/test/command/table-with-column-span.md +++ b/test/command/table-with-column-span.md @@ -72,47 +72,47 @@ [(TableBody ("",[],[]) (RowHeadColumns 0) [] [Row ("",[],[]) - [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) + [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) [Para [Strong [Str "Octet",Space,Str "no.",Space,Str "1"]]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) [Para [Strong [Str "Octet",Space,Str "no.",Space,Str "2"]]]] ,Row ("",[],[]) - [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "16"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "15"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "14"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "13"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "12"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "11"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "10"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "9"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "8"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "7"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "6"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "5"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "4"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "3"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "2"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "1"]]] ,Row ("",[],[]) - [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) + [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) [Para [Str "Code",Space,Str "A"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) [Para [Str "Code",Space,Str "B"]]]])] (TableFoot ("",[],[]) [])] @@ -142,47 +142,47 @@ [(TableBody ("",[],[]) (RowHeadColumns 0) [] [Row ("",[],[]) - [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) + [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) [Para [Strong [Str "Octet",Space,Str "no.",Space,Str "1"]]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) [Para [Strong [Str "Octet",Space,Str "no.",Space,Str "2"]]]] ,Row ("",[],[]) - [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "16"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "15"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "14"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "13"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "12"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "11"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "10"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "9"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "8"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "7"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "6"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "5"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "4"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "3"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "2"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Para [Str "1"]]] ,Row ("",[],[]) - [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) + [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) [Para [Str "Code",Space,Str "A"]] - ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) [Para [Str "Code",Space,Str "B"]]]])] (TableFoot ("",[],[]) [])] |