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

R Code chunks mis-align when a left-handed arrow is present; not responding to tidy option #345

Closed
chunyunma opened this issue Nov 22, 2018 · 3 comments
Milestone

Comments

@chunyunma
Copy link

Dear Yihui,

I recently started playing with blogdown and have been having trouble with R code chunks that contain a left-handed arrow "<-". I tested the following two chunks in a blog post:

plot <- ggplot(df, 
               
   aes(x = x, y = y))
plot <- ggplot(df, 
               
   aes(x = x, y = y))

You can see the result here (link)
Turning on and off the tidy option did not seem to make a difference, either.

Did I miss something here or is this a bug with blogdown?

Thank you very much!

Warmly, Chunyun

@chunyunma chunyunma changed the title R Code chunks not responding to tidy option R Code chunks mis-align when a left-handed arrow is present; not responding to tidy option Nov 22, 2018
@tcgriffith
Copy link
Collaborator

I've seen this issue before, for the Tranquilpeak theme in particular. See #321

The problem is that R code chunks are mistakenly treated as xml code chunks by the default highlightjs from the theme.

The final solution we came up is to re-configure the highlight js as in here
#321 (comment)

@chunyunma
Copy link
Author

chunyunma commented Nov 23, 2018

Thank you very much for your quick reply! @tcgriffith I followed the solution you referenced and finally got it working! Here is what I did:

  • Commented out syntaxHighlighter = "highlight.js" in confit.toml
  • Followed step two described here. The tutorial was very comprehensive. The only part not very clear to me was where to add that three lines of code. I added them inside head.html starting at line43

@tcgriffith
Copy link
Collaborator

Thank you very much for your quick reply! @tcgriffith I followed the solution you referenced and finally got it working! Here is what I did:

  • Commented out syntaxHighlighter = "highlight.js" in confit.toml
  • Followed step two described here. The tutorial was very comprehensive. The only part not very clear to me was where to add that three lines of code. I added them inside head.html starting at line43

You are doing it alright.

if you edited the theme files directly, they may be lost if you need to update the theme. A better way is to override the theme files.

In your case:

  • Copy head.html from /*blogrepo*/themes/hugo-tranquilpeak-theme/layouts/partials/head.html
    to /*blogrepo*/layouts/partials/head.html
  • Copy the downloaded highlight.js to /*blogrepo*/static/js/highlight.js

Source: https://gohugo.io/templates/base/#override-the-base-template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants