diff options
Diffstat (limited to 'src/3rdparty/md4c/md4c.h')
-rw-r--r-- | src/3rdparty/md4c/md4c.h | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/src/3rdparty/md4c/md4c.h b/src/3rdparty/md4c/md4c.h index c2c4311f50..8d6be1cb46 100644 --- a/src/3rdparty/md4c/md4c.h +++ b/src/3rdparty/md4c/md4c.h @@ -2,7 +2,7 @@ * MD4C: Markdown parser for C * (http://github.com/mity/md4c) * - * Copyright (c) 2016-2020 Martin Mitas + * Copyright (c) 2016-2024 Martin Mitáš * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -23,15 +23,15 @@ * IN THE SOFTWARE. */ -#ifndef MD4C_MARKDOWN_H -#define MD4C_MARKDOWN_H +#ifndef MD4C_H +#define MD4C_H #ifdef __cplusplus extern "C" { #endif #if defined MD4C_USE_UTF16 - /* Magic to support UTF-16. Not that in order to use it, you have to define + /* Magic to support UTF-16. Note that in order to use it, you have to define * the macro MD4C_USE_UTF16 both when building MD4C as well as when * including this header in your code. */ #ifdef _WIN32 @@ -91,7 +91,8 @@ typedef enum MD_BLOCKTYPE { MD_BLOCK_P, /* <table>...</table> and its contents. - * Detail: Structure MD_BLOCK_TD_DETAIL (used with MD_BLOCK_TH and MD_BLOCK_TD) + * Detail: Structure MD_BLOCK_TABLE_DETAIL (for MD_BLOCK_TABLE), + * structure MD_BLOCK_TD_DETAIL (for MD_BLOCK_TH and MD_BLOCK_TD) * Note all of these are used only if extension MD_FLAG_TABLES is enabled. */ MD_BLOCK_TABLE, MD_BLOCK_THEAD, @@ -119,7 +120,7 @@ typedef enum MD_SPANTYPE { * Detail: Structure MD_SPAN_IMG_DETAIL. * Note: Image text can contain nested spans and even nested images. * If rendered into ALT attribute of HTML <IMG> tag, it's responsibility - * of the renderer to deal with it. + * of the parser to deal with it. */ MD_SPAN_IMG, @@ -171,7 +172,7 @@ typedef enum MD_TEXTTYPE { * (c) Hexadecimal entity, e.g. ካ * * As MD4C is mostly encoding agnostic, application gets the verbatim - * entity text into the MD_RENDERER::text_callback(). */ + * entity text into the MD_PARSER::text_callback(). */ MD_TEXT_ENTITY, /* Text in a code block (inside MD_BLOCK_CODE) or inlined code (`code`). @@ -206,8 +207,13 @@ typedef enum MD_ALIGN { * propagated within various detailed structures, but which still may contain * string portions of different types like e.g. entities. * - * So, for example, lets consider an image has a title attribute string - * set to "foo " bar". (Note the string size is 14.) + * So, for example, lets consider this image: + * + * ![image alt text](http://example.org/image.png 'foo " bar') + * + * The image alt text is propagated as a normal text via the MD_PARSER::text() + * callback. However, the image title ('foo " bar') is propagated as + * MD_ATTRIBUTE in MD_SPAN_IMG_DETAIL::title. * * Then the attribute MD_SPAN_IMG_DETAIL::title shall provide the following: * -- [0]: "foo " (substr_types[0] == MD_TEXT_NORMAL; substr_offsets[0] == 0) @@ -215,10 +221,12 @@ typedef enum MD_ALIGN { * -- [2]: " bar" (substr_types[2] == MD_TEXT_NORMAL; substr_offsets[2] == 10) * -- [3]: (n/a) (n/a ; substr_offsets[3] == 14) * - * Note that these conditions are guaranteed: + * Note that these invariants are always guaranteed: * -- substr_offsets[0] == 0 * -- substr_offsets[LAST+1] == size - * -- Only MD_TEXT_NORMAL, MD_TEXT_ENTITY, MD_TEXT_NULLCHAR substrings can appear. + * -- Currently, only MD_TEXT_NORMAL, MD_TEXT_ENTITY, MD_TEXT_NULLCHAR + * substrings can appear. This could change only of the specification + * changes. */ typedef struct MD_ATTRIBUTE { const MD_CHAR* text; @@ -260,6 +268,13 @@ typedef struct MD_BLOCK_CODE_DETAIL { MD_CHAR fence_char; /* The character used for fenced code block; or zero for indented code block. */ } MD_BLOCK_CODE_DETAIL; +/* Detailed info for MD_BLOCK_TABLE. */ +typedef struct MD_BLOCK_TABLE_DETAIL { + unsigned col_count; /* Count of columns in the table. */ + unsigned head_row_count; /* Count of rows in the table header (currently always 1) */ + unsigned body_row_count; /* Count of rows in the table body */ +} MD_BLOCK_TABLE_DETAIL; + /* Detailed info for MD_BLOCK_TH and MD_BLOCK_TD. */ typedef struct MD_BLOCK_TD_DETAIL { MD_ALIGN align; @@ -269,6 +284,7 @@ typedef struct MD_BLOCK_TD_DETAIL { typedef struct MD_SPAN_A_DETAIL { MD_ATTRIBUTE href; MD_ATTRIBUTE title; + int is_autolink; /* nonzero if this is an autolink */ } MD_SPAN_A_DETAIL; /* Detailed info for MD_SPAN_IMG. */ @@ -284,7 +300,7 @@ typedef struct MD_SPAN_WIKILINK { /* Flags specifying extensions/deviations from CommonMark specification. * - * By default (when MD_RENDERER::flags == 0), we follow CommonMark specification. + * By default (when MD_PARSER::flags == 0), we follow CommonMark specification. * The following flags may allow some extensions or deviations from it. */ #define MD_FLAG_COLLAPSEWHITESPACE 0x0001 /* In MD_TEXT_NORMAL, collapse non-trivial whitespace into single ' ' */ @@ -301,6 +317,7 @@ typedef struct MD_SPAN_WIKILINK { #define MD_FLAG_LATEXMATHSPANS 0x1000 /* Enable $ and $$ containing LaTeX equations. */ #define MD_FLAG_WIKILINKS 0x2000 /* Enable wiki links extension. */ #define MD_FLAG_UNDERLINE 0x4000 /* Enable underline extension (and disables '_' for normal emphasis). */ +#define MD_FLAG_HARD_SOFT_BREAKS 0x8000 /* Force all soft breaks to act as hard breaks. */ #define MD_FLAG_PERMISSIVEAUTOLINKS (MD_FLAG_PERMISSIVEEMAILAUTOLINKS | MD_FLAG_PERMISSIVEURLAUTOLINKS | MD_FLAG_PERMISSIVEWWWAUTOLINKS) #define MD_FLAG_NOHTML (MD_FLAG_NOHTMLBLOCKS | MD_FLAG_NOHTMLSPANS) @@ -317,7 +334,7 @@ typedef struct MD_SPAN_WIKILINK { #define MD_DIALECT_COMMONMARK 0 #define MD_DIALECT_GITHUB (MD_FLAG_PERMISSIVEAUTOLINKS | MD_FLAG_TABLES | MD_FLAG_STRIKETHROUGH | MD_FLAG_TASKLISTS) -/* Renderer structure. +/* Parser structure. */ typedef struct MD_PARSER { /* Reserved. Set to zero. @@ -338,9 +355,10 @@ typedef struct MD_PARSER { * * Note any strings provided to the callbacks as their arguments or as * members of any detail structure are generally not zero-terminated. - * Application has take the respective size information into account. + * Application has to take the respective size information into account. * - * Callbacks may abort further parsing of the document by returning non-zero. + * Any rendering callback may abort further parsing of the document by + * returning non-zero. */ int (*enter_block)(MD_BLOCKTYPE /*type*/, void* /*detail*/, void* /*userdata*/); int (*leave_block)(MD_BLOCKTYPE /*type*/, void* /*detail*/, void* /*userdata*/); @@ -365,18 +383,19 @@ typedef struct MD_PARSER { } MD_PARSER; -/* For backward compatibility. Do not use in new code. */ +/* For backward compatibility. Do not use in new code. + */ typedef MD_PARSER MD_RENDERER; /* Parse the Markdown document stored in the string 'text' of size 'size'. - * The renderer provides callbacks to be called during the parsing so the + * The parser provides callbacks to be called during the parsing so the * caller can render the document on the screen or convert the Markdown * to another format. * * Zero is returned on success. If a runtime error occurs (e.g. a memory * fails), -1 is returned. If the processing is aborted due any callback - * returning non-zero, md_parse() the return value of the callback is returned. + * returning non-zero, the return value of the callback is returned. */ int md_parse(const MD_CHAR* text, MD_SIZE size, const MD_PARSER* parser, void* userdata); @@ -385,4 +404,4 @@ int md_parse(const MD_CHAR* text, MD_SIZE size, const MD_PARSER* parser, void* u } /* extern "C" { */ #endif -#endif /* MD4C_MARKDOWN_H */ +#endif /* MD4C_H */ |