summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuki Izumi <ashe@kivikakk.ee>2017-08-10 13:39:36 +1000
committerYuki Izumi <ashe@kivikakk.ee>2017-08-10 13:39:36 +1000
commit9853666272e87c83050f7e30ae4b3ed9890c8c4f (patch)
tree04b443286c1b2d3a94fce86358efccb06b6ad383
parente22d1b42ce7f860c51c261ea9d42c0b77245fde5 (diff)
Skip sourcepos tracking if disabled
-rw-r--r--src/inlines.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/inlines.c b/src/inlines.c
index 07f3709..21b11e1 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -265,7 +265,11 @@ static int count_newlines(subject *subj, bufsize_t from, bufsize_t len, int *sin
// Adjust `node`'s `end_line`, `end_column`, and `subj`'s `line` and
// `column_offset` according to the number of newlines in a just-matched span
// of text in `subj`.
-static void adjust_subj_node_newlines(subject *subj, cmark_node *node, int matchlen, int extra) {
+static void adjust_subj_node_newlines(subject *subj, cmark_node *node, int matchlen, int extra, int options) {
+ if (!(options & CMARK_OPT_SOURCEPOS)) {
+ return;
+ }
+
int since_newline;
int newlines = count_newlines(subj, subj->pos - matchlen - extra, matchlen, &since_newline);
if (newlines) {
@@ -323,7 +327,7 @@ static bufsize_t scan_to_closing_backticks(subject *subj,
// Parse backtick code section or raw backticks, return an inline.
// Assumes that the subject has a backtick at the current position.
-static cmark_node *handle_backticks(subject *subj) {
+static cmark_node *handle_backticks(subject *subj, int options) {
cmark_chunk openticks = take_while(subj, isbacktick);
bufsize_t startpos = subj->pos;
bufsize_t endpos = scan_to_closing_backticks(subj, openticks.len);
@@ -340,7 +344,7 @@ static cmark_node *handle_backticks(subject *subj) {
cmark_strbuf_normalize_whitespace(&buf);
cmark_node *node = make_code(subj, startpos, endpos - openticks.len - 1, cmark_chunk_buf_detach(&buf));
- adjust_subj_node_newlines(subj, node, endpos - startpos, openticks.len);
+ adjust_subj_node_newlines(subj, node, endpos - startpos, openticks.len, options);
return node;
}
}
@@ -798,7 +802,7 @@ cmark_chunk cmark_clean_title(cmark_mem *mem, cmark_chunk *title) {
// Parse an autolink or HTML tag.
// Assumes the subject has a '<' character at the current position.
-static cmark_node *handle_pointy_brace(subject *subj) {
+static cmark_node *handle_pointy_brace(subject *subj, int options) {
bufsize_t matchlen = 0;
cmark_chunk contents;
@@ -828,7 +832,7 @@ static cmark_node *handle_pointy_brace(subject *subj) {
contents = cmark_chunk_dup(&subj->input, subj->pos - 1, matchlen + 1);
subj->pos += matchlen;
cmark_node *node = make_raw_html(subj, subj->pos - matchlen - 1, subj->pos - 1, contents);
- adjust_subj_node_newlines(subj, node, matchlen, 1);
+ adjust_subj_node_newlines(subj, node, matchlen, 1, options);
return node;
}
@@ -1179,7 +1183,7 @@ static int parse_inline(subject *subj, cmark_node *parent, int options) {
new_inl = handle_newline(subj);
break;
case '`':
- new_inl = handle_backticks(subj);
+ new_inl = handle_backticks(subj, options);
break;
case '\\':
new_inl = handle_backslash(subj);
@@ -1188,7 +1192,7 @@ static int parse_inline(subject *subj, cmark_node *parent, int options) {
new_inl = handle_entity(subj);
break;
case '<':
- new_inl = handle_pointy_brace(subj);
+ new_inl = handle_pointy_brace(subj, options);
break;
case '*':
case '_':