Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Quotes in YAML need to be escaped somehow #54

Open
noamross opened this issue Aug 28, 2019 · 2 comments
Open

Quotes in YAML need to be escaped somehow #54

noamross opened this issue Aug 28, 2019 · 2 comments

Comments

@noamross
Copy link
Owner

noamross commented Aug 28, 2019

@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
Copy link

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
Copy link

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

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

No branches or pull requests

2 participants