Optional highlight support
This commit is contained in:
parent
2e9301b116
commit
0bb213e183
3 changed files with 24 additions and 3 deletions
15
html/html.c
15
html/html.c
|
@ -231,6 +231,19 @@ rndr_underline(struct buf *ob, const struct buf *text, void *opaque)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
rndr_highlight(struct buf *ob, const struct buf *text, void *opaque)
|
||||
{
|
||||
if (!text || !text->size)
|
||||
return 0;
|
||||
|
||||
BUFPUTSL(ob, "<mark>");
|
||||
bufput(ob, text->data, text->size);
|
||||
BUFPUTSL(ob, "</mark>");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
rndr_linebreak(struct buf *ob, void *opaque)
|
||||
{
|
||||
|
@ -637,6 +650,7 @@ sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *optio
|
|||
rndr_double_emphasis,
|
||||
rndr_emphasis,
|
||||
rndr_underline,
|
||||
rndr_highlight,
|
||||
NULL,
|
||||
NULL,
|
||||
toc_link,
|
||||
|
@ -682,6 +696,7 @@ sdhtml_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options,
|
|||
rndr_double_emphasis,
|
||||
rndr_emphasis,
|
||||
rndr_underline,
|
||||
rndr_highlight,
|
||||
rndr_image,
|
||||
rndr_linebreak,
|
||||
rndr_link,
|
||||
|
|
|
@ -634,6 +634,8 @@ parse_emph2(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t size
|
|||
|
||||
if (c == '~')
|
||||
r = rndr->cb.strikethrough(ob, work, rndr->opaque);
|
||||
else if (c == '=')
|
||||
r = rndr->cb.highlight(ob, work, rndr->opaque);
|
||||
else
|
||||
r = rndr->cb.double_emphasis(ob, work, rndr->opaque);
|
||||
|
||||
|
@ -702,7 +704,7 @@ char_emphasis(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t of
|
|||
if (size > 2 && data[1] != c) {
|
||||
/* whitespace cannot follow an opening emphasis;
|
||||
* strikethrough only takes two characters '~~' */
|
||||
if (c == '~' || _isspace(data[1]) || (ret = parse_emph1(ob, rndr, data + 1, size - 1, c)) == 0)
|
||||
if (c == '~' || c == '=' || _isspace(data[1]) || (ret = parse_emph1(ob, rndr, data + 1, size - 1, c)) == 0)
|
||||
return 0;
|
||||
|
||||
return ret + 1;
|
||||
|
@ -716,7 +718,7 @@ char_emphasis(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t of
|
|||
}
|
||||
|
||||
if (size > 4 && data[1] == c && data[2] == c && data[3] != c) {
|
||||
if (c == '~' || _isspace(data[3]) || (ret = parse_emph3(ob, rndr, data + 3, size - 3, c)) == 0)
|
||||
if (c == '~' || c == '=' || _isspace(data[3]) || (ret = parse_emph3(ob, rndr, data + 3, size - 3, c)) == 0)
|
||||
return 0;
|
||||
|
||||
return ret + 3;
|
||||
|
@ -2703,6 +2705,8 @@ sd_markdown_new(
|
|||
md->active_char['_'] = MD_CHAR_EMPHASIS;
|
||||
if (extensions & MKDEXT_STRIKETHROUGH)
|
||||
md->active_char['~'] = MD_CHAR_EMPHASIS;
|
||||
if (extensions & MKDEXT_HIGHLIGHT)
|
||||
md->active_char['='] = MD_CHAR_EMPHASIS;
|
||||
}
|
||||
|
||||
if (md->cb.codespan)
|
||||
|
|
|
@ -61,7 +61,8 @@ enum mkd_extensions {
|
|||
MKDEXT_SUPERSCRIPT = (1 << 7),
|
||||
MKDEXT_LAX_SPACING = (1 << 8),
|
||||
MKDEXT_DISABLE_INDENTED_CODE = (1 << 9),
|
||||
MKDEXT_FOOTNOTES = (1 << 10),
|
||||
MKDEXT_HIGHLIGHT = (1 << 10),
|
||||
MKDEXT_FOOTNOTES = (1 << 11)
|
||||
};
|
||||
|
||||
/* sd_callbacks - functions for rendering parsed data */
|
||||
|
@ -87,6 +88,7 @@ struct sd_callbacks {
|
|||
int (*double_emphasis)(struct buf *ob, const struct buf *text, void *opaque);
|
||||
int (*emphasis)(struct buf *ob, const struct buf *text, void *opaque);
|
||||
int (*underline)(struct buf *ob, const struct buf *text, void *opaque);
|
||||
int (*highlight)(struct buf *ob, const struct buf *text, void *opaque);
|
||||
int (*image)(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque);
|
||||
int (*linebreak)(struct buf *ob, void *opaque);
|
||||
int (*link)(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque);
|
||||
|
|
Loading…
Reference in a new issue