コード例 #1
0
ファイル: hoedown_html_patch.c プロジェクト: Bluelich/macdown
// rndr_blockcode from HEAD. The "language-" prefix in class in needed to make
// the HTML compatible with Prism.
void hoedown_patch_render_blockcode(
    hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_buffer *lang,
    const hoedown_renderer_data *data)
{
	if (ob->size) hoedown_buffer_putc(ob, '\n');

	if (lang) {
        hoedown_html_renderer_state_extra *extra =
            ((hoedown_html_renderer_state *)data->opaque)->opaque;
        hoedown_buffer *mapped = NULL;
        if (extra->language_addition)
            mapped = extra->language_addition(lang, extra->owner);
		HOEDOWN_BUFPUTSL(ob, "<pre><code class=\"language-");
        if (mapped)
        {
            hoedown_escape_html(ob, mapped->data, mapped->size, 0);
            hoedown_buffer_free(mapped);
        }
        else
        {
            hoedown_escape_html(ob, lang->data, lang->size, 0);
        }
		HOEDOWN_BUFPUTSL(ob, "\">");
	} else {
		HOEDOWN_BUFPUTSL(ob, "<pre><code>");
	}

	if (text)
		hoedown_escape_html(ob, text->data, text->size, 0);

	HOEDOWN_BUFPUTSL(ob, "</code></pre>\n");
}
コード例 #2
0
// rndr_blockcode from HEAD. The "language-" prefix in class in needed to make
// the HTML compatible with Prism.
void hoedown_patch_render_blockcode(
    hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_buffer *lang,
    const hoedown_renderer_data *data)
{
	if (ob->size) hoedown_buffer_putc(ob, '\n');

    hoedown_html_renderer_state *state = data->opaque;

    hoedown_buffer *front = NULL;
    hoedown_buffer *back = NULL;
    if (lang && USE_BLOCKCODE_INFORMATION(state))
    {
        front = hoedown_buffer_new(lang->size);
        back = hoedown_buffer_new(lang->size);

        hoedown_buffer *current = front;
        for (size_t i = 0; i < lang->size; i++)
        {
            uint8_t c = lang->data[i];
            if (current == front && c == ':')
                current = back;
            else
                hoedown_buffer_putc(current, c);
        }
        lang = front;
    }


    HOEDOWN_BUFPUTSL(ob, "<pre");
    if (state->flags & HOEDOWN_HTML_BLOCKCODE_LINE_NUMBERS)
        HOEDOWN_BUFPUTSL(ob, " class=\"line-numbers\"");
    if (back && back->size)
    {
        HOEDOWN_BUFPUTSL(ob, " data-information=\"");
        hoedown_buffer_put(ob, back->data, back->size);
        HOEDOWN_BUFPUTSL(ob, "\"");
    }
    HOEDOWN_BUFPUTSL(ob, "><code class=\"language-");
    if (lang && lang->size)
        hoedown_escape_html(ob, lang->data, lang->size, 0);
    else
        HOEDOWN_BUFPUTSL(ob, "none");
    HOEDOWN_BUFPUTSL(ob, "\">");

	if (text)
    {
        // Remove last newline to prevent prism from adding a blank line at the
        // end of code blocks.
        size_t size = text->size;
        if (size > 0 && text->data[size - 1] == '\n')
            size--;
        hoedown_escape_html(ob, text->data, size, 0);
    }

	HOEDOWN_BUFPUTSL(ob, "</code></pre>\n");

    hoedown_buffer_free(front);
    hoedown_buffer_free(back);
}
コード例 #3
0
    static NAN_METHOD(Do) {
      NanScope();
      EscapeHTML* obj = Unwrap<EscapeHTML>(args.Holder());
      hoedown_buffer* ob = obj->ob;
      NanUtf8String input (args[0]);

      if (ob->asize > obj->maxSize) {
        free(ob->data);
        ob->data = (uint8_t*) malloc(obj->minSize);
        ob->asize = obj->minSize;
      }
      ob->size = 0;

      hoedown_escape_html(ob, (uint8_t*)*input, input.length(), obj->secure);
      NanReturnValue(NanNew<String>((char*)ob->data, ob->size));
    }
コード例 #4
0
ファイル: html.c プロジェクト: Anomareh/Hoep
static inline void escape_html(hoedown_buffer *ob, const uint8_t *source, size_t length)
{
	hoedown_escape_html(ob, source, length, 0);
}