コード例 #1
0
ファイル: blocks.c プロジェクト: gcgft/cmark
static cmark_node *finalize_document(cmark_parser *parser) {
  while (parser->current != parser->root) {
    parser->current = finalize(parser, parser->current);
  }

  finalize(parser, parser->root);
  process_inlines(parser->root, parser->refmap, parser->options);

  return parser->root;
}
コード例 #2
0
ファイル: blocks.c プロジェクト: Frozen-Shadow/CommonMark
static cmark_node *finalize_document(cmark_doc_parser *parser)
{
	while (parser->current != parser->root) {
		finalize(parser, parser->current, parser->line_number);
		parser->current = parser->current->parent;
	}

	finalize(parser, parser->root, parser->line_number);
	process_inlines(parser->root, parser->refmap);

	return parser->root;
}
コード例 #3
0
ファイル: main.c プロジェクト: CyberLight/stmd
int main(int argc, char *argv[]) {
  int i;
  bool ast = false;
  int g = 0;
  int numfps = 0;
  int files[argc];

  for (i=1; i < argc; i++) {
    if (strcmp(argv[i], "--version") == 0) {
      printf("stmd %s", VERSION);
      printf(" - standard markdown converter (c) 2014 John MacFarlane\n");
      exit(0);
    } else if ((strcmp(argv[i], "--help") == 0) ||
               (strcmp(argv[i], "-h") == 0)) {
      print_usage();
      exit(0);
    } else if (strcmp(argv[i], "--ast") == 0) {
      ast = true;
    } else if (*argv[i] == '-') {
      print_usage();
      exit(1);
    } else { // treat as file argument
      files[g] = i;
      g++;
    }
  }

  numfps = g;
  bstring s = NULL;
  bstring html;
  g = 0;
  block * cur = make_document();
  int linenum = 1;
  extern int errno;
  FILE * fp = NULL;

  if (numfps == 0) {
    // read from stdin
    while ((s = bgets((bNgetc) fgetc, stdin, '\n'))) {
      check(incorporate_line(s, linenum, &cur) == 0,
          "error incorporating line %d", linenum);
      bdestroy(s);
      linenum++;
    }
  } else {
    // iterate over input file pointers
    for (g=0; g < numfps; g++) {

      fp = fopen(argv[files[g]], "r");
      if (fp == NULL) {
        fprintf(stderr, "Error opening file %s: %s\n",
                argv[files[g]], strerror(errno));
        exit(1);
      }

      while ((s = bgets((bNgetc) fgetc, fp, '\n'))) {
        check(incorporate_line(s, linenum, &cur) == 0,
            "error incorporating line %d", linenum);
        bdestroy(s);
        linenum++;
      }
      fclose(fp);
    }
  }

  while (cur != cur->top) {
    finalize(cur, linenum);
    cur = cur->parent;
  }
  check(cur == cur->top, "problems finalizing open containers");
  finalize(cur, linenum);
  process_inlines(cur, cur->attributes.refmap);
  if (ast) {
    print_blocks(cur, 0);
  } else {
    check(blocks_to_html(cur, &html, false) == 0, "could not format as HTML");
    printf("%s", html->data);
    bdestroy(html);
  }
  free_blocks(cur);
  return 0;
error:
  return -1;
}