Skip to content

add handling for CJK text around emphasis delimiters #78

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

Open
wants to merge 8 commits into
base: gfm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
110 changes: 110 additions & 0 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,114 @@ static void table_spans(test_batch_runner *runner) {
}
}

static void cjk_emphasis(test_batch_runner *runner) {
static const char markdown[] =
"**テスト。**テスト\n"
"\n"
"**テスト**。テスト\n"
"\n"
"**テスト、**テスト\n"
"\n"
"**テスト**、テスト\n"
"\n"
"**テスト?**テスト\n"
"\n"
"**テスト**?テスト\n";
static const char expected_html[] =
"<p><strong>テスト。</strong>テスト</p>\n"
"<p><strong>テスト</strong>。テスト</p>\n"
"<p><strong>テスト、</strong>テスト</p>\n"
"<p><strong>テスト</strong>、テスト</p>\n"
"<p><strong>テスト?</strong>テスト</p>\n"
"<p><strong>テスト</strong>?テスト</p>\n";

cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);

char *html = cmark_render_html(doc, CMARK_OPT_DEFAULT, NULL);
STR_EQ(runner, html, expected_html, "emphasis parsing with CJK didn't generate expected HTML");

free(html);
cmark_node_free(doc);
}

static void cjk_emoji_emphasis(test_batch_runner *runner) {
static const char markdown[] =
"テスト。**テスト。**テスト\n"
"\n"
"テスト。**テスト**。テスト\n"
"\n"
"テスト、**テスト、**テスト\n"
"\n"
"テスト、**テスト**、テスト\n"
"\n"
"テスト?**テスト?**テスト\n"
"\n"
"テスト?**テスト**?テスト\n"
"\n"
"テスト**テスト?**テスト\n"
"\n"
"テスト**テスト**?テスト\n"
"\n"
"テスト✌🏻**テスト?**テスト\n"
"\n"
"テスト✌🏻**テスト**?テスト\n"
"\n"
"テスト🇯🇵**テスト?**テスト\n"
"\n"
"テスト🇯🇵**テスト**?テスト\n"
"\n"
"テスト🏴󠁧󠁢󠁳󠁣󠁴󠁿**テスト?**テスト\n"
"\n"
"テスト🏴󠁧󠁢󠁳󠁣󠁴󠁿**テスト**?テスト\n"
"\n"
"テスト*️⃣**テスト?**テスト\n"
"\n"
"テスト*️⃣**テスト**?テスト\n"
"\n"
"テスト©️**テスト?**テスト\n"
"\n"
"テスト©️**テスト**?テスト\n"
"\n"
"テスト©**テスト?**テスト\n"
"\n"
"テスト©**テスト**?テスト\n"
"\n"
"テスト⌛**テスト?**テスト\n"
"\n"
"テスト⌛**テスト**?テスト\n";
Comment on lines +1648 to +1674
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These emojis and symbols have no effect. The following is better:

テスト**テスト?**test

テスト**✌🏻テスト**テスト

テスト**テスト?**テスト

test**「テスト」**テスト

static const char expected_html[] =
"<p>テスト。<strong>テスト。</strong>テスト</p>\n"
"<p>テスト。<strong>テスト</strong>。テスト</p>\n"
"<p>テスト、<strong>テスト、</strong>テスト</p>\n"
"<p>テスト、<strong>テスト</strong>、テスト</p>\n"
"<p>テスト?<strong>テスト?</strong>テスト</p>\n"
"<p>テスト?<strong>テスト</strong>?テスト</p>\n"
"<p>テスト<strong>テスト?</strong>テスト</p>\n"
"<p>テスト<strong>テスト</strong>?テスト</p>\n"
"<p>テスト✌🏻<strong>テスト?</strong>テスト</p>\n"
"<p>テスト✌🏻<strong>テスト</strong>?テスト</p>\n"
"<p>テスト🇯🇵<strong>テスト?</strong>テスト</p>\n"
"<p>テスト🇯🇵<strong>テスト</strong>?テスト</p>\n"
"<p>テスト🏴󠁧󠁢󠁳󠁣󠁴󠁿<strong>テスト?</strong>テスト</p>\n"
"<p>テスト🏴󠁧󠁢󠁳󠁣󠁴󠁿<strong>テスト</strong>?テスト</p>\n"
"<p>テスト*️⃣<strong>テスト?</strong>テスト</p>\n"
"<p>テスト*️⃣<strong>テスト</strong>?テスト</p>\n"
"<p>テスト©️<strong>テスト?</strong>テスト</p>\n"
"<p>テスト©️<strong>テスト</strong>?テスト</p>\n"
"<p>テスト©<strong>テスト?</strong>テスト</p>\n"
"<p>テスト©<strong>テスト</strong>?テスト</p>\n"
"<p>テスト⌛<strong>テスト?</strong>テスト</p>\n"
"<p>テスト⌛<strong>テスト</strong>?テスト</p>\n";

cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);

char *html = cmark_render_html(doc, CMARK_OPT_DEFAULT, NULL);
STR_EQ(runner, html, expected_html, "emphasis parsing with CJK and emoji didn't generate expected HTML");

free(html);
cmark_node_free(doc);
}

int main() {
int retval;
test_batch_runner *runner = test_batch_runner_new();
Expand Down Expand Up @@ -1616,6 +1724,8 @@ int main() {
verify_custom_attributes_node_with_footnote(runner);
parser_interrupt(runner);
table_spans(runner);
cjk_emphasis(runner);
cjk_emoji_emphasis(runner);

test_print_summary(runner);
retval = test_ok(runner) ? 0 : 1;
Expand Down
Loading