예제 #1
0
static cmark_node *function_link_match(cmark_syntax_extension *self,
                                cmark_parser *parser,
                                cmark_node *parent,
                                cmark_inline_parser *inline_parser)
{
  cmark_node *ret = NULL;
  delimiter *tmp_delim;
  int offset;
  int start;

  offset = cmark_inline_parser_get_offset(inline_parser);

  if (offset == 0)
    goto done;

  if (cmark_inline_parser_peek_at(inline_parser, offset + 1) != ')')
    goto done;

  start = offset - 1;

  if (!is_valid_c(cmark_inline_parser_peek_at(inline_parser, start)))
    goto done;

  while (start >= 0) {
    unsigned char c = cmark_inline_parser_peek_at(inline_parser, start);

    if (is_valid_c(c)) {
      start -= 1;
    } else {
      break;
    }
  }

  ret = fixup_nodes(inline_parser, parent, offset - start - 1);

  if (!ret)
    goto done;

  tmp_delim = cmark_inline_parser_get_last_delimiter(inline_parser);

  while (tmp_delim) {
    delimiter *prev = tmp_delim->previous;

    if (tmp_delim->position < start + 1) {
      break;
    }

    cmark_inline_parser_remove_delimiter(inline_parser, tmp_delim);
    tmp_delim = prev;
  }

  cmark_inline_parser_advance_offset(inline_parser);
  cmark_inline_parser_advance_offset(inline_parser);

done:
  return ret;
}
예제 #2
0
static cmark_node *param_ref_match(cmark_syntax_extension *self,
                                   cmark_parser *parser,
                                   cmark_node *parent,
                                   cmark_inline_parser *inline_parser) {
    cmark_node *emph, *text_node;
    char *param_name;
    char prev_char;
    ParsingContext context;

    context.parser = inline_parser;
    context.allow_dashes = 0;

    prev_char = cmark_inline_parser_peek_at(
                    inline_parser,
                    cmark_inline_parser_get_offset(inline_parser) - 1);

    if (prev_char && prev_char != ' ' && prev_char != '\t' && prev_char != '\n')
        return NULL;

    cmark_inline_parser_advance_offset(inline_parser);
    param_name = cmark_inline_parser_take_while(inline_parser,
                 (CMarkInlinePredicate) is_valid_c, &context);

    if (!param_name)
        return NULL;

    emph = cmark_node_new(CMARK_NODE_EMPH);
    text_node = cmark_node_new(CMARK_NODE_TEXT);
    cmark_node_append_child(emph, text_node);

    cmark_node_set_literal(text_node, param_name);
    free(param_name);
    return emph;
}
예제 #3
0
static cmark_node *symbol_link_match(cmark_syntax_extension *self,
                                cmark_parser *parser,
                                cmark_node *parent,
                                cmark_inline_parser *inline_parser) {
  cmark_node *link;
  char *symbol_name;

  if (cmark_inline_parser_get_offset(inline_parser) > 0) {
    char prev_char = cmark_inline_parser_peek_at(
        inline_parser,
        cmark_inline_parser_get_offset(inline_parser) - 1);

    if (prev_char && prev_char != ' ' && prev_char != '\t' && prev_char != '\n')
      return NULL;
  }

  cmark_inline_parser_advance_offset(inline_parser);

  symbol_name = cmark_inline_parser_take_while(inline_parser,
      (CMarkInlinePredicate) is_valid_symbol_name);

  if (!symbol_name)
    return NULL;

  link = cmark_node_new(CMARK_NODE_LINK);

  cmark_node_set_url(link, symbol_name);
  free(symbol_name);

  return link;
}
예제 #4
0
static cmark_node *symbol_link_match(cmark_syntax_extension *self,
                                     cmark_parser *parser,
                                     cmark_node *parent,
                                     cmark_inline_parser *inline_parser) {
    cmark_node *link = NULL;
    char *symbol_name = NULL;
    NamedLink *named_link = NULL;
    int start_offset = cmark_inline_parser_get_offset(inline_parser);
    ParsingContext context;

    context.parser = inline_parser;
    context.allow_dashes = 0;

    if (start_offset > 0) {
        char prev_char = cmark_inline_parser_peek_at(
                             inline_parser,
                             start_offset - 1);

        if (prev_char && prev_char != ' ' && prev_char != '\t' && prev_char != '\n')
            return NULL;
    }

    cmark_inline_parser_advance_offset(inline_parser);

    symbol_name = cmark_inline_parser_take_while(inline_parser,
                  (CMarkInlinePredicate) is_valid_symbol_name, &context);

    if (!symbol_name)
        goto done;

    named_link = PRIV(self)->link_resolve_func(symbol_name);
    if (!named_link || !named_link->ref) {
        int actual_line, actual_col;

        translate_sourcepos(get_first_parent_block(parent),
                            start_offset, &actual_line, &actual_col);
        cmark_strbuf *message = cmark_strbuf_new(0);
        cmark_strbuf_puts(message, "Trying to link to non-existing symbol ‘");
        cmark_strbuf_puts(message, symbol_name);
        cmark_strbuf_puts(message, "’");
        diagnose("gtk-doc-bad-link", cmark_strbuf_get(message), actual_line - 1, actual_col - 1);
        cmark_strbuf_free(message);
        link = cmark_node_new (CMARK_NODE_TEXT);
        cmark_node_set_literal (link, symbol_name);
    } else {
        link = cmark_node_new(CMARK_NODE_LINK);
    }

    cmark_node_set_url(link, symbol_name);

done:
    free(symbol_name);
    free_named_link(named_link);

    return link;
}
예제 #5
0
static int is_valid_c_or_dbus(ParsingContext *context, int c, int pos) {
    if (is_valid_c(c, pos, context))
        return 1;


    if (c == '.') {
        char nc = cmark_inline_parser_peek_at(context->parser, pos + 1);

        if (!nc || is_valid_c(nc, pos + 1, context))
            return 0;

        if (pos > 0) {
            nc = cmark_inline_parser_peek_at(context->parser, pos - 1);
            return is_valid_c(nc, pos + 1, context);
        }

        return 1;
    }

    return 0;
}
예제 #6
0
static int is_valid_symbol_name(int c, int pos, ParsingContext *context) {
    if (is_valid_c(c, pos, context))
        return 1;

    if (c == ':' || c == '-' || c == '.') {
        char nc = cmark_inline_parser_peek_at(context->parser, pos + 1);

        if (c == ':')
            context->allow_dashes = 1;
        else if (c == '-' && !context->allow_dashes)
            return 0;

        return (nc && is_valid_symbol_name(nc, pos + 1, context));
    }
    return 0;
}