summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blocks.c12
-rw-r--r--src/cmark.h2
-rw-r--r--src/main.c2
-rw-r--r--src/parser.h1
4 files changed, 14 insertions, 3 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 00639cf..f49ad4e 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -90,6 +90,7 @@ cmark_parser *cmark_parser_new(int options) {
parser->last_line_length = 0;
parser->linebuf = buf;
parser->options = options;
+ parser->last_buffer_ended_with_cr = false;
return parser;
}
@@ -506,6 +507,11 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer,
const unsigned char *end = buffer + len;
static const uint8_t repl[] = {239, 191, 189};
+ if (parser->last_buffer_ended_with_cr && *buffer == '\n') {
+ // skip NL if last buffer ended with CR ; see #117
+ buffer++;
+ }
+ parser->last_buffer_ended_with_cr = false;
while (buffer < end) {
const unsigned char *eol;
bufsize_t chunk_len;
@@ -546,8 +552,11 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer,
buffer += chunk_len;
// skip over line ending characters:
- if (buffer < end && *buffer == '\r')
+ if (buffer < end && *buffer == '\r') {
buffer++;
+ if (buffer == end)
+ parser->last_buffer_ended_with_cr = true;
+ }
if (buffer < end && *buffer == '\n')
buffer++;
}
@@ -1124,6 +1133,7 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer,
parser->offset = 0;
parser->column = 0;
parser->blank = false;
+ parser->partially_consumed_tab = false;
input.data = parser->curline->ptr;
input.len = parser->curline->size;
diff --git a/src/cmark.h b/src/cmark.h
index 31bbf01..3c5d6b6 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -418,7 +418,7 @@ CMARK_EXPORT void cmark_consolidate_text_nodes(cmark_node *root);
* Streaming interface:
*
* cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT);
- * FILE *fp = fopen("myfile.md", "r");
+ * FILE *fp = fopen("myfile.md", "rb");
* while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
* cmark_parser_feed(parser, buffer, bytes);
* if (bytes < sizeof(buffer)) {
diff --git a/src/main.c b/src/main.c
index a78c76a..fa18e03 100644
--- a/src/main.c
+++ b/src/main.c
@@ -146,7 +146,7 @@ int main(int argc, char *argv[]) {
parser = cmark_parser_new(options);
for (i = 0; i < numfps; i++) {
- FILE *fp = fopen(argv[files[i]], "r");
+ FILE *fp = fopen(argv[files[i]], "rb");
if (fp == NULL) {
fprintf(stderr, "Error opening file %s: %s\n", argv[files[i]],
strerror(errno));
diff --git a/src/parser.h b/src/parser.h
index b3ff39b..ab21d0f 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -27,6 +27,7 @@ struct cmark_parser {
bufsize_t last_line_length;
cmark_strbuf *linebuf;
int options;
+ bool last_buffer_ended_with_cr;
};
#ifdef __cplusplus