示例#1
0
static void rndr_blockcode_github(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque) {
    if (ob->size)
        bufputc(ob, '\n');

    if (!text || !text->size) {
        BUFPUTSL(ob, "<pre><code></code></pre>");
        return;
    }

    if (lang && lang->size) {
        size_t i = 0, lang_size;
        const char *lang_name = NULL;

        while (i < lang->size && !isspace(lang->data[i]))
            i++;

        if (lang->data[0] == '.') {
            lang_name = (char const *) (lang->data + 1);
            lang_size = i - 1;
        } else {
            lang_name = (char const *) lang->data;
            lang_size = i;
        }

        BUFPUTSL(ob, "<pre lang=\"");
        houdini_escape_html0(ob, (uint8_t const *) lang_name, lang_size, 0);
        BUFPUTSL(ob, "\"><code>");

    } else {
        BUFPUTSL(ob, "<pre><code>");
    }

    houdini_escape_html0(ob, text->data, text->size, 0);
    BUFPUTSL(ob, "</code></pre>\n");
}
示例#2
0
文件: html.c 项目: lowks/cmark.ex
static void escape_html(cmark_strbuf *dest, const unsigned char *source, int length)
{
	if (length < 0)
		length = strlen((char *)source);

	houdini_escape_html0(dest, source, (size_t)length, 0);
}
示例#3
0
/**
 * HTML methods
 */
static VALUE rb_eu_escape_html(int argc, VALUE *argv, VALUE self)
{
	VALUE rb_out_buf, str, rb_secure;
	struct buf *out_buf;
	int secure = g_html_secure;

	if (rb_scan_args(argc, argv, "11", &str, &rb_secure) == 2) {
		if (rb_secure == Qfalse) {
			secure = 0;
		}
	}

	Check_Type(str, T_STRING);
	out_buf = bufnew(128);

	houdini_escape_html0(out_buf, (uint8_t *)RSTRING_PTR(str), RSTRING_LEN(str), secure);

	rb_out_buf = rb_str_new((char *)out_buf->data, out_buf->size);
	bufrelease(out_buf);

#ifdef HAVE_RUBY_ENCODING_H
	rb_enc_copy(rb_out_buf, str);
#endif

	return rb_out_buf;
}
示例#4
0
static PyObject *
plissken_escape_html(PyObject *self, PyObject *args)
{
	const char *str;
    PyObject *py_secure;
	gh_buf buf = GH_BUF_INIT;
    int secure = g_html_secure;

    if (PyArg_ParseTuple(args, "s|O", &str,&py_secure)) 
    {
        if(!PyObject_IsTrue(py_secure))
        {
            secure=0;
        }
        
    } else {
        return NULL;
    }

    if (houdini_escape_html0(&buf, (const uint8_t *)str, sizeof(str),secure)) {
		PyObject *result = Py_BuildValue("s",buf.ptr);
		return result;
	}

	return Py_BuildValue("s",str);
}
示例#5
0
static VALUE rb_eu_escape_html_as_html_safe(VALUE self, VALUE str)
{
	VALUE result;
	int secure = g_html_secure;
	gh_buf buf = GH_BUF_INIT;

	Check_Type(str, T_STRING);
	check_utf8_encoding(str);

	if (houdini_escape_html0(&buf, (const uint8_t *)RSTRING_PTR(str), RSTRING_LEN(str), secure)) {
		result = new_html_safe_string(buf.ptr, buf.size);
		gh_buf_free(&buf);
	} else {
		result = new_html_safe_string(RSTRING_PTR(str), RSTRING_LEN(str));
	}

	rb_ivar_set(result, ID_at_html_safe, Qtrue);

	return result;
}
示例#6
0
static VALUE rb_eu_escape_html(int argc, VALUE *argv, VALUE self)
{
	VALUE str, rb_secure;
	gh_buf buf = GH_BUF_INIT;
	int secure = g_html_secure;

	if (rb_scan_args(argc, argv, "11", &str, &rb_secure) == 2) {
		if (rb_secure == Qfalse) {
			secure = 0;
		}
	}

	Check_Type(str, T_STRING);
	check_utf8_encoding(str);

	if (houdini_escape_html0(&buf, (const uint8_t *)RSTRING_PTR(str), RSTRING_LEN(str), secure)) {
		VALUE result = eu_new_str(buf.ptr, buf.size);
		gh_buf_free(&buf);
		return result;
	}

	return str;
}
示例#7
0
static inline void escape_html(struct buf *ob, const uint8_t *source, size_t length)
{
	houdini_escape_html0(ob, source, length, 0);
}
示例#8
0
void
houdini_escape_html(struct buf *ob, const uint8_t *src, size_t size)
{
	houdini_escape_html0(ob, src, size, 1);
}
示例#9
0
static void escape_xml(cmark_strbuf *dest, const unsigned char *source,
                       bufsize_t length) {
  houdini_escape_html0(dest, source, length, 0);
}
int
houdini_escape_html(cmark_strbuf *ob, const uint8_t *src, size_t size)
{
	return houdini_escape_html0(ob, src, size, 1);
}