Closed andrewheiss closed 6 years ago
Could you try github master and report if it works for you?
Awesome, that works! Thanks!
print_md(ht)
#> -----------------------
#> 1 5
#> ----------- -----------
#> **2** **4**
#>
#> **3** **3**
#>
#> **4** **2**
#>
#> *5* *1*
#> -----------------------
Actually, could you try again with the latest version? I had to rewrite it to deal with strings that break over multiple lines, and I'm not certain I've got it right (or can test it easily...)
Yep, here's what I'm getting now:
library(tidyverse)
library(huxtable)
df <- tribble(
~a, ~b,
1, "This is a test.",
2, "This is a test with two lines.\n\nHere's the second line.",
3, "This is a test with a bunch of lines\n\nthat just keep going and does it break anything\n\n if it goes this long maybe I don't know yet\n\nbut I'm still typing and that's probably\n\nenough text for now."
)
ht <- df %>%
huxtable() %>%
set_bold(2:3, 2, TRUE)
print_md(ht)
#> ---------------------------------------------------
#> 1 This is a test.
#> ----------- ---------------------------------------
#> 2 **This is a test with two lines.**
#> ****
#> **Here's the second line.**
#>
#> 3 **This is a test with a bunch of**
#> **lines**
#> ****
#> **that just keep going and does it**
#> **break anything**
#> ****
#> **if it goes this long maybe I don't**
#> **know yet**
#> ****
#> **but I'm still typing and that's**
#> **probably**
#> ****
#> **enough text for now.**
#> ---------------------------------------------------
It's wrapping each broken line in bold, including empty lines (hence the ****
). Ideally it should wrap the entire line with **
s, even if broken in the middle, I think. Like this?
---------------------------------------------------
1 This is a test.
----------- ---------------------------------------
2 **This is a test with two lines.**
**Here's the second line.**
3 **This is a test with a bunch of
lines**
**that just keep going and does it
break anything**
**if it goes this long maybe I don't
know yet**
**but I'm still typing and that's
probably**
**enough text for now.**
---------------------------------------------------
So what's wrong at the moment is that even empty lines get wrapped in bold. Hmm, does that actually make it compile wrong to HTML or PDF?
The ****
s in empty lines trip up pandoc. This markdown file:
# Table with broken lines wrapped in `**`s
----------------------------------------------------
1 This is a test.
------------ ---------------------------------------
2 **This is a test with two lines.**
****
**Here's the second line.**
3 **This is a test with a bunch of**
**lines**
****
**that just keep going and does it**
**break anything**
****
**if it goes this long maybe I don't**
**know yet**
****
**but I'm still typing and that's**
**probably**
****
**enough text for now.**
----------------------------------------------------
# Table with complete lines wrapped in `**`s
---------------------------------------------------
1 This is a test.
----------- ---------------------------------------
2 **This is a test with two lines.**
**Here's the second line.**
3 **This is a test with a bunch of
lines**
**that just keep going and does it
break anything**
**if it goes this long maybe I don't
know yet**
**but I'm still typing and that's
probably**
**enough text for now.**
---------------------------------------------------
…creates HTML that looks like this (using this pandoc command: pandoc testing.md -s -t html5 -o testing.html
)
<h1 id="table-with-broken-lines-wrapped-in-s">Table with broken lines wrapped in <code>**</code>s</h1>
<table style="width:72%;">
<colgroup>
<col style="width: 18%" />
<col style="width: 54%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">1</th>
<th style="text-align: left;">This is a test.</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">2</td>
<td style="text-align: left;"><strong>This is a test with two lines.</strong> **** <strong>Here’s the second line.</strong></td>
</tr>
<tr class="even">
<td style="text-align: right;">3</td>
<td style="text-align: left;"><strong>This is a test with a bunch of</strong> <strong>lines</strong> **** <strong>that just keep going and does it</strong> <strong>break anything</strong> **** <strong>if it goes this long maybe I don’t</strong> <strong>know yet</strong> **** <strong>but I’m still typing and that’s</strong> <strong>probably</strong> **** <strong>enough text for now.</strong></td>
</tr>
</tbody>
</table>
<h1 id="table-with-complete-lines-wrapped-in-s">Table with complete lines wrapped in <code>**</code>s</h1>
<table style="width:71%;">
<colgroup>
<col style="width: 16%" />
<col style="width: 54%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">1</th>
<th style="text-align: left;">This is a test.</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">2</td>
<td style="text-align: left;"><strong>This is a test with two lines.</strong></td>
</tr>
<tr class="even">
<td style="text-align: right;"></td>
<td style="text-align: left;"><strong>Here’s the second line.</strong></td>
</tr>
<tr class="odd">
<td style="text-align: right;">3</td>
<td style="text-align: left;"><strong>This is a test with a bunch of lines</strong></td>
</tr>
<tr class="even">
<td style="text-align: right;"></td>
<td style="text-align: left;"><strong>that just keep going and does it break anything</strong></td>
</tr>
<tr class="odd">
<td style="text-align: right;"></td>
<td style="text-align: left;"><strong>if it goes this long maybe I don’t know yet</strong></td>
</tr>
<tr class="even">
<td style="text-align: right;"></td>
<td style="text-align: left;"><strong>but I’m still typing and that’s probably</strong></td>
</tr>
<tr class="odd">
<td style="text-align: right;"></td>
<td style="text-align: left;"><strong>enough text for now.</strong></td>
</tr>
</tbody>
</table>
Or
Well, in any case, latest push should fix.
Try now.
Cool, that mostly fixes it! The only weirdness is that broken lines get extra </strong> <strong>
breaks in the middle when converted to HTML and TeX, but it still works fine:
<strong>This is a test with a bunch of</strong> <strong>lines</strong>
and
\textbf{This is a test with a bunch of} \textbf{lines}
instead of
<strong>This is a test with a bunch of lines</strong>
\textbf{This is a test with a bunch of lines}
Markdown has limited support for formatting (i.e. no cell background colors, borders, column spans, etc.), but it does support bold and italics. Currently with
print_md()
andto_md()
, bold and italic formatting is discarded:It would be cool if huxtable could maintain bold and italic and generate Markdown tables like this (though I don't know how difficult implementing that would be):
If that's not possible, issuing a warning similar to those created when using
huxreg()
(e.g.Markdown cannot handle cells with colspan/rowspan > 1
) could be helpful to warn users that the bold and italics are gone.