author | Olivier Brunel
<jjk@jjacky.com> 2023-07-19 11:47:30 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-07-19 11:47:30 UTC |
parent | e9ff661ff818ee94a4a231958d9b6768dc6882c9 |
src/md4c.c | +36 | -0 |
diff --git a/src/md4c.c b/src/md4c.c index 3677c0e..43d7655 100644 --- a/src/md4c.c +++ b/src/md4c.c @@ -2992,6 +2992,42 @@ md_is_autolink(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end, int* p_missing_mai return FALSE; } +/*********************************************** + *** Helpers for identifying opener/closer *** + ***********************************************/ +enum { + SP_WHITESPACE_OR_PUNCT_BEFORE = 1 << 0, + SP_WHITESPACE_OR_PUNCT_AFTER = 1 << 1, + SP_BEGINS_LINE = 1 << 2, + SP_ENDS_LINE = 1 << 3, +}; + +static inline unsigned +md_get_potential_flags(MD_CTX *ctx, OFF off, OFF tmp, OFF line_beg, OFF line_end) +{ + unsigned sp, flags; + + sp = flags = 0; + + if(ISUNICODEWHITESPACEBEFORE(off) || ISUNICODEPUNCTBEFORE(off)) + sp |= SP_WHITESPACE_OR_PUNCT_BEFORE; + if(ISUNICODEWHITESPACE(tmp) || ISUNICODEPUNCT(tmp)) + sp |= SP_WHITESPACE_OR_PUNCT_AFTER; + if(off == line_beg) + sp |= SP_BEGINS_LINE; + if(tmp == line_end) + sp |= SP_ENDS_LINE; + + if (sp) { + if(!(sp & (SP_ENDS_LINE | SP_WHITESPACE_OR_PUNCT_AFTER))) + flags |= MD_MARK_POTENTIAL_OPENER; + if(!(sp & (SP_BEGINS_LINE | SP_WHITESPACE_OR_PUNCT_BEFORE))) + flags |= MD_MARK_POTENTIAL_CLOSER; + } + + return flags; +} + static int md_collect_marks(MD_CTX* ctx, const MD_LINE* lines, int n_lines, int table_mode) {