Skip to content

Commit

Permalink
Merge pull request #380 from jcheatham/fix_214_and_369
Browse files Browse the repository at this point in the history
Fix emphasis escape sequence detection
  • Loading branch information
robin850 committed May 29, 2014
2 parents 799cbdf + 96ea6b6 commit e4dd7ec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

* Fix emphasis character escape sequence detection while mid-emphasis.

*jcheatham*

* Convert trailing single quotes to curly quotes. For example,
`Road Trippin'` now converts to `Road Trippin’`.

Expand Down
8 changes: 4 additions & 4 deletions ext/redcarpet/markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,14 @@ find_emph_char(uint8_t *data, size_t size, uint8_t c)
if (i == size)
return 0;

if (data[i] == c)
return i;

/* not counting escaped chars */
if (i && data[i - 1] == '\\') {
i++; continue;
}

if (data[i] == c)
return i;

if (data[i] == '`') {
size_t span_nb = 0, bt;
size_t tmp_i = 0;
Expand Down Expand Up @@ -845,7 +845,7 @@ char_quote(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t offse
static size_t
char_escape(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t offset, size_t size)
{
static const char *escape_chars = "\\`*_{}[]()#+-.!:|&<>^~";
static const char *escape_chars = "\\`*_{}[]()#+-.!:|&<>^~=";
struct buf work = { 0, 0, 0, 0 };

if (size > 1) {
Expand Down
13 changes: 12 additions & 1 deletion test/markdown_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ def test_proper_intra_emphasis
assert_equal html, render_with({:no_intra_emphasis => true}, markdown)
end

def test_emphasis_escaping
markdown = @markdown.render("**foo\\*** _dd\\_dd_")
html_equal "<p><strong>foo*</strong> <em>dd_dd</em></p>\n", markdown
end

def test_char_escaping_when_highlighting
markdown = "==attribute\\==="
output = render_with({highlight: true}, markdown)
html_equal "<p><mark>attribute=</mark></p>\n", output
end

def test_ordered_lists_with_lax_spacing
markdown = "Foo:\n1. Foo\n2. Bar"
output = render_with({lax_spacing: true}, markdown)
Expand All @@ -290,6 +301,6 @@ def test_ordered_lists_with_lax_spacing

def test_references_with_tabs_after_colon
markdown = @markdown.render("[Link][id]\n[id]:\t\t\thttp://google.es")
html_equal '<p><a href="http://google.es">Link</a></p>', markdown
html_equal "<p><a href=\"http://google.es\">Link</a></p>\n", markdown
end
end

0 comments on commit e4dd7ec

Please sign in to comment.