Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2.0.0
- The tagfilter extension for markdown_html now actually works (#15)
- Backport patch to filter illegal control characters in markdown_xml()
- Implement LaTeX footnotes (#32)

1.9.5
- Fix parallel make problem
Expand Down
14 changes: 13 additions & 1 deletion src/cmark/latex.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,20 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
break;

case CMARK_NODE_FOOTNOTE_DEFINITION:
if (entering) {
LIT("\\footnotetext[");
OUT(cmark_chunk_to_cstr(renderer->mem, &node->as.literal), false, LITERAL);
LIT("]{");
} else {
LIT("}");
}
break;
case CMARK_NODE_FOOTNOTE_REFERENCE:
// TODO
if (entering) {
LIT("\\footnotemark[");
OUT(cmark_chunk_to_cstr(renderer->mem, &node->parent_footnote_def->as.literal), false, LITERAL);
LIT("]");
}
break;

default:
Expand Down
3 changes: 2 additions & 1 deletion src/patches/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# Upstream PR: https://github.com/github/cmark-gfm/pull/362
patch -p2 -d ../cmark < 362.diff

# Support footnotes for LaTeX: https://github.com/r-lib/commonmark/pull/32
patch -p2 -d ../cmark < latex-footnotes.diff
26 changes: 26 additions & 0 deletions src/patches/latex-footnotes.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/src/cmark/latex.c b/src/cmark/latex.c
index 1a6367a..5fab7ee 100644
--- a/src/cmark/latex.c
+++ b/src/cmark/latex.c
@@ -447,8 +447,20 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
break;

case CMARK_NODE_FOOTNOTE_DEFINITION:
+ if (entering) {
+ LIT("\\footnotetext[");
+ OUT(cmark_chunk_to_cstr(renderer->mem, &node->as.literal), false, LITERAL);
+ LIT("]{");
+ } else {
+ LIT("}");
+ }
+ break;
case CMARK_NODE_FOOTNOTE_REFERENCE:
- // TODO
+ if (entering) {
+ LIT("\\footnotemark[");
+ OUT(cmark_chunk_to_cstr(renderer->mem, &node->parent_footnote_def->as.literal), false, LITERAL);
+ LIT("]");
+ }
break;

default:
14 changes: 14 additions & 0 deletions tests/testthat/test-extensions.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ test_that("autolink", {

})


test_that("footnotes", {
# a single footnote
md <- "Hello[^1]\n\n[^1]: A footnote."
expect_equal(markdown_latex(md, footnotes = FALSE), "Hello{[}\\^{}1{]}\n\n{[}\\^{}1{]}: A footnote.\n")
expect_equal(markdown_latex(md, footnotes = TRUE), "Hello\\footnotemark[1]\n\n\\footnotetext[1]{A footnote.\n\n}\n")

# multiple footnotes
md <- "Hello[^1] World[^foo-2]\n\n[^1]: A footnote.\n\n[^foo-2]: Footnote ID does not have to be a number."
expect_equal(markdown_latex(md, footnotes = FALSE), "Hello{[}\\^{}1{]} World{[}\\^{}foo-2{]}\n\n{[}\\^{}1{]}: A footnote.\n\n{[}\\^{}foo-2{]}: Footnote ID does not have to be a number.\n")
expect_equal(markdown_latex(md, footnotes = TRUE), "Hello\\footnotemark[1] World\\footnotemark[foo-2]\n\n\\footnotetext[1]{A footnote.\n\n}\\footnotetext[foo-2]{Footnote ID does not have to be a number.\n\n}\n")
})


test_that('tagefilter', {
input <- "<title><style></style></title>\n"
expect_equal(input, markdown_html(input))
Expand Down