Skip to content

DOCX reader to support row head #9495

Closed
@rgaiacs

Description

@rgaiacs

Pandoc types has support for row head, see https://pandoc.org/lua-filters.html#type-tablebody, and Microsoft Word allows users to apply "special formatting for the first column", see the "Table Style Options" in the screenshot.

Screenshot 2024-02-22 174809

DOCX reader could treat the selection of "special formatting for the first column" as "the first column is a header".

Minimal Working Examples

table-2x2-single-header.docx

table-2x2-two-headers.docx

XML structure

table-2x2-single-header.docx has

    <w:tbl>
      <w:tblPr>
        <w:tblStyle w:val="GridTable5Dark-Accent1"/>
        <w:tblW w:w="0" w:type="auto"/>
        <w:tblLook w:val="0420" w:firstRow="1" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
      </w:tblPr>

and table-2x2-two-headers.docx has

    <w:tbl>
      <w:tblPr>
        <w:tblStyle w:val="GridTable5Dark-Accent1"/>
        <w:tblW w:w="0" w:type="auto"/>
        <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
      </w:tblPr>

DOCX reader need to check the value of w:firstColumn in <w:tblLook />.

Current Reading

pandoc --from docx --to native table-2x2-two-headers.docx produces

[ Table
    ( "" , [] , [] )
    (Caption Nothing [])
    [ ( AlignDefault , ColWidth 0.5 )
    , ( AlignDefault , ColWidth 0.5 )
    ]
    (TableHead
       ( "" , [] , [] )
       [ Row
           ( "" , [] , [] )
           [ Cell
               ( "" , [] , [] )
               AlignDefault
               (RowSpan 1)
               (ColSpan 1)
               [ Plain [ Str "1" ] ]
           , Cell
               ( "" , [] , [] )
               AlignDefault
               (RowSpan 1)
               (ColSpan 1)
               [ Plain [ Str "2" ] ]
           ]
       ])
    [ TableBody
        ( "" , [] , [] )
        (RowHeadColumns 0)
        []
        [ Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "3" ] ]
            , Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "4" ] ]
            ]
        ]
    ]
    (TableFoot ( "" , [] , [] ) [])
]

Desired Reading

pandoc --from docx --to native table-2x2-two-headers.docx should produce

[ Table
    ( "" , [] , [] )
    (Caption Nothing [])
    [ ( AlignDefault , ColWidth 0.5 )
    , ( AlignDefault , ColWidth 0.5 )
    ]
    (TableHead
       ( "" , [] , [] )
       [ Row
           ( "" , [] , [] )
           [ Cell
               ( "" , [] , [] )
               AlignDefault
               (RowSpan 1)
               (ColSpan 1)
               [ Plain [ Str "1" ] ]
           , Cell
               ( "" , [] , [] )
               AlignDefault
               (RowSpan 1)
               (ColSpan 1)
               [ Plain [ Str "2" ] ]
           ]
       ])
    [ TableBody
        ( "" , [] , [] )
        (RowHeadColumns 1)
        []
        [ Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "3" ] ]
            , Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "4" ] ]
            ]
        ]
    ]
    (TableFoot ( "" , [] , [] ) [])
]

The value of RowHeadColumns is now 1.

Environment

pandoc --version returns

pandoc 3.1.11.1
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /home/raniere/.local/share/pandoc
Copyright (C) 2006-2023 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions