`colformat_md()` + HTML tags
Closed this issue · 3 comments
Hey hey @atusy ! Thanks again for the recent updates! I love them ❤️
I had a colleague do some testing after I incorporated colformat_md()
into the dev version of gtsummary. She came across a potential issue when a header includes an HTML tag.
mtcars[1:3, 1:2] |>
flextable::as_flextable()|>
flextable::set_header_labels(mpg = "**MPG<br>Line 2**", cyl = "**No. Cyl.**") |>
ftExtra::colformat_md(part = "header", md_extensions = "+hard_line_breaks")
#> Error in a[[2]]: subscript out of bounds
Created on 2022-04-22 by the reprex package (v2.0.1)
There is no issue if ">"
of "<"
are added in isolation, or even if an empty "<>"
is included. But if "<anything_here>"
appears, we get an subscript out of bounds error.
- Is this error expected, i.e. html tags are not allowed?
- If it is, is it possible to add some error messaging, e.g. "HTML tag found in header label, which is not allowed."
- Are there any other restrictions about the text that can and cannot appear in the header labels I can communicate to the gtsummary users?
Apologies for not finding this before the release!
Thank you for finding the bug!
And no worries that we find it after the release.
Bug reports are always appreciated.
It comes from a line which attempts to retrieve attributes from the markdown element.
I know RawInlines
and RawBlocks
do not have attributes and thus the line fails.
Line 10 in f3776a0
I will consider fix the issue.
For now, you have two workarounds
- Escape HTML tags by backslashes (e.g.,
\\<
) - Treat HTML tags as plain texts by specifying
colformat_md(md_extensions = '-raw_html')
Thank you for looking into it! If I can help and/or review a Pull Request, please let me know!
FYI I sent gtsummary off to CRAN today. Once it's accepted, I'll start telling people about the new functionality! People (and especially me) are going to love it!