You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make <br> a universal linebreak across formats #1767
I think one thing to make "just work" is recognizing <br> as a line break in all output contexts; this'll avoid any need to call fmt_markdown(). This could probably be done in the process_text() function.
We incidentally also need a similar bit of 'extra' markup to represent cross-output tab stops but that's for another issue.
If possible, would it makes sense to make \n the universal line breaker, since that's how it's already interpreted in many other spaces? Then no one needs to learn another
I think my main reasoning is that even if gt supports all formats, it still remains an html-first format. When I construct a complex gt table, I do it interactively in html, and hope for the best when trying to convert to other formats. I am doing so blindly (too much sometimes).
html output is easier to preview
tested more thoroughly
works out of the box for html output without fmt_markdown(), md(), html(), or process_md = TRUE
So getting a LaTeX output or grid or docx is a matter of converting the html to this other format as close as possible to the html output.
Similarly, ggplot2 is grid first. Therefore, to make it interactive, plotly::ggplotly() interprets the grid system and translates it to html. (i.e. When I am using ggplotly, I trust that it will convert ggplot2 grid to html properly. ggplots are much easier to preview as static.)
By default, html ignores line breaks and multiple consecutive spaces.
grid is my new second favorite for easy previewing!
# line breakdata.frame(x= c("x\ny") |>
gt() |>
as_gtable() |>
plot()
Unfortunately, the output is not the same, hence a surprise output in my opinion.
We have to have one source of truth for this to be effective.
There are also a lot of contexts where \n is ignored in html and in many situations.
In md
Text
on the same line
In R,
cli::cli_abort("x\ny")
#> Error:#> ! x y
In gt, by default.
data.frame(
x= c("x\ny")
) |>
gt()
Changing \n as a linebreak in html would be a breaking change. I could live with it, but I think it would feel surprising for many JS / md /css / pandoc experts.
@rich-iannone feel free to add your grain of salt here!
One of my first use cases for as_gtable() would be to help create reprex (to proxy the html output), but it doesn't really work currently, because of the line break issue inconsistency.
There is also the danger of helpers like fmt_markdown(), gt(process_md), md(), html() that may not be respected everywhere, and then there is Quarto who may (or may not) post-process the table.
Edit: my assessment may have been incorrect. <br> works out of the box only for opt_interactive()
Yeah, it might be a bit eccentric but I think <br> would be best for the reasons you outlined and more. Then, we'd have to have a number of examples and some explanations in the docs to explain this will be a cross-output method for introducing a hard line break.
Activity
ddsjoberg commentedon Jul 11, 2024
If possible, would it makes sense to make
\nthe universal line breaker, since that's how it's already interpreted in many other spaces? Then no one needs to learn anotherteunbrand commentedon Jul 12, 2024
I second the suggestion to make
\nto universal line breaker. I don't understand why<br>would be the preferred option.olivroy commentedon Jul 12, 2024
I think my main reasoning is that even if gt supports all formats, it still remains an html-first format. When I construct a complex gt table, I do it interactively in html, and hope for the best when trying to convert to other formats. I am doing so blindly (too much sometimes).
works out of the box for html output without fmt_markdown(), md(), html(), or
process_md = TRUESo getting a LaTeX output or grid or docx is a matter of converting the html to this other format as close as possible to the html output.
Similarly, ggplot2 is grid first. Therefore, to make it interactive,
plotly::ggplotly()interprets the grid system and translates it to html. (i.e. When I am using ggplotly, I trust that it will convert ggplot2 grid to html properly. ggplots are much easier to preview as static.)By default, html ignores line breaks and multiple consecutive spaces.
grid is my new second favorite for easy previewing!
Unfortunately, the output is not the same, hence a surprise output in my opinion.
We have to have one source of truth for this to be effective.
There are also a lot of contexts where
\nis ignored in html and in many situations.In md
In R,
In gt, by default.
Changing \n as a linebreak in html would be a breaking change. I could live with it, but I think it would feel surprising for many JS / md /css / pandoc experts.
@rich-iannone feel free to add your grain of salt here!
One of my first use cases for
as_gtable()would be to help create reprex (to proxy the html output), but it doesn't really work currently, because of the line break issue inconsistency.There is also the danger of helpers like
fmt_markdown(),gt(process_md),md(),html()that may not be respected everywhere, and then there is Quarto who may (or may not) post-process the table.Edit: my assessment may have been incorrect.
<br>works out of the box only foropt_interactive()rich-iannone commentedon Jul 12, 2024
Yeah, it might be a bit eccentric but I think
<br>would be best for the reasons you outlined and more. Then, we'd have to have a number of examples and some explanations in the docs to explain this will be a cross-output method for introducing a hard line break.rich-iannone commentedon Aug 17, 2026
Implemented and available since
v1.1.0.