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

highlight() output is missing per-line <span> #122

Closed
cderv opened this issue Nov 3, 2021 · 1 comment · Fixed by #146
Closed

highlight() output is missing per-line <span> #122

cderv opened this issue Nov 3, 2021 · 1 comment · Fixed by #146
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@cderv
Copy link
Contributor

cderv commented Nov 3, 2021

This was first report in rstudio/distill#418, as distill_article() is using downlit by default.

In short, downlit is doing the highlighting instead of Pandoc but applies the classes expected by Pandoc. However the resulting structure is different, and this conflict with the CSS inserted by Pandoc. Especially, Pandoc's expect Div > pre > code > on span by line of code > spans for highlighted element.

highlight(..., classes = classes_pandoc()) currently does not create a span per line of code like Pandoc. From details shared in rstudio/distill#418 (comment)

for input

```{r}
configural_model <- '
  # Measurement model
  w1comp =~ w1vst1 + w1vst2 + w1vst3
	w2comp =~ w2vst1 + w2vst2 + w2vst3
'
```

Downlit will output

<span class="va">configural_model</span> <span class="op">&lt;-</span> <span class="st">'
  # Measurement model
  w1comp =~ w1vst1 + w1vst2 + w1vst3
  w2comp =~ w2vst1 + w2vst2 + w2vst3
'</span>

But pandoc will produced

<span id="cb1-1">configural_model <span class="ot">&lt;-</span> <span class="st">'</span></span>
<span id="cb1-2"><span class="st">  # Measurement model</span></span>
<span id="cb1-3"><span class="st">  w1comp =~ w1vst1 + w1vst2 + w1vst3</span></span>
<span id="cb1-4"><span class="st">    w2comp =~ w2vst1 + w2vst2 + w2vst3</span></span>
<span id="cb1-5"><span class="st">'</span></span>

However, Pandoc will insert some CSS for highlighting. e.g in the case of the issue mentioned
https://github.com/jgm/skylighting/blob/87d7b35731d634b9a629b23f6e06a76cf1a0c1d7/skylighting-core/src/Skylighting/Format/HTML.hs#L185

pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }

the display inline-block is causing formatting issue;

it should apply on <span> after <code> only, which are supposed to be the spans for each line, and not the ones holding the highlighting classes.

I could probably deal with that on a per-format basis, to tweak the CSS, but this will need to be done with any HTML format that uses Pandoc's CSS.

It seems last changed in evaluate_and_highlight() from #96 will add a span for each line of a class r-in. This would be compatible with Pandoc.

There is also a probabily that downlit support in distill should be done differently that it is now. It was done early and may need some adjustment (it is done using a knitr hook for now)

@hadley
Copy link
Member

hadley commented Nov 3, 2021

Seems harmless to add the <span> per line that pandoc expects

@hadley hadley added the bug an unexpected problem or unintended behavior label Jun 17, 2022
@hadley hadley changed the title highlight() output conflicts with Pandoc highlighting CSS highlight() output is missing per-line <span> Jun 17, 2022
@hadley hadley added this to the 0.4.1 milestone Jun 17, 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