Esempio n. 1
0
static void
rndr_table(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque)
{
    struct renderopt *opt = opaque;
    PyObject *ret = PyObject_CallMethod(
        (PyObject *) opt->self, "rndr_table", "ss",
        bufcstr((struct buf *) header),
        bufcstr((struct buf *) body)
    );
    BLOCK_PROCESS_OUTPUT(ret);
}
Esempio n. 2
0
static void
rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque)
{
    struct renderopt *opt = opaque;
    PyObject *ret = PyObject_CallMethod(
        (PyObject *) opt->self, "block_code", "ss",
        bufcstr((struct buf *) text),
        bufcstr((struct buf *) lang)
    );
    BLOCK_PROCESS_OUTPUT(ret);
}
Esempio n. 3
0
static int
rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque)
{
    struct renderopt *opt = opaque;
    PyObject *ret = PyObject_CallMethod(
        (PyObject *) opt->self, "link", "sss",
        bufcstr((struct buf *) link),
        bufcstr((struct buf *) title),
        bufcstr((struct buf *) content)
    );
    SPAN_PROCESS_OUTPUT(ret);
}
Esempio n. 4
0
static void
rndr_tablecell(struct buf *ob, const struct buf *text, int align, void *opaque)
{
    char *str_align;

    switch (align) {
    case MKD_TABLE_ALIGN_L:
        str_align = "left";
        break;

    case MKD_TABLE_ALIGN_R:
        str_align = "right";
        break;

    case MKD_TABLE_ALIGN_CENTER:
        str_align = "center";
        break;

    default:
        str_align = NULL;
        break;
    }

    struct renderopt *opt = opaque;
    PyObject *ret = PyObject_CallMethod(
        (PyObject *) opt->self, "table_cell", "ss",
        bufcstr((struct buf *) text),
        str_align
    );
    BLOCK_PROCESS_OUTPUT(ret);
}
Esempio n. 5
0
static QString markdown(QString in){
    struct buf *ib, *ob;
    struct sd_callbacks cbs;
    struct html_renderopt opts;
    struct sd_markdown *mkd;

    if(in.size() > 0){
        QByteArray qba = in.toUtf8();
        const char *txt = qba.constData();
        if(NULL == txt) qDebug() << "txt was null!";
        if(0 < qba.size()){
            ib = bufnew(qba.size());
            bufputs(ib,txt);
            ob = bufnew(64);
            sdhtml_renderer(&cbs,&opts,0);
            mkd = sd_markdown_new(0,16,&cbs,&opts);
            sd_markdown_render(ob,ib->data,ib->size,mkd);
            sd_markdown_free(mkd);
            return QString::fromUtf8(bufcstr(ob));
        }
        else
            qDebug() <<"qstrlen was null";
    }
    return "";
}
Esempio n. 6
0
JNIEXPORT jstring JNICALL Java_com_commonsware_cwac_anddown_AndDown_markdownToHtml
  (JNIEnv *env, jobject o, jstring raw) {
	struct buf *ib, *ob;
	int ret;
  jstring result;

	struct sd_callbacks callbacks;
	struct html_renderopt options;
	struct sd_markdown *markdown;

  const char* str;
  str = (*env)->GetStringUTFChars(env, raw, NULL);

	ib = bufnew(INPUT_UNIT);
  bufputs(ib, str);
	ob = bufnew(OUTPUT_UNIT);

  (*env)->ReleaseStringUTFChars(env, raw, str);

	sdhtml_renderer(&callbacks, &options, 0);
	markdown = sd_markdown_new(0, 16, &callbacks, &options);

	sd_markdown_render(ob, ib->data, ib->size, markdown);
	sd_markdown_free(markdown);

  result=(*env)->NewStringUTF(env, bufcstr(ob));

	/* cleanup */
	bufrelease(ib);
	bufrelease(ob);

  return(result);
}
Esempio n. 7
0
static void
rndr_raw_block(struct buf *ob, const struct buf *text, void *opaque)
{
    struct renderopt *opt = opaque;
    PyObject *ret = PyObject_CallMethod(
        (PyObject *) opt->self, "block_html", "s",
        bufcstr((struct buf *) text)
    );
    BLOCK_PROCESS_OUTPUT(ret);
}
Esempio n. 8
0
static int
rndr_superscript(struct buf *ob, const struct buf *text, void *opaque)
{
    struct renderopt *opt = opaque;
    PyObject *ret = PyObject_CallMethod(
        (PyObject *) opt->self, "superscript", "s",
        bufcstr((struct buf *) text)
    );
    SPAN_PROCESS_OUTPUT(ret);
}
Esempio n. 9
0
static void
rndr_list(struct buf *ob, const struct buf *text, int flags, void *opaque)
{
    struct renderopt *opt = opaque;
    PyObject *ret = PyObject_CallMethod(
        (PyObject *) opt->self, "list", "ss",
        bufcstr((struct buf *) text),
        (flags & MKD_LIST_ORDERED ? "ordered" : "unordered")
    );
    BLOCK_PROCESS_OUTPUT(ret);
}
Esempio n. 10
0
static void
rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
{
    struct renderopt *opt = opaque;
    PyObject *ret = PyObject_CallMethod(
        (PyObject *) opt->self, "header", "si",
        bufcstr((struct buf *) text),
        level
    );
    BLOCK_PROCESS_OUTPUT(ret);
}
Esempio n. 11
0
static int
rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque)
{
    struct renderopt *opt = opaque;
    PyObject *ret = PyObject_CallMethod(
        (PyObject *) opt->self, "autolink", "ss",
        bufcstr((struct buf *) link),
        (type == MKDA_NORMAL ? "url" : "email")
    );
    SPAN_PROCESS_OUTPUT(ret);
}
Esempio n. 12
0
char *header_anchor(struct buf *text)
{
	VALUE str = rb_str_new2(bufcstr(text));
	VALUE space_regex = rb_reg_new(" +", 2 /* length */, 0);
	VALUE tags_regex = rb_reg_new("<\\/?[^>]*>", 10, 0);

	VALUE heading = rb_funcall(str, rb_intern("gsub"), 2, space_regex, rb_str_new2("-"));
	heading = rb_funcall(heading, rb_intern("gsub"), 2, tags_regex, rb_str_new2(""));
	heading = rb_funcall(heading, rb_intern("downcase"), 0);

	return StringValueCStr(heading);
}
Esempio n. 13
0
char *header_anchor(const struct buf *buffer)
{
    size_t i = 0, j, k, size = buffer->size;

    char text[size];
    strcpy(text, bufcstr(buffer));

    char raw_string[size];

    /* Strip down the inline HTML markup if needed */
    if (strchr(text, '<') < strchr(text, '>')) {
        char* part = strtok(text, "<>");

        /* Once every two times, the yielded token is the
           content of a HTML tag so we don't need to copy it */
        for (k = 0; part != NULL; k++) {
            if (k == 0)
                strcpy(raw_string, part);
            else if (k % 2 == 0)
                strcat(raw_string, part);

            part = strtok(NULL, "<>");
        }

        size = strlen(raw_string);
    } else {
        strcpy(raw_string, text);
    }

    char* heading = malloc(size * sizeof(char));

    /* Remove leading stripped chars */
    while (STRIPPED_CHAR(raw_string[i])) i++;

    /* Dasherize the string removing extra white spaces
       and stripped chars */
    for (j = 0; i < size; i++, j++) {
        while ((i+1) < size && STRIPPED_CHAR(raw_string[i]) && STRIPPED_CHAR(raw_string[i+1]))
            i++;

        if (STRIPPED_CHAR(raw_string[i]) && i == size - 1)
            break;
        else if (STRIPPED_CHAR(raw_string[i]))
            heading[j] = '-';
        else
            heading[j] = tolower(raw_string[i]);
    }

    heading[j++] = '\0';
    return heading;
}