Skip to content

Termコンポーネントを書くための[[用語]]記法を導入#898

Open
chvmvd wants to merge 8 commits intomainfrom
add-remark-term
Open

Termコンポーネントを書くための[[用語]]記法を導入#898
chvmvd wants to merge 8 commits intomainfrom
add-remark-term

Conversation

@chvmvd
Copy link
Contributor

@chvmvd chvmvd commented Nov 23, 2025

Termコンポーネントを書くための[[用語]]記法を導入しました。この記法にした理由としては、Wikipediaなどでも使用されているようによく使われている直感的な記法であること、入力が極めて容易であること、将来的に記法を拡張する余地があることが挙げられます。

仕様は、TSDocの通りで、[[用語]]のように中身がテキストの場合、あるいは[[**用語**]]のように中身が単一のASTノードである場合のみ、正しくパースされます。

参考

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 23, 2025

Deploying utcode-learn with  Cloudflare Pages  Cloudflare Pages

Latest commit: 49d9c2e
Status: ✅  Deploy successful!
Preview URL: https://4b95f43b.utcode-learn.pages.dev
Branch Preview URL: https://add-remark-term.utcode-learn.pages.dev

View logs

@chvmvd chvmvd changed the base branch from main to add-typescript-support November 29, 2025 07:07
@chvmvd chvmvd force-pushed the add-remark-term branch 2 times, most recently from 5fdced0 to a0180af Compare November 29, 2025 07:16
Copy link
Contributor Author

Choose a reason for hiding this comment

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

「JavaScriptことはじめ」の節全体のみに、新しい記法を取り入れました。

import type { Nodes, Root, RootContent } from "mdast";
import { phrasing } from "mdast-util-phrasing";

const remarkTerm: Plugin<[], Root> = () => (tree) => transform(tree);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,114 @@
import type { Plugin } from "unified";
import type { Nodes, Root, RootContent } from "mdast";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

continue;
}

if (!phrasing(innerElement)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MdxJsxTextElement.childrenプロパティの型はArray<PhrasingContent>でありここで絞り込みをする必要があるため、mdast-util-phrasingパッケージのphrasing関数を使用しています。

cf. https://github.com/syntax-tree/mdast-util-mdx-jsx/blob/998d98d0aa29fe9ed12c636ddf1ed39f9a018096/readme.md#mdxjsxtextelement
cf. https://github.com/syntax-tree/mdast-util-phrasing

}
if (segmentedText.startsWith("[[")) {
transformedChildren.push({
type: "mdxJsxTextElement",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,116 @@
import type { Plugin } from "unified";
import type { Nodes, Root, RootContent } from "mdast";
import "mdast-util-mdx-jsx";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@chelproc chelproc Jan 10, 2026

Choose a reason for hiding this comment

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

ここだけランタイムに不要なインポートが発生しちゃってませんか?

@chvmvd chvmvd marked this pull request as ready for review November 30, 2025 03:57
Base automatically changed from add-typescript-support to main December 6, 2025 12:58
Copy link
Contributor

@chelproc chelproc left a comment

Choose a reason for hiding this comment

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

変換ロジックがやや冗長な気がします。↓みたいな感じでどうでしょう?Rootを特別扱いする必要もない気がします!

childrenを前から順番に走査しながら、

  1. 非テキストノード → 再帰
  2. (.+)\[\[(.+)\]\](.+) を見つけた → 現在のノードを $1, [[, $2, ]], $3 に分割して挿入
  3. (.+)\[\[ を見つけた → 先読みして \]\].+ が見つかったら Term を挿入

@@ -0,0 +1,116 @@
import type { Plugin } from "unified";
import type { Nodes, Root, RootContent } from "mdast";
import "mdast-util-mdx-jsx";
Copy link
Contributor

@chelproc chelproc Jan 10, 2026

Choose a reason for hiding this comment

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

ここだけランタイムに不要なインポートが発生しちゃってませんか?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Termコンポーネントを手書き JSX ではなく、Markdown 内の [[用語]] 記法から自動生成できるようにするための remark プラグイン導入PRです。Docusaurus の remarkPlugins に組み込み、既存ドキュメントの一部も新記法へ置き換えています。

Changes:

  • [[...]]<Term>...</Term> 相当の MDX JSX ノードへ変換する remark-term プラグインを追加
  • Docusaurus 設定に remarkTerm を追加し、必要な依存関係/型拡張を追加
  • サンプルとして JavaScript ドキュメントの <Term>[[...]] に置換

Reviewed changes

Copilot reviewed 4 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tsconfig.json TypeScript の strict を有効化
src/types/mdast-mdx-jsx.d.ts mdast に MDX JSX ノード型を追加するための型拡張 import を追加
src/remark/remark-term.ts [[...]]mdxJsxTextElement (Term) に変換する remark プラグインを新規追加
docusaurus.config.ts docs の remarkPluginsremarkTerm を追加
package.json プラグイン実装/型付けに必要な依存を追加
package-lock.json 依存追加に伴う lockfile 更新
docs/1-trial-session/04-javascript/index.mdx <Term>[[...]] 記法へ置換

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants