remark-cjk-friendly-gfm-strikethrough

1.0.0 • Public • Published

remark-cjk-friendly-gfm-strikethrough

Version NPM Downloads NPM Last Update

A remark plugin to make GitHub Flavored Markdown (GFM) strikethrough (~~) compatible with Chinese, Japanese, and Korean (CJK).

GitHub Flavored Markdown(GFM)の取り消し線記号(~~)を日本語・中国語・韓国語にきちんと対応させるためのremarkプラグイン

一个 remark 插件,用于使 GitHub Flavored Markdown(GFM)的删除线标记(~~)能够正确支持中文、日语和韩语文本。

GitHub Flavored Markdown(GFM)의 취소선 기호(~~)를 한국어, 중국어, 일본어와 호환되도록 만드는 remark 플러그인

Problem / 問題 / 问题 / 문제점

CommonMark has a problem that the following emphasis marks ** are not recognized as emphasis marks in Japanese, Chinese, and Korean.

CommonMarkには、日本語・中国語・韓国語内の次のような強調記号(**)が強調記号として認識されない問題があります。

CommonMark存在以下问题:在中文、日语和韩语文本中,强调标记**不会被识别为强调标记。

CommonMark는 일본어와 중국어에서 다음과 같은 강조 표시 **가 강조 표시로 인식되지 않는 문제가 있습니다.

**このアスタリスクは強調記号として認識されず、そのまま表示されます。**この文のせいで。

**该星号不会被识别,而是直接显示。**这是因为它没有被识别为强调符号。

**이 별표는 강조 표시로 인식되지 않고 그대로 표시됩니다(이 괄호 때문에)**이 문장 때문에.

This problem occurs because the character just inside the ** is a (Japanese or Chinese) punctuation mark (。) or parenthesis and the character just outside is not a space or punctuation mark.

これが起こった原因は、終了側の**のすぐ内側が約物(。やカッコ)、かつ外側が約物や空白以外の文字であるためです。

这个问题是因为在**的结束部分,内侧字符是标点符号(。)或括号,而外侧字符不是空格或标点符号。

이 문제는 ** 바로 안쪽의 문자가 (일본어나 중국어) 문장 부호(。) 또는 괄호이고 바깥쪽 문자가 공백이나 문장 부호가 아니기 때문에 발생합니다.

Of course, not only the end side but also the start side has the same issue.

もちろん終了側だけでなく、開始側も同様の問題が存在します。

当然,不仅是结束侧,开始侧也存在同样的问题。

물론 끝나는 부분뿐만 아니라 시작하는 부분에서도 동일한 문제가 있습니다.

CommonMark issue: https://github.com/commonmark/commonmark-spec/issues/650

This behavior is also applied to the strikethrough (~~) in GFM.

この挙動は、GFMの取り消し線(~~)にも該当します。

这个行为也适用于 GFM 的删除线(~~)。

이 동작은 GFM의 취소선(~~)에도 해당됩니다.

Runtime Requirements / 実行環境の要件 / 运行环境要求 / 업데이트 전략

This package uses the v flag of the regular expression introduced in ES2024 to determine whether the character is an emoji or not.

本パッケージは文字が絵文字かどうかを判定するために、ES2024で導入された正規表現のvフラグを使用しています。

本包使用 ES2024 引入的v 标志 来判断字符是否为 emoji。

이 패키지는 ES2024에서 도입된 v 플래그를 사용하여 문자가 이모지인지 여부를 판단합니다.

It makes this package compatible only with relatively recent browsers and Node.js:

このため、本パッケージは、次のような比較的新しいブラウザやNode.jsでしか動作しません。

因此,本包只兼容比较新的浏览器和 Node.js:

따라서, 이 패키지는 비교적 최신 브라우저와 Node.js에서만 작동합니다.

  • Chrome / Edge 112 or later
  • Firefox 116 or later
  • Safari 17 or later
  • Node.js 20 or later

Installation / インストール / 安装 / 설치

Install remark-cjk-friendly via npm:

remark-cjk-friendlynpmでインストールしてください。

通过 npm 安装 remark-cjk-friendly

remark-cjk-friendlynpm으로 설치하세요.

npm install remark-cjk-friendly

If you use another package manager, please replace npm install with the command of the package manager you use (e.g. pnpm add or yarn add).

npm以外のパッケージマネージャを使う場合は、npm installを当該パッケージマネージャのコマンド(例:pnpm addyarn add)に置き換えてください。

如果使用其他包管理器,请将 npm install 替换为当时包管理器的命令(例如:pnpm addyarn add)。

다른 패키지 매니저를 사용하는 경우 npm install을 해당 패키지 매니저의 명령어(예: pnpm add, yarn add)로 바꾸어 주세요.

Usage / 使い方 / 用法 / 사용법

Import remark-cjk-friendly-gfm-strikethrough with other remark-related packages, and use the plugin as follows:

remark-cjk-friendly-gfm-strikethroughを他のremark関連パッケージと一緒にインポートし、次のようにプラグインを使用してください。

remark-cjk-friendly-gfm-strikethrough 与其他 remark 相关的包一起导入,然后使用插件如下:

remark-cjk-friendly-gfm-strikethrough를 다른 remark 관련 패키지와 함께 가져온 후 다음과 같이 플러그인을 사용하세요.

import rehypeStringify from "rehype-stringify";
import remarkCjkFriendly from "remark-cjk-friendly";
import remarkCjkFriendlyGfmStrikethrough from "remark-cjk-friendly-gfm-strikethrough";
import remarkGfm from "remark-gfm";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import { unified } from "unified";

