
Research
/Security News
Mini Shai-Hulud Campaign Hits Red Hat Cloud Services npm Packages
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.
markdown-it-escaped-space
Advanced tools
A markdown-it plugin that fixes emphasis markers and GFM autolinks in CJK text using escaped spaces, inspired by reStructuredText and goldmark. Also converts escaped double spaces to non-breaking spaces and fixes full-width space trimming.
A markdown-it extension that allows escaped spaces around emphasis markers and GFM autolinks in CJK (Chinese, Japanese, and Korean) text.
CommonMark has limitations when dealing with CJK text:
Emphasis markers like ** may not be recognized as emphasis marks when they are adjacent to CJK punctuation marks or when soft line breaks exist between CJK characters.
For example, without this extension:
太郎は**「こんにちわ」**といった。
张三说**「你好」**的时候。
김철수는**「안녕하세요」**라고 말했습니다.
The emphasis markers here are not recognized as emphasis due to the adjacent punctuation marks.
GFM's autolink feature also has compatibility issues with CJK text. Without proper handling, GFM autolinks may incorrectly extend into following CJK content or cause unwanted breaks.
For example:
詳しくはhttps://example.comをご覧ください。
Renders as:
<p>詳しくは<a href="https://example.comをご覧ください。">https://example.comをご覧ください。</a></p>
The autolink incorrectly includes the CJK text after the URL, breaking the intended link.
A common workaround is to add a space after the URL:
詳しくはhttps://example.com をご覧ください。
This renders correctly:
<p>詳しくは<a href="https://example.com">https://example.com</a> をご覧ください。</p>
However, this workaround has a visual drawback: the space between the URL and the following CJK text is rendered as a visible space in HTML, which may look unnatural or create unexpected line breaks in some contexts. This is especially problematic for professional documents where precise spacing is important.
This extension allows you to use escaped spaces (backslash-space) to fix both emphasis recognition and autolink delineation in CJK contexts:
太郎は\ **「こんにちわ」**\ といった。
张三说\ **「你好」**\ 的时候。
김철수는\ **「안녕하세요」**\ 라고 말했습니다。
詳しくはhttps://example.com\ をご覧ください。
The escaped spaces are "not rendered" in the output but allow proper parsing while maintaining readability in the source.
This solution is also adopted in reStructuredText, which is a documentation format used by the Python community.
Escaped spaces around emphasis markers and autolinks help with CJK text processing, ensuring proper recognition even when adjacent to CJK punctuation.
For Emphasis:
太郎は\ **「こんにちわ」**\ といった。
Renders as:
<p>太郎は<strong>「こんにちわ」</strong>といった。</p>
For Autolinks:
詳しくはhttps://example.com\ をご覧ください。
Renders as:
<p>詳しくは<a href="https://example.com">https://example.com</a>をご覧ください。</p>
Note how the escaped space delineates the autolink without introducing a visible space in the output.
In addition to CJK support, this extension includes a custom feature for general typography: backslash followed by two spaces is converted to a non-breaking space (U+00A0).
Use case: Preventing line breaks between related words in European languages.
Example:
The\ author is John\ Doe.
Renders as:
<p>The author is John Doe.</p>
This is useful for:
[!NOTE] This feature is experimental and its syntax may be changed to
\ \in the future.
See specification.md for detailed technical specifications.
You should use this extension if you:
<strong>This extension is designed to be used in conjunction with your Markdown parser. The behavior is:
\ ) around emphasis markers and autolinks is not rendered in the output\ ) is converted to a non-breaking spaceInput:
太郎は\ **「こんにちわ」**\ といった。
Output:
<p>太郎は<strong>「こんにちわ」</strong>といった。</p>
Input:
詳しくはhttps://example.com\ をご覧ください。
Output:
<p>詳しくは<a href="https://example.com">https://example.com</a>をご覧ください。</p>
Input:
The\ quick brown fox
Output:
<p>The quick brown fox</p>
This extension is a port of the WithEscapedSpace option from goldmark's CJK extension.
There is another more user-friendly approach to handling CJK text in Markdown without adding extra symbols \ (CJK Friendly Emphasis Extension):
It is not mutually exclusive with this extension, and you can use both together if needed. Especially, you can use this Escaped Space extension as the fallback for corner cases where the CJK Friendly Emphasis extension does not work.
This extension does not affect behavior in languages other than CJK for emphasis handling. Content in English, European languages, and other non-CJK text will render identically with or without the escaped space emphasis feature.
The non-breaking space feature is language-agnostic and works universally.
In addition to the escaped space features, this extension fixes a markdown-it bug where full-width spaces (U+3000 and other non-ASCII whitespace characters) at the beginning or end of lines are incorrectly trimmed.
markdown-it uses JavaScript's .trim() method to remove leading/trailing whitespace from lines. However, .trim() removes all Unicode whitespace characters, not just ASCII spaces (U+0020) as specified by CommonMark. This causes full-width spaces (U+3000) and other non-ASCII whitespace to be stripped from the source, which is problematic when:
Related issues:
Without this extension:
このテキストは全角スペースで始まります。
最後の行は全角スペースで終わります
The full-width spaces would be incorrectly removed by markdown-it's default trimming behavior.
This extension preserves full-width spaces and other non-ASCII whitespace at line boundaries, allowing you to:
If you're using markdown-it with CJK content or need to preserve full-width spaces for any reason, use this extension to avoid losing important formatting information.
Please submit issues and pull requests in English or Japanese.
MIT
Install dependencies:
pnpm install
Run the unit tests:
pnpm run test
Build the library:
pnpm run build
FAQs
A markdown-it plugin that fixes emphasis markers and GFM autolinks in CJK text using escaped spaces, inspired by reStructuredText and goldmark. Also converts escaped double spaces to non-breaking spaces and fixes full-width space trimming.
We found that markdown-it-escaped-space demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.

Security News
The Rust project is moving toward formal rules on LLM use in contributions after months of internal debate over maintainer burden, code quality, and contributor experience.