summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-02-14 18:30:05 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-02-14 18:30:05 -0800
commitfd3ae5c387e9be4e9e6362b71b25b9945e54f54b (patch)
treefa548c5330d0b4cbb50c20cf23f5a0bd541339b5
parent515e823051533a91cae322536e6926eea4c48113 (diff)
Improved smart quote recognition.
All tests now pass.
-rw-r--r--src/html.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/html.c b/src/html.c
index c8cc9fb..87f2371 100644
--- a/src/html.c
+++ b/src/html.c
@@ -236,8 +236,38 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
escape_html(html, lit.data + lastout,
i - lastout);
if (c == '\'' || c == '"') {
- before_char = i == 0 ? ',' : lit.data[i - 1];
- after_char = i == lit.len - 1 ? ',' : lit.data[i + 1];
+ if (i == 0) {
+ if (node->prev) {
+ if (node->prev->type == CMARK_NODE_TEXT) {
+ before_char = node->prev->as.literal.data[node->prev->as.literal.len - 1];
+ } else if (node->prev->type == CMARK_NODE_SOFTBREAK ||
+ node->prev->type == CMARK_NODE_LINEBREAK) {
+ before_char = '\n';
+ } else {
+ before_char = 'x';
+ }
+ } else {
+ before_char = '\n';
+ }
+ } else {
+ before_char = lit.data[i - 1];
+ }
+ if (i >= lit.len - 1) {
+ if (node->next) {
+ if (node->next->type == CMARK_NODE_TEXT) {
+ after_char = node->next->as.literal.data[0];
+ } else if (node->next->type == CMARK_NODE_SOFTBREAK ||
+ node->next->type == CMARK_NODE_LINEBREAK) {
+ before_char = '\n';
+ } else {
+ after_char = 'x';
+ }
+ } else {
+ after_char = '\n';
+ }
+ } else {
+ after_char = lit.data[i + 1];
+ }
left_flanking = !utf8proc_is_space(after_char) &&
!(utf8proc_is_punctuation(after_char) &&
!utf8proc_is_space(before_char) &&