Title: | Concordances for 'R Markdown' |
---|---|
Description: | Supports concordances in 'R Markdown' documents. This currently allows the original source location in the '.Rmd' file of errors detected by 'HTML tidy' to be found more easily, and potentially allows forward and reverse search in 'HTML' and 'LaTeX' documents produced from 'R Markdown'. The 'LaTeX' support has been included in the most recent development version of the 'patchDVI' package. |
Authors: | Duncan Murdoch [aut, cre], Heather Turner [ctb] |
Maintainer: | Duncan Murdoch <[email protected]> |
License: | GPL-2 |
Version: | 0.3 |
Built: | 2024-11-04 03:02:50 UTC |
Source: | https://github.com/dmurdoch/rmdconcord |
These drivers replace the like-named rmarkdown or markdown drivers with ones that output Commonmark rather than Pandoc Markdown. Commonmark is a dialect of Markdown. The Pandoc driver for Commonmark supports output of source position information. By using this function as your output driver, you can get that in your own documents.
A replacement for markdown::latex_format
is not planned; see the note below.
html_documentC(sourcepos = TRUE, ...) html_vignetteC(sourcepos = TRUE, ...) pdf_documentC0(latex_engine = "pdflatex", sourcepos = TRUE, defineSconcordance = TRUE, ...) html_formatC(options = list(sourcepos = TRUE), ...)
html_documentC(sourcepos = TRUE, ...) html_vignetteC(sourcepos = TRUE, ...) pdf_documentC0(latex_engine = "pdflatex", sourcepos = TRUE, defineSconcordance = TRUE, ...) html_formatC(options = list(sourcepos = TRUE), ...)
latex_engine |
Command to convert ‘.tex’ file to ‘.pdf’. |
defineSconcordance |
If |
sourcepos |
Whether to include source position information. |
options |
The options argument to pass to the base driver. If
|
... |
Other arguments to pass to the base driver. |
Each driver modifies the standard driver from rmarkdown or
markdown, e.g.
html_documentC
is similar to
html_document
, but uses Commonmark
and adds concordances.
An R Markdown output format object which will add concordance information.
The pdf_documentC0
function adds the concordances,
but they won't be interpreted by LaTeX or PDF previewers.
To get that to happen, use patchDVI::pdf_documentC
.
The html_formatC
function requires markdown
version 1.12.1 or higher. If a lower version of that
package is installed
html_formatC
will still run, but will issue a
warning and not add any concordances.
The concordances produced by html_formatC
tend to
be off by a few lines as the underlying Commonmark
processor only issues source position records once per
paragraph.
A latex_formatC
driver appears as if it would be
quite messy and is not currently planned. The issues are:
commonmark doesn't support source position attributes in LaTeX output
It doesn't allow edits between the parsing and rendering steps. This is what pdf_documentC
does.
A possible strategy would be to render first to XML
(which does keep source position attributes), then convert
the XML to LaTeX with macros inserted to record source
positions. However, markdown::latex_format
produces
the final LaTeX document in several steps, and would have to
support this two-stage rendering on some but not all of
the steps.
Duncan Murdoch
These functions produce a new driver which matches the old
one in most respects, but adds an argument sourcepos
(and possibly others).
If that argument is TRUE
(the default) then concordances
are handled by the new driver.
These functions are used to produce html_documentC
and similar drivers
in this package, but should also work on other drivers that produce
HTML output using Pandoc.
html_with_concordance(driver) pdf_with_concordance(driver)
html_with_concordance(driver) pdf_with_concordance(driver)
driver |
An R Markdown driver that produces HTML, LaTeX or PDF using Pandoc. |
A new driver function.
html_with_concordance(rmarkdown::html_fragment) pdf_with_concordance(rmarkdown::latex_fragment)
html_with_concordance(rmarkdown::html_fragment) pdf_with_concordance(rmarkdown::latex_fragment)
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.
processConcordance(filename, newfilename = filename, rename = NULL, followConcordance = TRUE)
processConcordance(filename, newfilename = filename, rename = NULL, followConcordance = TRUE)
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 |
followConcordance |
If |
Called for the side effect of rewriting the concordance, it returns
newfilename
invisibly.
Duncan Murdoch
# 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) # 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) unlink(c(intermediates, outfile1, outfile2), recursive = TRUE)
# 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) # 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) unlink(c(intermediates, outfile1, outfile2), recursive = TRUE)
Pandoc can record concordance information in \datapos
macros
when converting Commonmark documents to LaTeX. This retrieves
that information, and rewrites it as standard R concordance
data.
processLatexConcordance(filename, newfilename = filename, rename = NULL, followConcordance = NULL, defineSconcordance = TRUE)
processLatexConcordance(filename, newfilename = filename, rename = NULL, followConcordance = NULL, defineSconcordance = TRUE)
filename |
The filename of the LaTeX 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 |
followConcordance |
If |
defineSconcordance |
Whether to insert the definition of the |
Called for the side effect of rewriting the concordance, it returns
newfilename
invisibly.
Duncan Murdoch
This function tests for the presence of packages that will support RmdConcord functions.
test_packages(error = TRUE, pandoc = TRUE)
test_packages(error = TRUE, pandoc = TRUE)
error |
If |
pandoc |
Is Pandoc needed? |
A logical value indicating that the
requirements are present. Will never return
FALSE
if error
is TRUE
,
it will just trigger an error.
test_packages()
test_packages()
This function is taken from R-devel, to test the use of RmdConcord in checking packages.
tidy_validate(f, tidy = "tidy")
tidy_validate(f, tidy = "tidy")
f |
An ‘HTML’ file to test. |
tidy |
The name of the |
An object showing issues in the file and locations in the source file.