packages feed

cmark-gfm 0.1.2 → 0.1.3

raw patch · 9 files changed

+75/−15 lines, 9 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

cbits/blocks.c view
@@ -980,6 +980,7 @@        (*container)->as.heading.level = level;       (*container)->as.heading.setext = false;+      (*container)->internal_offset = matched;      } else if (!indented && (matched = scan_open_code_fence(                                  input, parser->first_nonspace))) {
cbits/cmark_export.h view
@@ -7,7 +7,7 @@ #  define CMARK_NO_EXPORT #else #  ifndef CMARK_EXPORT-#    ifdef libcmark_EXPORTS+#    ifdef libcmark_gfm_EXPORTS         /* We are building this library */ #      define CMARK_EXPORT __attribute__((visibility("default"))) #    else
cbits/cmark_version.h view
@@ -1,7 +1,8 @@ #ifndef CMARK_VERSION_H #define CMARK_VERSION_H -#define CMARK_VERSION ((0 << 16) | (28 << 8)  | 0)-#define CMARK_VERSION_STRING "0.28.0"+#define CMARK_VERSION ((0 << 24) | (28 << 16) | (0 << 8) | 5)+#define CMARK_VERSION_STRING "0.28.0.gfm.5"+#define CMARK_GFM_VERSION 5  #endif
cbits/inlines.c view
@@ -230,6 +230,47 @@   return cmark_chunk_dup(&subj->input, startpos, len); } +// Return the number of newlines in a given span of text in a subject.  If+// the number is greater than zero, also return the number of characters+// between the last newline and the end of the span in `since_newline`.+static int count_newlines(subject *subj, bufsize_t from, bufsize_t len, int *since_newline) {+  int nls = 0;+  int since_nl = 0;++  while (len--) {+    if (subj->input.data[from++] == '\n') {+      ++nls;+      since_nl = 0;+    } else {+      ++since_nl;+    }+  }++  if (!nls)+    return 0;++  *since_newline = since_nl;+  return nls;+}++// 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, 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) {+    subj->line += newlines;+    node->end_line += newlines;+    node->end_column = since_newline;+    subj->column_offset = -subj->pos + since_newline + extra;+  }+}+ // Try to process a backtick code span that began with a // span of ticks of length openticklength length (already // parsed).  Return 0 if you don't find matching closing@@ -277,7 +318,7 @@  // 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);@@ -293,7 +334,9 @@     cmark_strbuf_trim(&buf);     cmark_strbuf_normalize_whitespace(&buf); -    return make_code(subj, startpos, endpos - openticks.len - 1, cmark_chunk_buf_detach(&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, options);+    return node;   } } @@ -775,7 +818,7 @@  // Parse an autolink or HTML tag. // Assumes the subject has a '<' character at the current position.-static cmark_node *handle_pointy_brace(subject *subj, bool liberal_html_tag) {+static cmark_node *handle_pointy_brace(subject *subj, int options) {   bufsize_t matchlen = 0;   cmark_chunk contents; @@ -804,15 +847,19 @@   if (matchlen > 0) {     contents = cmark_chunk_dup(&subj->input, subj->pos - 1, matchlen + 1);     subj->pos += matchlen;-    return make_raw_html(subj, subj->pos - 1 - matchlen, subj->pos - 1, contents);+    cmark_node *node = make_raw_html(subj, subj->pos - matchlen - 1, subj->pos - 1, contents);+    adjust_subj_node_newlines(subj, node, matchlen, 1, options);+    return node;   } -  if (liberal_html_tag) {+  if (options & CMARK_OPT_LIBERAL_HTML_TAG) {     matchlen = scan_liberal_html_tag(&subj->input, subj->pos);     if (matchlen > 0) {       contents = cmark_chunk_dup(&subj->input, subj->pos - 1, matchlen + 1);       subj->pos += matchlen;-      return make_raw_html(subj, subj->pos - 1 - matchlen, subj->pos - 1, contents);+      cmark_node *node = make_raw_html(subj, subj->pos - matchlen - 1, subj->pos - 1, contents);+      adjust_subj_node_newlines(subj, node, matchlen, 1, options);+      return node;     }   } @@ -1169,7 +1216,7 @@     new_inl = handle_newline(subj);     break;   case '`':-    new_inl = handle_backticks(subj);+    new_inl = handle_backticks(subj, options);     break;   case '\\':     new_inl = handle_backslash(parser, subj);@@ -1178,7 +1225,7 @@     new_inl = handle_entity(subj);     break;   case '<':-    new_inl = handle_pointy_brace(subj, (options & CMARK_OPT_LIBERAL_HTML_TAG) != 0);+    new_inl = handle_pointy_brace(subj, options);     break;   case '*':   case '_':@@ -1240,7 +1287,7 @@                          cmark_reference_map *refmap,                          int options) {   subject subj;-  subject_from_buf(parser->mem, parent->start_line, parent->start_column - 1, &subj, &parent->content, refmap);+  subject_from_buf(parser->mem, parent->start_line, parent->start_column - 1 + parent->internal_offset, &subj, &parent->content, refmap);   cmark_chunk_rtrim(&subj.input);    while (!is_eof(&subj) && parse_inline(parser, &subj, parent, options))
cbits/node.h view
@@ -68,6 +68,7 @@   int start_column;   int end_line;   int end_column;+  int internal_offset;   uint16_t type;   uint16_t flags; 
cbits/table.c view
@@ -28,7 +28,7 @@  typedef struct {   cmark_strbuf *buf;-  int start_offset, end_offset;+  int start_offset, end_offset, internal_offset; } node_cell;  static void free_table_cell(cmark_mem *mem, void *data) {@@ -133,6 +133,10 @@       cell->buf = cell_buf;       cell->start_offset = offset;       cell->end_offset = offset + cell_matched - 1;+      while (cell->start_offset > 0 && string[cell->start_offset - 1] != '|') {+        --cell->start_offset;+        ++cell->internal_offset;+      }       row->n_columns += 1;       row->cells = cmark_llist_append(parser->mem, row->cells, cell);     }@@ -249,6 +253,7 @@       cmark_node *header_cell = cmark_parser_add_child(parser, table_header,           CMARK_NODE_TABLE_CELL, parent_container->start_column + cell->start_offset);       header_cell->start_line = header_cell->end_line = parent_container->start_line;+      header_cell->internal_offset = cell->internal_offset;       header_cell->end_column = parent_container->start_column + cell->end_offset;       cmark_node_set_string_content(header_cell, (char *) cell->buf->ptr);       cmark_node_set_syntax_extension(header_cell, self);@@ -292,6 +297,7 @@       node_cell *cell = (node_cell *) tmp->data;       cmark_node *node = cmark_parser_add_child(parser, table_row_block,           CMARK_NODE_TABLE_CELL, parent_container->start_column + cell->start_offset);+      node->internal_offset = cell->internal_offset;       node->end_column = parent_container->start_column + cell->end_offset;       cmark_node_set_string_content(node, (char *) cell->buf->ptr);       cmark_node_set_syntax_extension(node, self);
changelog view
@@ -1,3 +1,7 @@+cmark-gfm 0.1.3 (10 Aug 2017)++  * Update to cmark-gfm 0.28.0.gfm.6.+ cmark-gfm 0.1.2 (09 Aug 2017)    * Update to cmark-gfm 0.28.0.gfm.5.
cmark-gfm.cabal view
@@ -1,5 +1,5 @@ name:                cmark-gfm-version:             0.1.2+version:             0.1.3 synopsis:            Fast, accurate GitHub Flavored Markdown parser and renderer description:   This package provides Haskell bindings for
test/test-cmark.hs view
@@ -29,7 +29,7 @@   , "<p><a href=\"http://www.google.com\">www.google.com</a></p>\n" ~=? commonmarkToHtml [] [extAutolink] "www.google.com"   , "<p>| a |\n| --- |\n| b |</p>\n" ~=? commonmarkToHtml [] [] "| a |\n| --- |\n| b |\n"   , "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr></tbody></table>\n" ~=? commonmarkToHtml [] [extTable] "| a |\n| --- |\n| b |\n"-  , Node (Just (PosInfo {startLine = 1, startColumn = 1, endLine = 3, endColumn = 17})) DOCUMENT [Node (Just (PosInfo {startLine = 1, startColumn = 1, endLine = 3, endColumn = 17})) (TABLE [LeftAligned,CenterAligned,NoAlignment,RightAligned]) [Node (Just (PosInfo {startLine = 1, startColumn = 1, endLine = 1, endColumn = 17})) TABLE_ROW [Node (Just (PosInfo {startLine = 1, startColumn = 3, endLine = 1, endColumn = 4})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 3, endLine = 1, endColumn = 3})) (TEXT "a") []],Node (Just (PosInfo {startLine = 1, startColumn = 7, endLine = 1, endColumn = 8})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 7, endLine = 1, endColumn = 7})) (TEXT "b") []],Node (Just (PosInfo {startLine = 1, startColumn = 11, endLine = 1, endColumn = 12})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 11, endLine = 1, endColumn = 11})) (TEXT "c") []],Node (Just (PosInfo {startLine = 1, startColumn = 15, endLine = 1, endColumn = 16})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 15, endLine = 1, endColumn = 15})) (TEXT "d") []]],Node (Just (PosInfo {startLine = 3, startColumn = 1, endLine = 3, endColumn = 17})) TABLE_ROW [Node (Just (PosInfo {startLine = 3, startColumn = 3, endLine = 3, endColumn = 4})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 3, endLine = 3, endColumn = 3})) (TEXT "y") []],Node (Just (PosInfo {startLine = 3, startColumn = 7, endLine = 3, endColumn = 8})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 7, endLine = 3, endColumn = 7})) (TEXT "o") []],Node (Just (PosInfo {startLine = 3, startColumn = 11, endLine = 3, endColumn = 12})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 11, endLine = 3, endColumn = 11})) (TEXT "s") []],Node (Just (PosInfo {startLine = 3, startColumn = 15, endLine = 3, endColumn = 16})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 15, endLine = 3, endColumn = 15})) (TEXT "h") []]]]] ~=? commonmarkToNode [] [extTable] "| a | b | c | d |\n| :-- | :-: | --- | --: |\n| y | o | s | h |"+  , Node (Just (PosInfo {startLine = 1, startColumn = 1, endLine = 3, endColumn = 17})) DOCUMENT [Node (Just (PosInfo {startLine = 1, startColumn = 1, endLine = 3, endColumn = 17})) (TABLE [LeftAligned,CenterAligned,NoAlignment,RightAligned]) [Node (Just (PosInfo {startLine = 1, startColumn = 1, endLine = 1, endColumn = 17})) TABLE_ROW [Node (Just (PosInfo {startLine = 1, startColumn = 2, endLine = 1, endColumn = 4})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 3, endLine = 1, endColumn = 3})) (TEXT "a") []],Node (Just (PosInfo {startLine = 1, startColumn = 6, endLine = 1, endColumn = 8})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 7, endLine = 1, endColumn = 7})) (TEXT "b") []],Node (Just (PosInfo {startLine = 1, startColumn = 10, endLine = 1, endColumn = 12})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 11, endLine = 1, endColumn = 11})) (TEXT "c") []],Node (Just (PosInfo {startLine = 1, startColumn = 14, endLine = 1, endColumn = 16})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 15, endLine = 1, endColumn = 15})) (TEXT "d") []]],Node (Just (PosInfo {startLine = 3, startColumn = 1, endLine = 3, endColumn = 17})) TABLE_ROW [Node (Just (PosInfo {startLine = 3, startColumn = 2, endLine = 3, endColumn = 4})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 3, endLine = 3, endColumn = 3})) (TEXT "y") []],Node (Just (PosInfo {startLine = 3, startColumn = 6, endLine = 3, endColumn = 8})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 7, endLine = 3, endColumn = 7})) (TEXT "o") []],Node (Just (PosInfo {startLine = 3, startColumn = 10, endLine = 3, endColumn = 12})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 11, endLine = 3, endColumn = 11})) (TEXT "s") []],Node (Just (PosInfo {startLine = 3, startColumn = 14, endLine = 3, endColumn = 16})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 15, endLine = 3, endColumn = 15})) (TEXT "h") []]]]] ~=? commonmarkToNode [] [extTable] "| a | b | c | d |\n| :-- | :-: | --- | --: |\n| y | o | s | h |"   , "<xmp>\n" ~=? commonmarkToHtml [] [] "<xmp>"   , "&lt;xmp>\n" ~=? commonmarkToHtml [] [extTagfilter] "<xmp>"   ]