// e.g. in the case that you want to enable GFM and obtain HTML output
const processor = unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkCjkFriendly)
  .use(remarkCjkFriendlyGfmStrikethrough)
  .use(remarkRehype)
  .use(rehypeStringify);

const htmlResult = (await processor.process(markdownString)).toString();

[!IMPORTANT] You must place remarkCjkFriendlyGfmStrikethrough between remarkGfm and remarkRehype. If it is put before remarkGfm, this plugin will not work.

remarkCjkFriendlyGfmStrikethroughremarkGfmremarkRehypeの間に配置してください。remarkGfmより前に配置すると、このプラグインは動作しません。

remarkCjkFriendlyGfmStrikethrough 应放在 remarkGfmremarkRehype 之间。如果将它放在 remarkGfm 之前,该插件将无法工作。

remarkCjkFriendlyGfmStrikethroughremarkGfmremarkRehype 사이에 배치해야 합니다.remarkGfm보다 앞에 배치하면 이 플러그인은 작동하지 않습니다.

For MDX, add remarkCjkFriendlyGfmStrikethrough to the remarkPlugins array in the config object:

MDXでは、設定オブジェクトのremarkPlugins配列にremarkCjkFriendlySGfmStrikethroughを追加してください。

对于 MDX,将 remarkCjkFriendlyGfmStrikethrough 添加到配置对象的 remarkPlugins 数组中。

MDX의 경우, remarkCjkFriendlyGfmStrikethroughremarkPlugins 배열에 추가해주세요.

const someMdxConfig = {
  remarkPlugins: [remarkGfm, remarkCjkFriendly, remarkCjkFriendlyGfmStrikethrough, ...otherRemarkPlugins],
  rehypePlugins: [...someRehypePlugins],
};

[!IMPORTANT] Place remarkCjkFriendlyGfmStrikethrough after remarkGfm, or remarkCjkFriendlyGfmStrikethrough will not work.

remarkCjkFriendlyGfmStrikethroughremarkGfmの後に配置してください。さもなければ、remarkCjkFriendlyGfmStrikethroughが動作しません。

remarkCjkFriendlyGfmStrikethrough 放在 remarkGfm 后面,否则 remarkCjkFriendlyGfmStrikethrough 将无法工作。

remarkCjkFriendlyGfmStrikethroughremarkGfm 사이에 배치해야 합니다. 쓰면 remarkCjkFriendlyGfmStrikethrough는 작동하지 않습니다.

In Rspress and Next.js (@next/mdx), you will probably need to set mdxRs to false to make Rspress use a JavaScript-based and monkey-patchable parser.

RspressNext.js(@next/mdxでは、mdxRsfalseに設定して、RspressにJavaScript製でモンキーパッチ可能なパーサを使わせる必要がおそらくあります。

RspressNext.js(@next/mdx)中,您可能需要将mdxRs设置为false,以使Rspress使用基于JavaScript且可进行猴子补丁的解析器。

RspressNext.js(@next/mdx)에서는 mdxRsfalse로 설정하여 Rspress가 JavaScript 기반이며 몽키 패치가 가능한 파서를 사용하도록 해야 할 것 같습니다.

Compatibility with the other languages / 他言語との互換性 / 与其他语言的兼容性 / 다른 언어와의 호환성

This modification of the specification does not affect the other languages than Chinese, Japanese, and Korean. Even if your application or document has translations or content in other languages, it will not be affected, so please feel free to use this packages. I assure that even with this package, remark still outputs the same HTML for all test cases in cmark-gfm as of 0.29.0.gfm.13.

この仕様変更提案は、日本語・中国語・韓国語以外の言語には影響しません。アプリケーションやドキュメントに他言語の翻訳やコンテンツが含まれていても影響はありませんので、安心して本パッケージをご利用ください。本パッケージを使用しても、0.29.0.gfm.13時点のcmark-gfmの全てのテストケースで、remarkが同じHTMLを出力することを保証しています。

除中文、日文和韩文外,建议的规范变更不会影响其他语言。请放心使用此软件包,因为如果您的应用程序或文档包含其他语言的翻译或内容,也不会受到影响。我保证,即使使用此软件包,remark 仍然会为 0.29.0.gfm.13 版本的所有 cmark-gfm 测试用例输出相同的 HTML。

이번 사양 변경 제안은 한국어, 중국어, 일본어 이외의 언어에는 영향을 미치지 않습니다. 애플리케이션이나 문서에 다른 언어의 번역이나 콘텐츠가 포함되어 있어도 영향을 받지 않으므로 안심하고 본 패키지를 사용하시기 바랍니다. 본 패키지를 사용해도 0.29.0.gfm.13 기준 cmark-gfm.13의 모든 테스트 케이스에서 mark가 동일한 HTML을 출력하도록 보장합니다.

Specification / 規格書 / 规范 / 규정서

The condition for ~~ to be recognized as a strikeout is the same as the condition for ** to be recognized as emphasis in the following CommonMark specification amendment suggestion:

https://github.com/tats-u/markdown-cjk-friendly/blob/main/specification.md (English)

Related packages / 関連パッケージ / 相关包 / 관련 패키지

Contributing / 貢献 / 贡献 / 기여

Setup

Install the dependencies:

pnpm install

Get Started

Build the library:

pnpm build

Build the library in watch mode:

pnpm dev

Package Sidebar

Install

npm i remark-cjk-friendly-gfm-strikethrough

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

21.4 kB

Total Files

5

Last publish

Collaborators

  • tats-u