Skip to content

Commit

Permalink
Revert out changes to blocks.c and manually control cmark extensions …
Browse files Browse the repository at this point in the history
…where we should be doing it
  • Loading branch information
0xTim committed Mar 5, 2021
1 parent c25ea28 commit e97450a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
10 changes: 0 additions & 10 deletions Sources/cmark/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,6 @@ static cmark_node *finalize_document(cmark_parser *parser) {
cmark_node *cmark_parse_file(FILE *f, int options) {
unsigned char buffer[4096];
cmark_parser *parser = cmark_parser_new(options);
cmark_parser_attach_syntax_extension(parser, create_autolink_extension());
cmark_parser_attach_syntax_extension(parser, create_strikethrough_extension());
cmark_parser_attach_syntax_extension(parser, create_table_extension());
cmark_parser_attach_syntax_extension(parser, create_tagfilter_extension());
cmark_parser_attach_syntax_extension(parser, create_tasklist_extension());
size_t bytes;
cmark_node *document;

Expand All @@ -666,11 +661,6 @@ cmark_node *cmark_parse_file(FILE *f, int options) {

cmark_node *cmark_parse_document(const char *buffer, size_t len, int options) {
cmark_parser *parser = cmark_parser_new(options);
cmark_parser_attach_syntax_extension(parser, create_autolink_extension());
cmark_parser_attach_syntax_extension(parser, create_strikethrough_extension());
cmark_parser_attach_syntax_extension(parser, create_table_extension());
cmark_parser_attach_syntax_extension(parser, create_tagfilter_extension());
cmark_parser_attach_syntax_extension(parser, create_tasklist_extension());
cmark_node *document;

S_parser_feed(parser, (const unsigned char *)buffer, len, true);
Expand Down
34 changes: 34 additions & 0 deletions Sources/cmark/cmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
#include "houdini.h"
#include "cmark-gfm.h"
#include "buffer.h"
// Required for GRM cmark function
#include "autolink.h"
#include "strikethrough.h"
#include "table.h"
#include "tagfilter.h"
#include "tasklist.h"
#include "parser.h"

cmark_node_type CMARK_NODE_LAST_BLOCK = CMARK_NODE_FOOTNOTE_DEFINITION;
cmark_node_type CMARK_NODE_LAST_INLINE = CMARK_NODE_FOOTNOTE_REFERENCE;
Expand Down Expand Up @@ -53,3 +60,30 @@ char *cmark_markdown_to_html(const char *text, size_t len, int options) {

return result;
}

char *cmark_gfm_markdown_to_html(const char *text, size_t len, int options) {
cmark_node *doc = NULL;
cmark_parser *parser = NULL;
char *result;

// Create a new parser we control
parser = cmark_parser_new_with_mem(options, cmark_get_arena_mem_allocator());
// Manually register the extensions
cmark_parser_attach_syntax_extension(parser, create_autolink_extension());
cmark_parser_attach_syntax_extension(parser, create_strikethrough_extension());
cmark_parser_attach_syntax_extension(parser, create_table_extension());
cmark_parser_attach_syntax_extension(parser, create_tagfilter_extension());
cmark_parser_attach_syntax_extension(parser, create_tasklist_extension());

cmark_parser_feed(parser, text, len);
doc = cmark_parser_finish(parser);

cmark_mem *mem = cmark_get_default_mem_allocator();
result = cmark_render_html_with_mem(doc, options, parser->syntax_extensions, mem);
cmark_parser_free(parser);
cmark_node_free(doc);
cmark_release_plugins();

// This is not freed - it's up to the caller to release the memory
return result;
}
1 change: 1 addition & 0 deletions Sources/cmark/include/cmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern "C" {
*/
CMARK_GFM_EXPORT
char *cmark_markdown_to_html(const char *text, size_t len, int options);
char *cmark_gfm_markdown_to_html(const char *text, size_t len, int options);

/** ## Node Structure
*/
Expand Down

0 comments on commit e97450a

Please sign in to comment.