static int rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque) { struct html_renderopt *options = opaque; /* HTML_ESCAPE overrides SKIP_HTML, SKIP_STYLE, SKIP_LINKS and SKIP_IMAGES It doesn't see if there are any valid tags, just escape all of them. */ if((options->flags & HTML_ESCAPE) != 0) { escape_html(ob, text->data, text->size); return 1; } if ((options->flags & HTML_SKIP_HTML) != 0) return 1; if ((options->flags & HTML_SKIP_STYLE) != 0 && sdhtml_is_tag(text->data, text->size, "style")) return 1; if ((options->flags & HTML_SKIP_LINKS) != 0 && sdhtml_is_tag(text->data, text->size, "a")) return 1; if ((options->flags & HTML_SKIP_IMAGES) != 0 && sdhtml_is_tag(text->data, text->size, "img")) return 1; bufput(ob, text->data, text->size); return 1; }
static void rndr_raw_block(struct buf *ob, const struct buf *text, void *opaque) { size_t org, size; struct html_renderopt *options = opaque; if (!text) return; size = text->size; while (size > 0 && text->data[size - 1] == '\n') size--; for (org = 0; org < size && text->data[org] == '\n'; ++org) if (org >= size) return; /* Remove style tags if the `:no_styles` option is enabled */ if ((options->flags & HTML_SKIP_STYLE) != 0 && sdhtml_is_tag(text->data, size, "style")) return; if (ob->size) bufputc(ob, '\n'); bufput(ob, text->data + org, size - org); bufputc(ob, '\n'); }
static int rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque) { struct html_renderopt *options = opaque; char** whitelist = options->html_element_whitelist; int i, tagtype; /* Items on the whitelist ignore all other flags and just output */ if (((options->flags & HTML_ALLOW_ELEMENT_WHITELIST) != 0) && whitelist) { for (i = 0; whitelist[i]; i++) { tagtype = sdhtml_is_tag(text->data, text->size, whitelist[i]); if (tagtype != HTML_TAG_NONE) { rndr_html_tag(ob, text, opaque, whitelist[i], options->html_attr_whitelist, tagtype); return 1; } } } /* HTML_ESCAPE overrides SKIP_HTML, SKIP_STYLE, SKIP_LINKS and SKIP_IMAGES * It doens't see if there are any valid tags, just escape all of them. */ if((options->flags & HTML_ESCAPE) != 0) { escape_html(ob, text->data, text->size); return 1; } if ((options->flags & HTML_SKIP_HTML) != 0) return 1; if ((options->flags & HTML_SKIP_STYLE) != 0 && sdhtml_is_tag(text->data, text->size, "style")) return 1; if ((options->flags & HTML_SKIP_LINKS) != 0 && sdhtml_is_tag(text->data, text->size, "a")) return 1; if ((options->flags & HTML_SKIP_IMAGES) != 0 && sdhtml_is_tag(text->data, text->size, "img")) return 1; bufput(ob, text->data, text->size); return 1; }
static size_t smartypants_cb__ltag(struct buf *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size) { static const char *skip_tags[] = { "pre", "code", "var", "samp", "kbd", "math", "script", "style" }; static const size_t skip_tags_count = 8; size_t tag, i = 0; while (i < size && text[i] != '>') i++; for (tag = 0; tag < skip_tags_count; ++tag) { if (sdhtml_is_tag(text, size, skip_tags[tag]) == HTML_TAG_OPEN) break; } if (tag < skip_tags_count) { for (;;) { while (i < size && text[i] != '<') i++; if (i == size) break; if (sdhtml_is_tag(text + i, size - i, skip_tags[tag]) == HTML_TAG_CLOSE) break; i++; } while (i < size && text[i] != '>') i++; } bufput(ob, text, i + 1); return i; }