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

Margin/div bug when rendering gitbook #733

Closed
3 tasks
varemo opened this issue Jun 26, 2019 · 9 comments
Closed
3 tasks

Margin/div bug when rendering gitbook #733

varemo opened this issue Jun 26, 2019 · 9 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@varemo
Copy link

varemo commented Jun 26, 2019

I have encountered a problem with rendering a book in the gitbook format (bookdown::render_book('file.Rmd')). What happens is that the final HTML is looking fine down to "Section 4" (in my example below). This section is not indented/aligned with the other text but rather starts directly to the right of the sidebar, without any margins. I don't understand why it happens at Section 4 and not also Section 2.

If I add echo=FALSE to the last code chunk, this problem goes away.

I have played around with countless modifications of the file below trying to figure out what is causing this but failed to understand. I suspect that it is div tags that are not created correctly, judging by looking at the resulting html files.

A final note is that this was done with bookdown version 0.11, and it seems like the issue is also in 0.10. I downgraded to 0.7 and that resolved the problem.

file.Rmd:

---
title: "Title"
---

# Title

test

## Section 1

test
```{r}
1+1
```

## Section 2

test

## Section 3

test
```{r}
2+2
```

## Section 4

test

image


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('bookdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/bookdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@jwbowers
Copy link

I am having the same problem. It is also visible in the bookdown-demo. Making no changes to the bookdown-demo repo I can confirm this problem. Compare https://bookdown.org/yihui/bookdown-demo/intro.html to https://jwbowers.github.io/bookdown-demo/intro.html .

This problem does not appear when making pdf documents. I haven't checked epub.

It appears that something happens to the html after some R output is created. The example above occurs after a few output chunks. In the bookdown-demo example, it occurs after the first output chunk.

> xfun::session_info('bookdown')
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.5

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  base64enc_0.1.3 bookdown_0.11.1 digest_0.6.19   evaluate_0.14  
  glue_1.3.1      graphics_3.6.0  grDevices_3.6.0 highr_0.8      
  htmltools_0.3.6 jsonlite_1.6    knitr_1.23      magrittr_1.5   
  markdown_1.0    methods_3.6.0   mime_0.7        Rcpp_1.0.1     
  rmarkdown_1.13  stats_3.6.0     stringi_1.4.3   stringr_1.4.0  
  tinytex_0.13    tools_3.6.0     utils_3.6.0     xfun_0.7       
  yaml_2.2.0  

@jwbowers
Copy link

I confirm that downgrading to version .7 worked. I can also confirm that versions .9, .10, .11, and .11.1 all have this problem.

@serine
Copy link

serine commented Jun 28, 2019

This is awesome, I feel so much better since other people starting to hit this issue. I didn't posted on gitissue since the message (when you want to post on gitissues) told me to try other places fist. I have here - Rstudio Community

Exactly the same issue!

I think the issue is with both pandoc and bookdown have lost sync..?

Looking forward for a fix

just FYI I've set up a quick test git repo, so that people can git clone and tested it out on they machine to give quick yay or nay. cheers

@serine
Copy link

serine commented Jun 28, 2019

@jwbowers and @varemo if you keep latest bookdown (0.11) and downgrade to pandoc 2.6 it sort of works. As per Rstudio Comminuty discussion - my more complicated Rmd still doesn't compile properly.

@varemo
Copy link
Author

varemo commented Jun 28, 2019

Thanks @jwbowers and @serine for the pointers! I upgraded back to bookdown=0.11 and downgraded ot pandoc=2.7.2 and got correct rendering, at least for my Rmd-files.

@RLesur
Copy link
Collaborator

RLesur commented Jun 29, 2019

Following @jwbowers , @varemo and @serine , I've inspected the difference between the markups generated by Pandoc 2.7.2 and Pandoc 2.7.3.

The markup generated by bookdown with Pandoc 2.7.3 is invalid.
In the example provided by @jwbowers (https://jwbowers.github.io/bookdown-demo/intro.html), look here https://github.com/jwbowers/bookdown-demo/blob/a3febde6b0525254ba6adcdfdb4861bd5d550d4d/intro.html#L180
The problem is the closing tag </div>: we shouldn't have this tag here.

I think the problem may come from the skylighting library: Pandoc 2.7.2 uses skylighting 0.7.7 and Pandoc 2.7.3 uses skylighting 0.8.1.
The markup produced by skylighting evolved in skylighting 0.8 (see the changelog).

For instance, if we take these simple markdown lines:

```r
print("hello")
```

With Pandoc 2.7.2, the (here, beautified) markup is:

<div class="sourceCode" id="cb1">
    <pre class="sourceCode r">
        <code class="sourceCode r">
            <a class="sourceLine" id="cb1-1" title="1">
                <span class="kw">print</span>
                (<span class="st">&quot;hello&quot;</span>)
            </a>
        </code>
    </pre>
</div>

With Pandoc 2.7.3, we get a new (also beautified) markup:

<div class="sourceCode" id="cb1">
    <pre class="sourceCode r">
        <code class="sourceCode r">
            <span id="cb1-1">
                <a href="#cb1-1"></a>
                <span class="kw">print</span>
                (<span class="st">&quot;hello&quot;</span>)
            </span>
        </code>
    </pre>
</div>

My guess is that this new markup cleaned by bookdown leads to an invalid HTML document.

I am not familiar with all the cleaning operations made internally by bookdown but I wonder whether the clean_pandoc2_highlight_tags() function should be updated

bookdown/R/html.R

Lines 1011 to 1018 in 2c97ef3

# remove the <div> tags around <pre>, and clean up <a> on all lines
clean_pandoc2_highlight_tags = function(x) {
if (!pandoc2.0()) return(x)
x = gsub('(</a></code></pre>)</div>', '\\1', x)
x = gsub('<div class="sourceCode"[^>]+>(<pre)', '\\1', x)
x = gsub('<a class="sourceLine"[^>]+>(.*)</a>', '\\1', x)
x
}

I haven't had time for further investigations. I hope it can help.

@yihui
Copy link
Member

yihui commented Jun 29, 2019

@RLesur This is extremely helpful. I believe you have done 90% of the work. I'll try to finish the rest 10%. Thanks a lot!

@yihui yihui added this to the v0.11 milestone Jun 29, 2019
@yihui yihui added the bug an unexpected problem or unintended behavior label Jun 29, 2019
@yihui yihui modified the milestones: v0.11, v0.12 Jun 29, 2019
@yihui yihui closed this as completed in 364092a Jun 29, 2019
@yihui
Copy link
Member

yihui commented Jun 29, 2019

The 10% work was as simple as removing four characters :)

Please test the current development version of bookdown:

remotes::install_github('rstudio/bookdown')

Let me know if the problem persists. Thanks a lot!

@github-actions
Copy link

github-actions bot commented Nov 6, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants