noamross / redoc

[NOTE: Project in suspended animation for now] Reversible Reproducible Documents
https://noamross.github.io/redoc
Other
514 stars 44 forks source link

Quotes in YAML need to be escaped somehow #54

Open noamross opened 5 years ago

noamross commented 5 years ago

@rmflight this relates to your problem in #41

When rendering a document with R code in YAML with quotes like this, rendering YAML fails with the warning pandoc warning [WARNING] Could not parse YAML metadata:

---
date: "`r Sys.Date()`"
output: 
  redoc::redoc
---

This works if the YAML if placed in single quotes:

---
date: '`r Sys.Date()`'
output: 
  redoc::redoc
---

This is because, prior to knitting, redoc wraps R code in tags that include a quoted class. If you render the document with clean=FALSE, the pre-processed file will look like this:

---
date: "<span class="redoc" id="redoc-inlinecode-1">`r Sys.Date()`</span>"
output: 
  redoc::redoc
---

Currently working on a solution. I previously used pandoc-style native spans, which look like this, but switched to HTML style because something was conflicting with those:

[`r Sys.Date()`]{.redoc #redoc-inlineccode-1}

The yaml package always defaults to writing single quotes, so maybe I should always re-write header YAML as single quotes to avoid this? In any case, using single quotes will temporarily solve the issue.

rmflight commented 5 years ago

Thanks @noamross ! I'll try that out and make sure it works. That's annoying that the type of quote can make a difference, and I'll need to remember to try different types of quotes when I see odd behavior.

rmflight commented 5 years ago

Huh, it does work. Even with highlighting on, the date gets created and highlighted properly as long as I use the single quotes.