# Contributing to dg-echarts 日本語:[このページの後半](#日本語)([CONTRIBUTING.ja.md](CONTRIBUTING.ja.md) と同じ内容) Thank you for your interest. Bug reports, ideas, translations and pull requests are welcome. ## Before you start - For bugs and requests, please open an [issue](https://github.com/akiratamcat/joplin-plugin-dg-echarts/issues) first. - For security problems, do not open a public issue. See [SECURITY.md](SECURITY.md). - The design is described in [docs/design.ja.md](docs/design.ja.md) (in Japanese). The documents in `docs/` are written only in Japanese (`*.ja.md`): - `design.ja.md`: the design document (requirements, architecture, tests, release). - `lessons-learned.ja.md`: things found in investigations and tests that changed the design or the code (ECharts quirks, Joplin's behaviour). - `spike-results.ja.md`: the results of the experiments made before the design (how ECharts runs inside Joplin). - `owner-decisions.ja.md`: decisions made by the maintainer. ## Development environment - Node.js 22 or later and npm (the CI uses Node.js 22) - Google Chrome (used by the rendering tests; no browser download is needed) - Joplin desktop 3.1 or later, to try the plugin ```sh npm ci npm run dist # builds publish/io.github.akiratamcat.dg-echarts.jpl ``` Install the `.jpl` with "Install from file" on Joplin's plugin screen (Tools → Options → Plugins; on macOS, Joplin → Settings → Plugins), then restart Joplin. ## How it works Charts are drawn while Joplin turns Markdown into HTML: the Markdown-it content script loads the bundled ECharts build with Node's `require`, draws each `echarts` block as an SVG string, sanitises it and puts it straight into the HTML. So charts need no script in the page, and they also show in PDF and HTML exports. The viewer script only adds the toolbar. See `docs/design.ja.md`, chapters 5 and 7. ## Project layout | Path | Contents | | ---- | -------- | | `src/index.ts` | Main plugin script: settings, content scripts, toolbar actions (copy, save) | | `src/contentScript/markdownItPlugin.ts` | Markdown-it plugin: parses, checks and draws each chart, writes the HTML | | `src/contentScript/` | Engine loader, input guard and checks, theme and font size adjustments, sanitising, cache, viewer script (toolbar), CodeMirror plugin | | `src/shared/` | Code used by several scripts (fence parsing, setting keys, tokenizer, messages) | | `src/i18n/` | gettext implementation; `catalog/catalogs.json` is generated by `npm run i18n:compile` | | `vendor/echarts/` | The ECharts engine and locale files, copied unchanged (see `SOURCE.md`) | | `locales/` | Translations (gettext PO files) | | `icons/` | Plugin icon: `icon.svg` (an original pie chart, not the ECharts logo) and the PNG files made from it | | `scripts/` | i18n, license, README and publish checks | | `tests/` | Unit tests; `tests/render/` rendering tests; `tests/manual/` manual test procedures and records (`*.ja.md`, in Japanese) and test notes to paste into Joplin (`*.md`, in English); `tests/evidence/` files saved during the manual tests | ## Commands | Command | What it does | | ------- | ------------ | | `npm run dist` | Builds the plugin package (`publish/*.jpl`) | | `npm test` | Unit tests, then the rendering tests | | `npm run test:unit` | Compiles and checks the translations, checks the licenses and the bilingual documents, then runs the unit tests and the static network check (no build needed) | | `npm run test:render` | Builds the plugin, then shows charts made by the built content script in headless Chrome with the network blocked | | `npm run typecheck` | TypeScript type check | | `npm run lint` | ESLint | | `npm run i18n:extract` | Updates `locales/echarts.pot` and all PO files from the source code | | `npm run i18n:check` | Checks the PO files (placeholders, plural forms, fuzzy entries) | | `npm run i18n:compile` | Builds `src/i18n/catalog/catalogs.json` from the PO files (run by `dist`, `test:unit` and `typecheck`) | | `npm run notices` | Rebuilds `THIRD_PARTY_NOTICES.md` and `THIRD_PARTY_NOTICES.ja.md` | | `npm run docs` | Copies `README.ja.md`, `CONTRIBUTING.ja.md`, `SECURITY.ja.md` and `CHANGELOG.ja.md` into the Japanese half of the English files | | `npm run docs:check` | Checks that the Japanese halves match the `*.ja.md` files (run by `test:unit`) | | `npm run licenses:check` | Checks the licenses of the bundled packages and that the notices, version lists and README tables are up to date | | `npm run icons` | Makes the PNG icons from `icons/icon.svg` with Google Chrome | | `npm run check:publish` | Checks the branch history before pushing to GitHub (emails, files that must not be published, secrets, local paths). Maintainer use | Please run `npm test`, `npm run typecheck` and `npm run lint` before you open a pull request. To use another Chromium build for the rendering tests, set `DG_CHROME_PATH` to its executable. ## Branches and pull requests The project uses GitHub Flow. - `main` is the only long-lived branch and is always ready for a release. Releases are tags `vX.Y.Z` on `main`. - Create a branch from `main` with a prefix: `feature/…` (new or changed features), `fix/…` (bug fixes) or `docs/…` (documents only). - Open a pull request to `main`. It can be merged when the CI passes (lint, type check, and the tests on Windows, macOS and Linux). The maintainer's own changes go through pull requests too. - Pull requests are merged with a merge commit (no squash or rebase merge), so each piece of work stays visible in the history. - Merged branches are deleted (GitHub does it automatically). Their commits stay in `main`. - Fixes for a released version are made on a `fix/…` branch from `main` and released as a new PATCH version. Older versions get no fixes. - `spike/…` branches are throw-away experiments: they are not merged and not pushed. ## Rules - **No network access.** The plugin must not make network requests (see the README). Do not add code or dependencies that do. The static check (`tests/network.test.ts`) fails on new network code, and the rendering tests fail on any request. - **The input guard** (`src/contentScript/inputGuard.ts`) removes options that load images or take HTML. It is a deny list: when ECharts gets new options of that kind, add them there. - **The ECharts engine** in `vendor/echarts/` is kept unchanged (the official minified build). It is updated only for security fixes or needed bug fixes. The update steps are in `vendor/echarts/SOURCE.md`. - **Never run the chart source as JavaScript.** Charts are JSON or YAML data only. - **Dependencies** are pinned to exact versions. A package that ends up in the plugin needs a license from the allowlist in `scripts/check-licenses.mjs`, and an entry in `scripts/notices.mjs`, `src/thirdParty.ts` and the README tables. - **Documents**: the files at the top of the repository have an English and a Japanese version (`*.ja.md`); please update both, or say in the pull request which one needs a translation. GitHub and the Joplin plugin site show only the English file, so `README.md`, `CONTRIBUTING.md`, `SECURITY.md` and `CHANGELOG.md` hold the English text and, after it, a copy of the `*.ja.md` file: edit the `*.ja.md` file and run `npm run docs`, never the Japanese half of the English file itself. - **Changelog**: write each change in both `CHANGELOG.md` and `CHANGELOG.ja.md`. The release notes on GitHub are made from both (English first, then Japanese). ## Translations Translations are gettext PO files in `locales/` (`ja.po`, `de.po`...), so they can be edited with Poedit or any text editor. The current translations were made with generative AI, so corrections by native speakers are very welcome. - To correct a translation, edit the `msgstr` in `locales/.po` and run `npm run i18n:check`. - Keep placeholders such as `{line}` and `{message}` as they are. ECharts option names (`series`, `xAxis`...), `theme=dark`, `width=` and ```` ```echarts ```` are not translated. Notes for translators are the `#.` comments. - After changing texts in the source code, run `npm run i18n:extract` to update `locales/echarts.pot` and all PO files. - A new language needs an entry in `scripts/i18n-common.mjs` and in `src/i18n/gettext.ts` (plural rules). The month names of date axes come from the ECharts locale files in `vendor/echarts/`. Untranslated texts are shown in English. ## License of contributions dg-echarts is released under the MIT License. By submitting a contribution (code, translations, documentation), you agree that it is provided under the MIT License. ## Generative AI This project is developed with extensive use of generative AI (Anthropic's Claude), and the maintainer reviews every change. Generative AI is not needed to work on it: the documents and the commands above are all you need. You may use generative AI for your contribution, but please: - review and test the result yourself before you submit it, and - say in the pull request that you used generative AI, and for what. --- ## 日本語 関心を持っていただき、ありがとうございます。不具合の報告、アイデア、翻訳、プルリクエストを歓迎します。 ### 始める前に - 不具合や要望は、まず [Issue](https://github.com/akiratamcat/joplin-plugin-dg-echarts/issues) を作ってください。 - セキュリティの問題は、公開の Issue に書かないでください。[SECURITY.ja.md](SECURITY.ja.md) をご覧ください。 - 設計は [docs/design.ja.md](docs/design.ja.md) にあります。`docs/` の文書は日本語だけで書いています(`*.ja.md`)。 - `design.ja.md`:設計書(要求、構成、テスト、リリース)。 - `lessons-learned.ja.md`:調査とテストで分かり、設計やコードを変えた事柄(ECharts の癖、Joplin の動き)。 - `spike-results.ja.md`:設計の前に行った試作の結果(Joplin の中で ECharts がどう動くか)。 - `owner-decisions.ja.md`:作者が決めた事項。 ### 開発の環境 - Node.js 22 以降と npm(CI は Node.js 22 を使います) - Google Chrome(描画テストで使います。ブラウザーのダウンロードは不要です) - プラグインを試すための、Joplin のデスクトップ版 3.1 以降 ```sh npm ci npm run dist # publish/io.github.akiratamcat.dg-echarts.jpl を作る ``` Joplin のプラグインの画面(ツール → オプション → プラグイン。macOS は Joplin → 設定 → プラグイン)の「ファイルからインストール」で `.jpl` を入れ、Joplin を再起動します。 ### 仕組み グラフは、Joplin が Markdown を HTML にするときに描きます。Markdown-it のコンテンツスクリプトが、同梱した ECharts を Node の `require` で読み込み、`echarts` のブロックごとに SVG の文字列を作って無害化し、HTML に直接入れます。そのため、グラフの表示にページのスクリプトは要らず、PDF と HTML のエクスポートにもそのまま出ます。ビューアスクリプトは、ツールバーを付けるだけです。`docs/design.ja.md` の 5章と 7章をご覧ください。 ### フォルダーの構成 | 場所 | 中身 | | ---- | ---- | | `src/index.ts` | メインスクリプト:設定、コンテンツスクリプトの登録、ツールバーの処理(コピー、保存) | | `src/contentScript/markdownItPlugin.ts` | Markdown-it のプラグイン:グラフごとに読み取り、検査、描画をして、HTML を作る | | `src/contentScript/` | エンジンの読み込み、入力の検査、テーマと文字サイズの調整、無害化、キャッシュ、ビューアスクリプト(ツールバー)、CodeMirror のプラグイン | | `src/shared/` | 複数のスクリプトが使うコード(フェンスの判定、設定のキー、字句解析、メッセージ) | | `src/i18n/` | gettext の実装。`catalog/catalogs.json` は `npm run i18n:compile` で作ります | | `vendor/echarts/` | ECharts のエンジンとロケールのファイル。手を加えずにコピーしたもの(`SOURCE.md` を参照) | | `locales/` | 翻訳(gettext の PO ファイル) | | `icons/` | プラグインのアイコン。`icon.svg`(独自の円グラフの図案。ECharts のロゴではない)と、それから作った PNG | | `scripts/` | 翻訳、ライセンス、README、公開前の検査 | | `tests/` | 単体テスト。`tests/render/` は描画テスト、`tests/manual/` は手動テストの手順と記録(`*.ja.md`、日本語)と Joplin に貼るテスト用のノート(`*.md`、英語)、`tests/evidence/` は手動テストで保存したファイル | ### コマンド | コマンド | すること | | -------- | -------- | | `npm run dist` | プラグインのパッケージ(`publish/*.jpl`)を作る | | `npm test` | 単体テストの後に描画テスト | | `npm run test:unit` | 翻訳の変換と検査、ライセンスと英日併記の文書の検査の後、単体テストと外部通信なしの静的検査(ビルドは不要) | | `npm run test:render` | ビルドの後、ビルドしたコンテンツスクリプトが作ったグラフを、通信を止めたヘッドレスの Chrome で表示して確かめる | | `npm run typecheck` | TypeScript の型チェック | | `npm run lint` | ESLint | | `npm run i18n:extract` | ソースコードから `locales/echarts.pot` とすべての PO ファイルを更新する | | `npm run i18n:check` | PO ファイルを検査する(置き換えの名前、複数形、fuzzy) | | `npm run i18n:compile` | PO ファイルから `src/i18n/catalog/catalogs.json` を作る(`dist`、`test:unit`、`typecheck` が実行する) | | `npm run notices` | `THIRD_PARTY_NOTICES.md` と `THIRD_PARTY_NOTICES.ja.md` を作り直す | | `npm run docs` | `README.ja.md`、`CONTRIBUTING.ja.md`、`SECURITY.ja.md`、`CHANGELOG.ja.md` を、英語版のファイルの後半(日本語)に写す | | `npm run docs:check` | 英語版のファイルの後半が `*.ja.md` と同じかを確かめる(`test:unit` が実行する) | | `npm run licenses:check` | 同梱するパッケージのライセンスと、ライセンス表示・版数の一覧・README の表が最新かを確かめる | | `npm run icons` | `icons/icon.svg` から、Google Chrome で PNG のアイコンを作る | | `npm run check:publish` | GitHub に push する前に、ブランチの履歴を調べる(メールアドレス、公開してはいけないファイル、秘密の情報、PC のパス)。作者が使うもの | プルリクエストを作る前に、`npm test`、`npm run typecheck`、`npm run lint` を実行してください。 描画テストでほかの Chromium を使うときは、その実行ファイルを `DG_CHROME_PATH` に入れてください。 ### ブランチとプルリクエスト GitHub Flow を使います。 - 長く続くブランチは `main` だけで、いつでもリリースできる状態にします。リリースは `main` のタグ `vX.Y.Z` です。 - `main` から、接頭辞を付けたブランチを作ります:`feature/…`(機能の追加や変更)、`fix/…`(不具合の修正)、`docs/…`(文書だけ)。 - `main` へのプルリクエストを作ります。CI(lint、型チェック、Windows・macOS・Linux でのテスト)が通ればマージできます。作者自身の変更もプルリクエストを通します。 - プルリクエストはマージコミットでマージします(squash や rebase のマージはしません)。作業ごとのまとまりが履歴に残るようにするためです。 - マージしたブランチは削除します(GitHub が自動で削除します)。コミットは `main` に残ります。 - リリースした版の修正は、`main` から作った `fix/…` のブランチで行い、新しい PATCH の版としてリリースします。古い版は修正しません。 - `spike/…` のブランチは、使い捨ての試作です。マージも push もしません。 ### 決まり - **ネットワーク通信をしない。** プラグインはネットワーク通信をしてはいけません(README を参照)。通信するコードや依存パッケージを加えないでください。静的検査(`tests/network.test.ts`)は新しい通信のコードで失敗し、描画テストはどんな通信でも失敗します。 - **入力の検査**(`src/contentScript/inputGuard.ts`)は、画像を読み込む設定や HTML を受け取る設定を取り除きます。禁止リストの方式なので、ECharts にそのような設定が増えたら、ここに加えてください。 - **ECharts のエンジン**(`vendor/echarts/`)は、手を加えずに使います(公式の圧縮版)。更新はセキュリティの修正か、必要な不具合の修正のときだけです。更新の手順は `vendor/echarts/SOURCE.md` にあります。 - **グラフのソースを JavaScript として実行しない。** グラフは JSON か YAML のデータだけです。 - **依存パッケージ**は、版をきっちり固定します。プラグインに入るパッケージは、`scripts/check-licenses.mjs` の許可リストにあるライセンスで、`scripts/notices.mjs`、`src/thirdParty.ts`、README の表にも載せる必要があります。 - **文書**:リポジトリの最上位のファイルには、英語版と日本語版(`*.ja.md`)があります。両方を更新するか、どちらの翻訳が要るかをプルリクエストに書いてください。GitHub と Joplin のプラグインのサイトは英語版のファイルだけを表示するので、`README.md`、`CONTRIBUTING.md`、`SECURITY.md`、`CHANGELOG.md` には、英語の文章と、その後に `*.ja.md` の写しがあります。`*.ja.md` を直して `npm run docs` を実行してください。英語版のファイルの日本語の部分を直接直さないでください。 - **変更履歴**:変更は `CHANGELOG.md` と `CHANGELOG.ja.md` の両方に書きます。GitHub のリリースノートは、両方から作ります(英語の後に日本語)。 ### 翻訳 翻訳は `locales/` の gettext の PO ファイル(`ja.po`、`de.po` など)なので、Poedit やテキストエディタで直せます。今の翻訳は生成 AI で作ったので、その言語を話す方の訂正をとても歓迎します。 - 訳を直すときは、`locales/<ロケール>.po` の `msgstr` を直し、`npm run i18n:check` を実行します。 - `{line}`、`{message}` などの置き換えの名前は、そのまま残します。ECharts の設定の名前(`series`、`xAxis` など)、`theme=dark`、`width=`、```` ```echarts ```` は訳しません。翻訳者向けの説明は `#.` のコメントです。 - ソースコードの文字を変えたら、`npm run i18n:extract` を実行して、`locales/echarts.pot` とすべての PO ファイルを更新します。 - 新しい言語には、`scripts/i18n-common.mjs` と `src/i18n/gettext.ts`(複数形の規則)への追加が要ります。日付の軸の月の名前は、`vendor/echarts/` の ECharts のロケールのファイルから来ます。 訳していない文字は英語で表示します。 ### 寄せられた変更のライセンス dg-echarts は MIT ライセンスで公開しています。変更(コード、翻訳、文書)を寄せることで、それが MIT ライセンスで提供されることに同意したものとします。 ### 生成 AI このプロジェクトは、生成 AI(Anthropic の Claude)を全面的に用いて開発しており、作者がすべての変更を確認しています。 参加するのに生成 AI は要りません。上の文書とコマンドだけで作業できます。 変更に生成 AI を使ってもかまいませんが、次のことをお願いします。 - 出す前に、結果を自分で確認し、テストしてください。 - 生成 AI を使ったことと、何に使ったかを、プルリクエストに書いてください。