From 658242dd9c9e25559d305635a353ae9cdd5426ef Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Sat, 17 Jun 2017 17:50:34 -0400 Subject: [PATCH] FIXED: Improve apostrophe detection after punctuation mark --- Sources/libMultiMarkdown/mmd.c | 12 +++++++++--- tests/MMD6Tests/Smart Quotes.fodt | 6 ++++++ tests/MMD6Tests/Smart Quotes.html | 6 ++++++ tests/MMD6Tests/Smart Quotes.htmlc | 6 ++++++ tests/MMD6Tests/Smart Quotes.tex | 6 ++++++ tests/MMD6Tests/Smart Quotes.text | 6 ++++++ 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index 4ca0c94..9e2c794 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -1270,7 +1270,8 @@ void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, size // Some of these are actually APOSTROPHE's and should not be paired offset = t->start; - if (!((offset == 0) || (char_is_whitespace_or_line_ending_or_punctuation(str[offset - 1])) || + if (!((offset == 0) || + (char_is_whitespace_or_line_ending_or_punctuation(str[offset - 1])) || (char_is_whitespace_or_line_ending_or_punctuation(str[offset + 1])))) { t->type = APOSTROPHE; break; @@ -1278,8 +1279,13 @@ void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, size if (offset && (char_is_punctuation(str[offset - 1])) && (char_is_alphanumeric(str[offset + 1]))) { - t->type = APOSTROPHE; - break; + // If possessive apostrophe, e.g. `x`'s + if (str[offset + 1] == 's' || str[offset + 1] == 'S') { + if (char_is_whitespace_or_line_ending_or_punctuation(str[offset + 2])) { + t->type = APOSTROPHE; + break; + } + } } case QUOTE_DOUBLE: offset = t->start; diff --git a/tests/MMD6Tests/Smart Quotes.fodt b/tests/MMD6Tests/Smart Quotes.fodt index 8a6b726..3d59ff8 100644 --- a/tests/MMD6Tests/Smart Quotes.fodt +++ b/tests/MMD6Tests/Smart Quotes.fodt @@ -345,6 +345,12 @@ foo’s and bar’s foo’s and bar’s + +30 + +foo(‘bar’) + +foo(“bar”) diff --git a/tests/MMD6Tests/Smart Quotes.html b/tests/MMD6Tests/Smart Quotes.html index cf49903..db157d9 100644 --- a/tests/MMD6Tests/Smart Quotes.html +++ b/tests/MMD6Tests/Smart Quotes.html @@ -76,6 +76,12 @@

foo’s and bar’s

+

30

+ +

foo(‘bar’)

+ +

foo(“bar”)

+ diff --git a/tests/MMD6Tests/Smart Quotes.htmlc b/tests/MMD6Tests/Smart Quotes.htmlc index 413ee55..104dafb 100644 --- a/tests/MMD6Tests/Smart Quotes.htmlc +++ b/tests/MMD6Tests/Smart Quotes.htmlc @@ -70,3 +70,9 @@ latex config: article

foo's and bar's

foo's and bar's

+ +

30

+ +

foo('bar')

+ +

foo("bar")

diff --git a/tests/MMD6Tests/Smart Quotes.tex b/tests/MMD6Tests/Smart Quotes.tex index 16be996..47d3800 100644 --- a/tests/MMD6Tests/Smart Quotes.tex +++ b/tests/MMD6Tests/Smart Quotes.tex @@ -72,5 +72,11 @@ foo's and bar's \texttt{foo}'s and \texttt{bar}'s +30 + +foo(`bar') + +foo(``bar'') + \input{mmd6-article-footer} \end{document} diff --git a/tests/MMD6Tests/Smart Quotes.text b/tests/MMD6Tests/Smart Quotes.text index a1e92e4..c94227d 100644 --- a/tests/MMD6Tests/Smart Quotes.text +++ b/tests/MMD6Tests/Smart Quotes.text @@ -70,3 +70,9 @@ l'année l'été foo's and bar's `foo`'s and `bar`'s + +30 + +foo('bar') + +foo("bar") -- 2.40.0