diff --git a/R/markdown.R b/R/markdown.R index 562fd22..fdba80f 100644 --- a/R/markdown.R +++ b/R/markdown.R @@ -74,8 +74,8 @@ markdown_text <- function(text, hardbreaks = FALSE, smart = FALSE, normalize = F #' @export #' @rdname commonmark -markdown_latex <- function(text, hardbreaks = FALSE, smart = FALSE, normalize = FALSE, footnotes = FALSE, width = 0, extensions = FALSE){ +markdown_latex <- function(text, hardbreaks = FALSE, smart = FALSE, normalize = FALSE, sourcepos = FALSE, footnotes = FALSE, width = 0, extensions = FALSE){ text <- enc2utf8(paste(text, collapse="\n")) extensions <- get_extensions(extensions) - .Call(R_render_markdown, text, 6L, FALSE, hardbreaks, smart, normalize, footnotes, as.integer(width), extensions) + .Call(R_render_markdown, text, 6L, sourcepos, hardbreaks, smart, normalize, footnotes, as.integer(width), extensions) } diff --git a/man/commonmark.Rd b/man/commonmark.Rd index 6d9b26f..129891e 100644 --- a/man/commonmark.Rd +++ b/man/commonmark.Rd @@ -66,6 +66,7 @@ markdown_latex( hardbreaks = FALSE, smart = FALSE, normalize = FALSE, + sourcepos = FALSE, footnotes = FALSE, width = 0, extensions = FALSE diff --git a/src/cmark/latex.c b/src/cmark/latex.c index 8be15b0..e884691 100644 --- a/src/cmark/latex.c +++ b/src/cmark/latex.c @@ -15,9 +15,19 @@ #define OUT(s, wrap, escaping) renderer->out(renderer, node, s, wrap, escaping) #define LIT(s) renderer->out(renderer, node, s, false, LITERAL) #define CR() renderer->cr(renderer) -#define BLANKLINE() renderer->blankline(renderer) +#define BLANKLINE() latex_out_sourcepos(node, renderer, options); renderer->blankline(renderer) #define LIST_NUMBER_STRING_SIZE 20 +static CMARK_INLINE void latex_out_sourcepos(cmark_node *node, cmark_renderer *renderer, int options){ + char buffer[100]; + if (CMARK_OPT_SOURCEPOS & options) { + snprintf(buffer, 100, " %%sourcepos(%d:%d-%d:%d)", + cmark_node_get_start_line(node), cmark_node_get_start_column(node), + cmark_node_get_end_line(node), cmark_node_get_end_column(node)); + renderer->out(renderer, node, buffer, false, LITERAL); + } +} + static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_node *node, cmark_escaping escape, int32_t c, unsigned char nextc) {