-
-
Notifications
You must be signed in to change notification settings - Fork 978
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use yaml_metadata_block for preserve_yaml feature when possible (#2190)
This fixes change in Pandoc 2.13 about `yaml_metadata_block` for `commonmark` based formats (fixes #2118)
- Loading branch information
Showing
14 changed files
with
162 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: rmarkdown | ||
Type: Package | ||
Title: Dynamic Documents for R | ||
Version: 2.9.4 | ||
Version: 2.9.5 | ||
Authors@R: c( | ||
person("JJ", "Allaire", role = "aut", email = "[email protected]"), | ||
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/testthat/_snaps/md_document/yaml-block-markdown-meta.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: test | ||
--- | ||
|
||
content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
content |
5 changes: 5 additions & 0 deletions
5
tests/testthat/_snaps/md_document/yaml-block-markdown_github-meta.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: test | ||
--- | ||
|
||
content |
1 change: 1 addition & 0 deletions
1
tests/testthat/_snaps/md_document/yaml-block-markdown_github.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
content |
5 changes: 5 additions & 0 deletions
5
tests/testthat/_snaps/md_document/yaml-block-markdown_mmd-meta.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: test | ||
--- | ||
|
||
content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
content |
5 changes: 5 additions & 0 deletions
5
tests/testthat/_snaps/md_document/yaml-block-markdown_phpextra-meta.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: test | ||
--- | ||
|
||
content |
1 change: 1 addition & 0 deletions
1
tests/testthat/_snaps/md_document/yaml-block-markdown_phpextra.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
content |
5 changes: 5 additions & 0 deletions
5
tests/testthat/_snaps/md_document/yaml-block-markdown_strict-meta.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: test | ||
--- | ||
|
||
content |
1 change: 1 addition & 0 deletions
1
tests/testthat/_snaps/md_document/yaml-block-markdown_strict.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
local_edition(3) | ||
|
||
test_that("adapt_md_variant() adds extensions to markdown variants", { | ||
expect_identical(adapt_md_variant("markdown", TRUE), "markdown+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown_phpextra", TRUE), "markdown_phpextra+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown_mmd", TRUE), "markdown_mmd+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown_strict", TRUE), "markdown_strict+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown_github", TRUE), "markdown_github+yaml_metadata_block") | ||
|
||
expect_identical(adapt_md_variant("markdown", FALSE), "markdown-yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown_phpextra", FALSE), "markdown_phpextra-yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown_mmd", FALSE), "markdown_mmd-yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown_strict", FALSE), "markdown_strict-yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown_github", FALSE), "markdown_github-yaml_metadata_block") | ||
|
||
expect_identical(adapt_md_variant("markdown+yaml_metadata_block", TRUE), "markdown+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown-yaml_metadata_block", TRUE), "markdown-yaml_metadata_block+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown+yaml_metadata_block", FALSE), "markdown+yaml_metadata_block-yaml_metadata_block") | ||
expect_identical(adapt_md_variant("markdown-yaml_metadata_block", FALSE), "markdown-yaml_metadata_block") | ||
|
||
# ignore correctly unsupported variants | ||
expect_identical(adapt_md_variant("markdown_new", TRUE), "markdown_new") | ||
expect_identical(adapt_md_variant("markdown_new", FALSE), "markdown_new") | ||
}) | ||
|
||
test_that("adapt_md_variant() ignored unknown variants", { | ||
expect_identical(adapt_md_variant("markdown_new", TRUE), "markdown_new") | ||
expect_identical(adapt_md_variant("markdown_new", FALSE), "markdown_new") | ||
}) | ||
|
||
test_that("adapt_md_variant() with special variants (pandoc >= 2.13)", { | ||
skip_if_not_pandoc('2.13') | ||
expect_identical(adapt_md_variant("commonmark", TRUE), "commonmark+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("gfm", TRUE), "gfm+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("commonmark_x", TRUE), "commonmark_x+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("commonmark", FALSE), "commonmark-yaml_metadata_block") | ||
expect_identical(adapt_md_variant("gfm", FALSE), "gfm-yaml_metadata_block") | ||
expect_identical(adapt_md_variant("commonmark_x", FALSE), "commonmark_x-yaml_metadata_block") | ||
|
||
expect_identical(adapt_md_variant("gfm+yaml_metadata_block", TRUE), "gfm+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("gfm-yaml_metadata_block", TRUE), "gfm-yaml_metadata_block+yaml_metadata_block") | ||
expect_identical(adapt_md_variant("gfm+yaml_metadata_block", FALSE), "gfm+yaml_metadata_block-yaml_metadata_block") | ||
expect_identical(adapt_md_variant("gfm-yaml_metadata_block", FALSE), "gfm-yaml_metadata_block") | ||
|
||
}) | ||
|
||
test_that("adapt_md_variant() with special variants (pandoc < 2.13)", { | ||
skip_if_pandoc('2.13') | ||
expect_identical(adapt_md_variant("commonmark", TRUE), "commonmark") | ||
expect_identical(adapt_md_variant("gfm", TRUE), "gfm") | ||
expect_identical(adapt_md_variant("commonmark_x", TRUE), "commonmark_x") | ||
expect_identical(adapt_md_variant("commonmark", FALSE), "commonmark") | ||
expect_identical(adapt_md_variant("gfm", FALSE), "gfm") | ||
expect_identical(adapt_md_variant("commonmark_x", FALSE), "commonmark_x") | ||
}) | ||
|
||
test_that("md_document() can preserve yaml", { | ||
skip_on_cran() # avoid pandoc issue on CRAN | ||
expect_snapshot_md <- function(variant, preserve_yaml) { | ||
rmd <- local_rmd_file(c("---", "title: test", "---", "", "content")) | ||
res <- render(rmd, md_document(variant, preserve_yaml = preserve_yaml), quiet = TRUE) | ||
expect_snapshot_file(res, sprintf("yaml-block-%s%s.md", variant, if (preserve_yaml) "-meta" else "")) | ||
} | ||
expect_snapshot_md("markdown", preserve_yaml = FALSE) | ||
expect_snapshot_md("markdown_phpextra", preserve_yaml = FALSE) | ||
expect_snapshot_md("markdown_mmd", preserve_yaml = FALSE) | ||
expect_snapshot_md("markdown_strict", preserve_yaml = FALSE) | ||
expect_snapshot_md("markdown_github", preserve_yaml = FALSE) | ||
expect_snapshot_md("markdown", preserve_yaml = TRUE) | ||
expect_snapshot_md("markdown_phpextra", preserve_yaml = TRUE) | ||
expect_snapshot_md("markdown_mmd", preserve_yaml = TRUE) | ||
expect_snapshot_md("markdown_strict", preserve_yaml = TRUE) | ||
expect_snapshot_md("markdown_github", preserve_yaml = TRUE) | ||
}) | ||
|