Adding a prettyprint class for google-code-prettify
This commit is contained in:
parent
d32be1c697
commit
bb3a9d92c3
2 changed files with 20 additions and 5 deletions
24
html/html.c
24
html/html.c
|
@ -118,13 +118,20 @@ rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, vo
|
|||
static void
|
||||
rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque)
|
||||
{
|
||||
struct html_renderopt *options = opaque;
|
||||
|
||||
if (ob->size) bufputc(ob, '\n');
|
||||
|
||||
if (lang && lang->size) {
|
||||
size_t i, cls;
|
||||
BUFPUTSL(ob, "<pre><code class=\"");
|
||||
size_t i, cls = 0;
|
||||
if (options->flags & HTML_PRETTIFY) {
|
||||
BUFPUTSL(ob, "<pre><code class=\"prettyprint");
|
||||
cls++;
|
||||
} else {
|
||||
BUFPUTSL(ob, "<pre><code class=\"");
|
||||
}
|
||||
|
||||
for (i = 0, cls = 0; i < lang->size; ++i, ++cls) {
|
||||
for (i = 0; i < lang->size; ++i, ++cls) {
|
||||
while (i < lang->size && isspace(lang->data[i]))
|
||||
i++;
|
||||
|
||||
|
@ -142,8 +149,11 @@ rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, v
|
|||
}
|
||||
|
||||
BUFPUTSL(ob, "\">");
|
||||
} else
|
||||
} else if (options->flags & HTML_PRETTIFY) {
|
||||
BUFPUTSL(ob, "<pre><code class=\"prettyprint\">");
|
||||
} else {
|
||||
BUFPUTSL(ob, "<pre><code>");
|
||||
}
|
||||
|
||||
if (text)
|
||||
escape_html(ob, text->data, text->size);
|
||||
|
@ -163,7 +173,11 @@ rndr_blockquote(struct buf *ob, const struct buf *text, void *opaque)
|
|||
static int
|
||||
rndr_codespan(struct buf *ob, const struct buf *text, void *opaque)
|
||||
{
|
||||
BUFPUTSL(ob, "<code>");
|
||||
struct html_renderopt *options = opaque;
|
||||
if (options->flags & HTML_PRETTIFY)
|
||||
BUFPUTSL(ob, "<code class=\"prettyprint\">");
|
||||
else
|
||||
BUFPUTSL(ob, "<code>");
|
||||
if (text) escape_html(ob, text->data, text->size);
|
||||
BUFPUTSL(ob, "</code>");
|
||||
return 1;
|
||||
|
|
|
@ -49,6 +49,7 @@ typedef enum {
|
|||
HTML_HARD_WRAP = (1 << 7),
|
||||
HTML_USE_XHTML = (1 << 8),
|
||||
HTML_ESCAPE = (1 << 9),
|
||||
HTML_PRETTIFY = (1 << 10),
|
||||
} html_render_mode;
|
||||
|
||||
typedef enum {
|
||||
|
|
Loading…
Reference in a new issue