Example #1
0
static cmark_node *try_opening_code_block(cmark_syntax_extension *self,
        bool indented,
        cmark_parser *parser,
        cmark_node *parent,
        const char *input)
{
    cmark_node *ret = NULL;
    cmark_bufsize_t matched = scan_open_gtkdoc_code_block(input,
                              cmark_parser_get_first_nonspace(parser));

    if (!indented && matched) {
        ret = cmark_parser_add_child(parser, parent,
                                     CMARK_NODE_CODE_BLOCK, cmark_parser_get_offset(parser));
        cmark_node_set_syntax_extension(ret, self);
        cmark_node_set_fenced(ret, true, 2,
                              cmark_parser_get_first_nonspace(parser) - cmark_parser_get_offset(parser),
                              0);
        cmark_parser_advance_offset(parser, input, matched, false);

        matched = scan_language_comment(input, matched);
        if (matched) {
            cmark_strbuf *lang = cmark_strbuf_new(32);
            cmark_strbuf_put(lang, (unsigned char *) input + 17, matched - 20);
            /* Will be transformed to fence info */
            cmark_node_set_string_content(ret, cmark_strbuf_get(lang));
            cmark_strbuf_free(lang);
            cmark_parser_advance_offset(parser, input, matched, false);
        }

    }

    return ret;
}
static delimiter *insert(cmark_syntax_extension *self, cmark_parser *parser,
                         cmark_inline_parser *inline_parser, delimiter *opener,
                         delimiter *closer) {
  cmark_node *strikethrough;
  cmark_node *tmp, *next;
  delimiter *delim, *tmp_delim;
  delimiter *res = closer->next;

  strikethrough = opener->inl_text;

  if (!cmark_node_set_type(strikethrough, CMARK_NODE_STRIKETHROUGH))
    goto done;

  cmark_node_set_syntax_extension(strikethrough, self);

  cmark_node_set_string_content(strikethrough, "~");
  tmp = cmark_node_next(opener->inl_text);

  while (tmp) {
    if (tmp == closer->inl_text)
      break;
    next = cmark_node_next(tmp);
    cmark_node_append_child(strikethrough, tmp);
    tmp = next;
  }

  strikethrough->end_column = closer->inl_text->start_column + closer->inl_text->as.literal.len - 1;
  cmark_node_free(closer->inl_text);

  delim = closer;
  while (delim != NULL && delim != opener) {
    tmp_delim = delim->previous;
    cmark_inline_parser_remove_delimiter(inline_parser, delim);
    delim = tmp_delim;
  }

  cmark_inline_parser_remove_delimiter(inline_parser, opener);

done:
  return res;
}