Skip to contents

Pandoc can record concordance information in datapos attributes when converting Commonmark documents to HTML. This retrieves that information, and rewrites it as standard R concordance data.

Usage

processConcordance(filename, newfilename = filename,
                      rename = NULL,
                      followConcordance = TRUE)

Arguments

filename

The filename of the HTML file produced by Pandoc.

newfilename

A filename in which to write the changed data.

rename

A named character vector. Names are the names in the datapos attributes; values are the names that should be included in the concordance instead. This might be used since knitr produces a Markdown file and renames it later.

followConcordance

If filename already contains concordance data, assume that the Rmd file was produced automatically, and chain the concordances.

Value

Called for the side effect of rewriting the concordance, it returns newfilename invisibly.

Author

Duncan Murdoch

Examples

# This example works on the file inst/sample/Sample.Rmd,
# which should be a copy of the vignette Sample.Rmd.  This
# is convenient because RStudio doesn't install vignettes by default.

# First, see the results without concordances:

library(RmdConcord)
dir <- tempdir()
intermediates <- tempfile()

infile <- system.file("sample/Sample.Rmd", package = "RmdConcord")
outfile1 <- file.path(dir, "html_vignette.html")

rmarkdown::render(infile,
                  intermediates_dir = intermediates,
                  output_file = outfile1,
                  quiet = TRUE)
tidy_validate(outfile1)
#>      line  col msg                                       txt              
#> [1,] "359" "4" "Error: <foobar> is not recognized!"      "<p><foobar></p>"
#> [2,] "359" "4" "Warning: discarding unexpected <foobar>" "<p><foobar></p>"

# Next, see them with concordances by setting
# the output format to use RmdConcord::html_documentC
# which post-processes the document with processConcordance.

dir <- tempdir()
outfile2 <- file.path(dir, "commonmark.html")
rmarkdown::render(infile,
                  intermediates_dir = intermediates,
                  output_file = outfile2,
                  output_format = html_documentC(),
                  quiet = TRUE)
tidy_validate(outfile2)
#>      line  col msg                                       txt       
#> [1,] "319" "1" "Error: <foobar> is not recognized!"      "<foobar>"
#> [2,] "319" "1" "Warning: discarding unexpected <foobar>" "<foobar>"
#>      srcFile      srcLine
#> [1,] "Sample.Rmd" "23"   
#> [2,] "Sample.Rmd" "23"   
unlink(c(intermediates, outfile1, outfile2), recursive = TRUE)