pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

error with table ColWidth "default" and numeric when convert to html

Open ilcpm opened this issue 1 year ago • 2 comments

convert this to html, a style="width:70%; attribute will be added to the table

image

demo link

[ Table
    ( "" , [] , [] )
    (Caption Nothing [])
    [ ( AlignCenter , ColWidthDefault )
    , ( AlignCenter , ColWidth 0.7 )
    ]
    (TableHead ( "" , [] , [] ) [])
    [ TableBody
        ( "" , [] , [] )
        (RowHeadColumns 0)
        []
        [ Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) []
            , Cell
                ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) []
            ]
        ]
    ]
    (TableFoot ( "" , [] , [] ) [])
]

ilcpm avatar Feb 23 '24 10:02 ilcpm

it seems that pandoc is designed to set table_width = sum(col_width) when sum(col_width) < 100% on purpose, to set the table width and the column width at the same time, rather than a bug

I think this feature is designed for this case: to get a table with width:60%, and two columns with the same width. in this case, it will be set to:

    [ ( AlignCenter , ColWidth 0.3)
    , ( AlignCenter , ColWidth 0.3)
    ]

but when I want to set one column to 10% width of the table, and leave the rest columns default, this feature will set the table's width to 10% of the page.

so, if a separate setting is added for the width of the table, it would be more appropriate

ilcpm avatar Feb 23 '24 11:02 ilcpm

it seems that pandoc is designed to set table_width = sum(col_width) when sum(col_width) < 100% on purpose, to set the table width and the column width at the same time, rather than a bug

Correct.

In pandoc we generally either have all columns default width or all columns specified width. So your case is a bit unusual; it's not one that any pandoc parser would generate, and that's why we don't handle it very well.

Perhaps the best solution would be to disable the table width calculation in the HTML writer when any of the columns have default width.

jgm avatar Feb 23 '24 15:02 jgm