|
|
|
@ -73,6 +73,11 @@ struct zet_mtime {
|
|
|
|
|
int mtime;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct zet_renderopt {
|
|
|
|
|
struct html_renderopt html;
|
|
|
|
|
const char *query;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum page {
|
|
|
|
|
PAGE_NEW,
|
|
|
|
|
PAGE_ALL,
|
|
|
|
@ -618,9 +623,9 @@ static void parse_req_uri(char *path, char **hashp, char **queryp) {
|
|
|
|
|
static int
|
|
|
|
|
md_rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque)
|
|
|
|
|
{
|
|
|
|
|
struct html_renderopt *options = opaque;
|
|
|
|
|
struct zet_renderopt *options = opaque;
|
|
|
|
|
|
|
|
|
|
if (link != NULL && (options->flags & HTML_SAFELINK) != 0 && !sd_autolink_issafe(link->data, link->size))
|
|
|
|
|
if (link != NULL && (options->html.flags & HTML_SAFELINK) != 0 && !sd_autolink_issafe(link->data, link->size))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
BUFPUTSL(ob, "<a href=\"");
|
|
|
|
@ -636,6 +641,11 @@ md_rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, co
|
|
|
|
|
} else if (!strncmp((char *)link->data, "§", sigil_size)) {
|
|
|
|
|
houdini_escape_href(ob, link->data + sigil_size,
|
|
|
|
|
link->size - sigil_size);
|
|
|
|
|
const char *query = options->query;
|
|
|
|
|
if (query != NULL) {
|
|
|
|
|
bufputc(ob, '?');
|
|
|
|
|
bufputs(ob, query);
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
houdini_escape_href(ob, link->data, link->size);
|
|
|
|
|
}
|
|
|
|
@ -645,9 +655,9 @@ md_rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, co
|
|
|
|
|
houdini_escape_html0(ob, title->data, title->size, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options->link_attributes) {
|
|
|
|
|
if (options->html.link_attributes) {
|
|
|
|
|
bufputc(ob, '\"');
|
|
|
|
|
options->link_attributes(ob, link, opaque);
|
|
|
|
|
options->html.link_attributes(ob, link, opaque);
|
|
|
|
|
bufputc(ob, '>');
|
|
|
|
|
} else {
|
|
|
|
|
BUFPUTSL(ob, "\">");
|
|
|
|
@ -661,7 +671,7 @@ md_rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, co
|
|
|
|
|
static int
|
|
|
|
|
md_rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
|
|
|
|
|
{
|
|
|
|
|
struct html_renderopt *options = opaque;
|
|
|
|
|
struct zet_renderopt *options = opaque;
|
|
|
|
|
if (!link || !link->size) return 0;
|
|
|
|
|
|
|
|
|
|
BUFPUTSL(ob, "<img src=\"");
|
|
|
|
@ -708,12 +718,12 @@ static void put_link_truncated(struct buf *ob, const struct buf *link, int max_l
|
|
|
|
|
static int
|
|
|
|
|
md_rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque)
|
|
|
|
|
{
|
|
|
|
|
struct html_renderopt *options = opaque;
|
|
|
|
|
struct zet_renderopt *options = opaque;
|
|
|
|
|
|
|
|
|
|
if (!link || !link->size)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if ((options->flags & HTML_SAFELINK) != 0 &&
|
|
|
|
|
if ((options->html.flags & HTML_SAFELINK) != 0 &&
|
|
|
|
|
!sd_autolink_issafe(link->data, link->size) &&
|
|
|
|
|
type != MKDA_EMAIL)
|
|
|
|
|
return 0;
|
|
|
|
@ -743,9 +753,9 @@ md_rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options->link_attributes) {
|
|
|
|
|
if (options->html.link_attributes) {
|
|
|
|
|
bufputc(ob, '\"');
|
|
|
|
|
options->link_attributes(ob, link, opaque);
|
|
|
|
|
options->html.link_attributes(ob, link, opaque);
|
|
|
|
|
bufputc(ob, '>');
|
|
|
|
|
} else {
|
|
|
|
|
BUFPUTSL(ob, "\">");
|
|
|
|
@ -844,10 +854,11 @@ static int dpi_serve_zet(int fd, char *path) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct sd_callbacks callbacks;
|
|
|
|
|
struct html_renderopt options;
|
|
|
|
|
struct zet_renderopt options;
|
|
|
|
|
struct sd_markdown *markdown;
|
|
|
|
|
struct buf *ob = bufnew(128);
|
|
|
|
|
sdhtml_renderer(&callbacks, &options, HTML_ESCAPE);
|
|
|
|
|
sdhtml_renderer(&callbacks, &options.html, HTML_ESCAPE);
|
|
|
|
|
options.query = query;
|
|
|
|
|
callbacks.link = md_rndr_link;
|
|
|
|
|
callbacks.image = md_rndr_image;
|
|
|
|
|
callbacks.autolink = md_rndr_autolink;
|
|
|
|
@ -894,7 +905,8 @@ static int dpi_serve_zet(int fd, char *path) {
|
|
|
|
|
result_title[sizeof(result_title)-1] = '\0';
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
rc = dprintf(fd, "<li><a href=\"%s\">", result_id);
|
|
|
|
|
rc = dprintf(fd, "<li><a href=\"%s%s%s\">", result_id,
|
|
|
|
|
query ? "?" : "", query ? query : "");
|
|
|
|
|
rc |= write_html(fd, result_title, strlen(result_title));
|
|
|
|
|
rc |= write_buf(fd, "</a></li>");
|
|
|
|
|
} while (1);
|
|
|
|
|