|
| 1 | + |
| 2 | +// -------------------------------- |
| 3 | +// CJK-friendly Emphasis |
| 4 | +// -------------------------------- |
| 5 | + |
| 6 | +using System; |
| 7 | +using NUnit.Framework; |
| 8 | + |
| 9 | +namespace Markdig.Tests.Specs.CJKFriendlyEmphasis |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class TestCJKFriendlyEmphasisExtension |
| 13 | + { |
| 14 | + // ## CJK-friendly Emphasis Extension |
| 15 | + // |
| 16 | + // See https://github.com/tats-u/markdown-cjk-friendly/blob/main/specification.md for details about the spec of this extension. |
| 17 | + // |
| 18 | + // This extension drastically mitigates [the long-standing issue (specification flaw)](https://github.com/commonmark/commonmark-spec/issues/650) in CommonMark that emphasis in CJK languages is often not parsed as expected. |
| 19 | + // |
| 20 | + // The plain CommonMark cannot recognize even the following emphasis in CJK languages: |
| 21 | + [Test] |
| 22 | + public void CJKFriendlyEmphasisExtension_Example001() |
| 23 | + { |
| 24 | + // Example 1 |
| 25 | + // Section: CJK-friendly Emphasis Extension |
| 26 | + // |
| 27 | + // The following Markdown: |
| 28 | + // **この文を強調できますか(Can I emphasize this sentence)?**残念ながらこの文のせいでできません(Unfortunately not possible due to this sentence)。 |
| 29 | + // |
| 30 | + // Should be rendered as: |
| 31 | + // <p><strong>この文を強調できますか(Can I emphasize this sentence)?</strong>残念ながらこの文のせいでできません(Unfortunately not possible due to this sentence)。</p> |
| 32 | + |
| 33 | + TestParser.TestSpec("**この文を強調できますか(Can I emphasize this sentence)?**残念ながらこの文のせいでできません(Unfortunately not possible due to this sentence)。", "<p><strong>この文を強調できますか(Can I emphasize this sentence)?</strong>残念ながらこの文のせいでできません(Unfortunately not possible due to this sentence)。</p>", "cjk-friendly-emphasis", context: "Example 1\nSection CJK-friendly Emphasis Extension\n"); |
| 34 | + } |
| 35 | + |
| 36 | + // ````````````````````````````````` example |
| 37 | + // 我可以强调**这个`code`**吗(Can I emphasize **this `code`**)? |
| 38 | + // . |
| 39 | + // <p>我可以强调<code>这个`code`</code>吗(Can I emphasize <strong>this <code>code</code></strong>)?</p> |
| 40 | + // ````````````````````````````````` |
| 41 | + [Test] |
| 42 | + public void CJKFriendlyEmphasisExtension_Example002() |
| 43 | + { |
| 44 | + // Example 2 |
| 45 | + // Section: CJK-friendly Emphasis Extension |
| 46 | + // |
| 47 | + // The following Markdown: |
| 48 | + // **이 용어(This term)**를 강조해 주세요. (Please emphasize **this term**.) |
| 49 | + // |
| 50 | + // Should be rendered as: |
| 51 | + // <p><strong>이 용어(This term)</strong>를 강조해 주세요. (Please emphasize <strong>this term</strong>.)</p> |
| 52 | + |
| 53 | + TestParser.TestSpec("**이 용어(This term)**를 강조해 주세요. (Please emphasize **this term**.)", "<p><strong>이 용어(This term)</strong>를 강조해 주세요. (Please emphasize <strong>this term</strong>.)</p>", "cjk-friendly-emphasis", context: "Example 2\nSection CJK-friendly Emphasis Extension\n"); |
| 54 | + } |
| 55 | + // You can compare the results with and without this extension: https://tats-u.github.io/markdown-cjk-friendly/?sc8=KirjgZPjga7mlofjgpLlvLfoqr_jgafjgY3jgb7jgZnjgYvvvIhDYW4gSSBlbXBoYXNpemUgdGhpcyBzZW50ZW5jZe-8ie-8nyoq5q6L5b-144Gq44GM44KJ44GT44Gu5paH44Gu44Gb44GE44Gn44Gn44GN44G-44Gb44KT77yIVW5mb3J0dW5hdGVseSBub3QgcG9zc2libGUgZHVlIHRvIHRoaXMgc2VudGVuY2XvvInjgIIKCuaIkeWPr-S7peW8uuiwgyoq6L-Z5LiqYGNvZGVgKirlkJfvvIhDYW4gSSBlbXBoYXNpemUgKip0aGlzIGBjb2RlYCoq77yJ77yfCgoqKuydtCDsmqnslrQoVGhpcyB0ZXJtKSoq66W8IOqwleyhsO2VtCDso7zshLjsmpQuIChQbGVhc2UgZW1waGFzaXplICoqdGhpcyB0ZXJtKiouKQo&gfm=1&engine=markdown-it |
| 56 | + // |
| 57 | + // You will find how poor the plain CommonMark is for CJK languages. |
| 58 | + // |
| 59 | + // To use this extension, configure the pipeline as follows: |
| 60 | + // |
| 61 | + // ```csharp |
| 62 | + // var pipeline = new MarkdownPipelineBuilder() |
| 63 | + // .UseCJKFriendlyEmphasis() // Add this |
| 64 | + // .Build(); |
| 65 | + // ``` |
| 66 | + } |
| 67 | +} |
0 commit comments