Skip to content

Commit

Permalink
Adding options to prettify instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Rosenberg committed Jan 25, 2013
1 parent fa720d9 commit d3bc743
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ext/redcarpet/html.c
Expand Up @@ -121,10 +121,14 @@ rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, v
if (ob->size) bufputc(ob, '\n');

if (lang && lang->size) {
size_t i;
BUFPUTSL(ob, "<pre><code class=\"prettyprint");
size_t i, cls;
BUFPUTSL(ob, "<pre><code class=\"");
if (render_flags & HTML_PRETTIFY) {
BUFPUTSL(ob, "prettyprint");
cls++;
}

for (i = 0; i < lang->size; ++i) {
for (i = 0, cls = 0; i < lang->size; ++i, ++cls) {
while (i < lang->size && isspace(lang->data[i]))
i++;

Expand All @@ -136,14 +140,16 @@ rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, v
if (lang->data[org] == '.')
org++;

bufputc(ob, ' ');
if (cls) bufputc(ob, ' ');
escape_html(ob, lang->data + org, i - org);
}
}

BUFPUTSL(ob, "\">");
} else
} else if (render_flags & HTML_PRETTIFY)
BUFPUTSL(ob, "<pre><code class=\"prettyprint\">");
} else
BUFPUTSL(ob, "<pre><code>");

if (text)
escape_html(ob, text->data, text->size);
Expand Down
1 change: 1 addition & 0 deletions ext/redcarpet/html.h
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions ext/redcarpet/rc_render.c
Expand Up @@ -386,6 +386,10 @@ static VALUE rb_redcarpet_html_init(int argc, VALUE *argv, VALUE self)
if (rb_hash_aref(hash, CSTR2SYM("no_links")) == Qtrue)
render_flags |= HTML_SKIP_LINKS;

/* prettify */
if (rb_hash_aref(hash, CSTR2SYM("prettify")) == Qtrue)
render_flags |= HTML_PRETTIFY;

/* filter_style */
if (rb_hash_aref(hash, CSTR2SYM("no_styles")) == Qtrue)
render_flags |= HTML_SKIP_STYLE;
Expand Down

0 comments on commit d3bc743

Please sign in to comment.