Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--full-info-string #73

Merged
merged 2 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
C_SOURCES = $(wildcard ext/commonmarker/*.[ch])

update-c-sources: $(C_SOURCES)
update-c-sources: build-upstream $(C_SOURCES)

.PHONY: build-upstream

build-upstream:
cd ext/commonmarker/cmark-upstream && make

ext/commonmarker/%: ext/commonmarker/cmark-upstream/src/%
cp $< $@
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ CommonMarker accepts the same options that CMark does, as symbols. Note that the

### Render options

| Name | Description
| ------------------ | -----------
| `:DEFAULT` | The default rendering system.
| `:GITHUB_PRE_LANG` | Use GitHub-style `<pre lang>` for fenced code blocks.
| `:HARDBREAKS` | Treat `\n` as hardbreaks (by adding `<br/>`).
| `:NOBREAKS` | Translate `\n` in the source to a single whitespace.
| `:SAFE` | Suppress raw HTML and unsafe links.
| `:SOURCEPOS` | Include source position in rendered HTML.
| `:TABLE_PREFER_STYLE_ATTRIBUTES` | Use `style` insted of `align` for table cells
| Name | Description |
| ------------------ | ----------- |
| `:DEFAULT` | The default rendering system. |
| `:GITHUB_PRE_LANG` | Use GitHub-style `<pre lang>` for fenced code blocks. |
| `:HARDBREAKS` | Treat `\n` as hardbreaks (by adding `<br/>`). |
| `:NOBREAKS` | Translate `\n` in the source to a single whitespace. |
| `:SAFE` | Suppress raw HTML and unsafe links. |
| `:SOURCEPOS` | Include source position in rendered HTML. |
| `:TABLE_PREFER_STYLE_ATTRIBUTES` | Use `style` insted of `align` for table cells |
| `:FULL_INFO_STRING` | Include full info strings of code blocks in separate attribute |

### Passing options

Expand Down
34 changes: 20 additions & 14 deletions ext/commonmarker/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,22 +755,24 @@ static void S_find_first_nonspace(cmark_parser *parser, cmark_chunk *input) {
char c;
int chars_to_tab = TAB_STOP - (parser->column % TAB_STOP);

parser->first_nonspace = parser->offset;
parser->first_nonspace_column = parser->column;
while ((c = peek_at(input, parser->first_nonspace))) {
if (c == ' ') {
parser->first_nonspace += 1;
parser->first_nonspace_column += 1;
chars_to_tab = chars_to_tab - 1;
if (chars_to_tab == 0) {
if (parser->first_nonspace <= parser->offset) {
parser->first_nonspace = parser->offset;
parser->first_nonspace_column = parser->column;
while ((c = peek_at(input, parser->first_nonspace))) {
if (c == ' ') {
parser->first_nonspace += 1;
parser->first_nonspace_column += 1;
chars_to_tab = chars_to_tab - 1;
if (chars_to_tab == 0) {
chars_to_tab = TAB_STOP;
}
} else if (c == '\t') {
parser->first_nonspace += 1;
parser->first_nonspace_column += chars_to_tab;
chars_to_tab = TAB_STOP;
} else {
break;
}
} else if (c == '\t') {
parser->first_nonspace += 1;
parser->first_nonspace_column += chars_to_tab;
chars_to_tab = TAB_STOP;
} else {
break;
}
}

Expand Down Expand Up @@ -1137,6 +1139,7 @@ static void open_new_blocks(cmark_parser *parser, cmark_node **container,

(*container)->internal_offset = matched;
} else if ((!indented || cont_type == CMARK_NODE_LIST) &&
parser->indent < 4 &&
(matched = parse_list_marker(
parser->mem, input, parser->first_nonspace,
(*container)->type == CMARK_NODE_PARAGRAPH, &data))) {
Expand Down Expand Up @@ -1372,6 +1375,9 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer,

parser->offset = 0;
parser->column = 0;
parser->first_nonspace = 0;
parser->first_nonspace_column = 0;
parser->indent = 0;
parser->blank = false;
parser->partially_consumed_tab = false;

Expand Down
2 changes: 1 addition & 1 deletion ext/commonmarker/cmark-upstream
5 changes: 5 additions & 0 deletions ext/commonmarker/cmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,11 @@ char *cmark_render_latex_with_mem(cmark_node *root, int options, int width, cmar
*/
#define CMARK_OPT_TABLE_PREFER_STYLE_ATTRIBUTES (1 << 15)

/** Include the remainder of the info string in code blocks in
* a separate attribute.
*/
#define CMARK_OPT_FULL_INFO_STRING (1 << 16)

/**
* ## Version information
*/
Expand Down
2 changes: 1 addition & 1 deletion ext/commonmarker/cmark_extension_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "C" {
#endif

#include <cmark.h>
#include "cmark.h"

struct cmark_renderer;
struct cmark_html_renderer;
Expand Down
2 changes: 1 addition & 1 deletion ext/commonmarker/core-extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "C" {
#endif

#include <cmark_extension_api.h>
#include "cmark_extension_api.h"
#include "cmarkextensions_export.h"
#include <stdint.h>

Expand Down
8 changes: 8 additions & 0 deletions ext/commonmarker/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,20 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
cmark_html_render_sourcepos(node, html, options);
cmark_strbuf_puts(html, " lang=\"");
escape_html(html, node->as.code.info.data, first_tag);
if (first_tag < node->as.code.info.len && (options & CMARK_OPT_FULL_INFO_STRING)) {
cmark_strbuf_puts(html, "\" data-meta=\"");
escape_html(html, node->as.code.info.data + first_tag + 1, node->as.code.info.len - first_tag - 1);
}
cmark_strbuf_puts(html, "\"><code>");
} else {
cmark_strbuf_puts(html, "<pre");
cmark_html_render_sourcepos(node, html, options);
cmark_strbuf_puts(html, "><code class=\"language-");
escape_html(html, node->as.code.info.data, first_tag);
if (first_tag < node->as.code.info.len && (options & CMARK_OPT_FULL_INFO_STRING)) {
cmark_strbuf_puts(html, "\" data-meta=\"");
escape_html(html, node->as.code.info.data + first_tag + 1, node->as.code.info.len - first_tag - 1);
}
cmark_strbuf_puts(html, "\">");
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/commonmarker/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ static bufsize_t manual_scan_link_url(cmark_chunk *input, bufsize_t offset,
break;
} else if (input->data[i] == '\\')
i += 2;
else if (cmark_isspace(input->data[i]) || input->data[i] == '<')
else if (input->data[i] == '\n' || input->data[i] == '<')
return manual_scan_link_url_2(input, offset, output);
else
++i;
Expand Down
Loading