Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multline strings formatted incorrectly? #139

Closed
hadley opened this issue May 26, 2022 · 5 comments · Fixed by #146
Closed

Multline strings formatted incorrectly? #139

hadley opened this issue May 26, 2022 · 5 comments · Fixed by #146
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@hadley
Copy link
Member

hadley commented May 26, 2022

con |> 
  dbGetQuery("
    SELECT carat, cut, clarity, color, price 
    FROM diamonds 
    WHERE price > 15000
  ") |> 
  as_tibble()

looks like

Screen Shot 2022-05-26 at 10 28 00

Because, I think, the multi-line string is put in a single span.

@cderv
Copy link
Contributor

cderv commented Jun 17, 2022

We also have something related in Quarto which uses downlit: quarto-dev/quarto-cli#1165

Chunk to highlight

strwrap(
  "Volcano plot - Response Size and Significance of Differential
  Expression among all miRNA at Baseline", width = 80
)

We get a single <span> for the whole multiline

chunk_content <-
  c(
    "strwrap(\n  \"Volcano plot - Response Size and Significance of Differential\n  Expression among all miRNA at Baseline\", width = 80\n)"
  )

res <- downlit::highlight(chunk_content, downlit::classes_pandoc())

xfun::raw_string(res)
#> <span class='fu'><a href='https://rdrr.io/r/base/strwrap.html'>strwrap</a></span><span class='op'>(</span>
#>   <span class='st'>"Volcano plot - Response Size and Significance of Differential
#>   Expression among all miRNA at Baseline"</span>, width <span class='op'>=</span> <span class='fl'>80</span>
#> <span class='op'>)</span>

Created on 2022-06-17 by the reprex package (v2.0.1)

Output is like
image

Related to #133 as Pandoc correctly adds a <span> per line, but it is lost in the translation when applying downlit_html_path()

@hadley
Copy link
Member Author

hadley commented Jun 17, 2022

Yeah, I'm pretty sure the problem is multi-line strings.

@hadley hadley changed the title Something messed up with this code Multline strings formatted incorrectly? Jun 17, 2022
@hadley hadley added the bug an unexpected problem or unintended behavior label Jun 17, 2022
@hadley hadley added this to the 0.4.1 milestone Jun 17, 2022
@hadley
Copy link
Member Author

hadley commented Jun 21, 2022

Minimal reprex with rmd:

---
output: 
  html_document:
    highlight_downlit: true
---

```{r, results = FALSE}
paste("Line 1
  Line 2
  Line 3"
)
```

which generates:

<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste</a></span><span class="op">(</span><span class="st">"Line 1
  Line 2
  Line 3"</span>
<span class="op">)</span></code></pre></div>

@hadley
Copy link
Member Author

hadley commented Jun 21, 2022

And the messed appearance arises because pre > code.sourceCode > span is given display: inline-block;.

@hadley
Copy link
Member Author

hadley commented Jun 21, 2022

Minimal reprex just using downlit:

cat(downlit::highlight('paste("Line 1
  Line 2
  Line 3"
)'))
#> <span class='nf'><a href='https://rdrr.io/r/base/paste.html'>paste</a></span><span class='o'>(</span><span class='s'>"Line 1
#>   Line 2
#>   Line 3"</span>
#> <span class='o'>)</span>

Created on 2022-06-21 by the reprex package (v2.0.1)

hadley added a commit that referenced this issue Jun 21, 2022
@hadley hadley mentioned this issue Jun 21, 2022
hadley added a commit that referenced this issue Jun 22, 2022
* For individual tokens (Fixes #139).
* For every line (Fixes #122).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants