@riebeckite/plugin-text-fragment 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +70 -70
  2. package/README_ja.md +57 -57
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,70 +1,70 @@
1
- # @riebeckite/plugin-text-fragment
2
-
3
- Copy a Text Fragment deep link (`#:~:text=`) or a Markdown quote for the text
4
- you select in an article.
5
-
6
- [日本語](./README_ja.md)
7
-
8
- ## Overview
9
-
10
- Client-only plugin. On page load it installs one selection popover with two
11
- actions:
12
-
13
- - **リンクをコピー** — builds a URL with a
14
- [Text Fragment directive](https://wicg.github.io/scroll-to-text-fragment/)
15
- that highlights the selected text.
16
- - **引用をコピー** — builds a Markdown block quote with a link back to the page.
17
-
18
- ## Usage
19
-
20
- ```ts
21
- import { defineConfig } from "@riebeckite/core";
22
- import { textFragmentPlugin } from "@riebeckite/plugin-text-fragment";
23
-
24
- export default defineConfig({
25
- // ...
26
- plugins: [textFragmentPlugin()],
27
- });
28
- ```
29
-
30
- `textFragmentPlugin()` registers `style.css` and the `initTextFragmentShare`
31
- client entry, which the app calls during page initialization.
32
-
33
- ## Behavior
34
-
35
- - A non-empty selection inside the article body shows the popover near the
36
- selection. Selections inside `pre`, `code`, `a[href]`, or `[data-no-share]`
37
- are ignored.
38
- - Both actions write to the clipboard through `navigator.clipboard.writeText`
39
- and fall back to a hidden textarea with `document.execCommand("copy")`.
40
- - Failures are announced in a visible `aria-live="polite"` status region.
41
- - `Escape` or a click outside closes the popover. The buttons are real
42
- `<button>` elements, so they are reachable with the keyboard.
43
- - The popover is installed once per page and does nothing when there is no
44
- `document` (SSR-safe).
45
-
46
- ### URL rules
47
-
48
- The fragment follows `#:~:text=[prefix-,]start[,end][,-suffix]`:
49
-
50
- - `,`, `-` and `&` are percent-encoded (`%2C`, `%2D`, `%26`).
51
- - Other characters are encoded per UTF-8 (newlines become `%0A`).
52
- - An existing hash on the page URL is dropped before the directive is appended.
53
- - Selections longer than ~200 characters or containing a newline are reduced to
54
- a `start,end` range built from the first and last token.
55
- - An empty or whitespace-only selection produces `""`.
56
-
57
- ## API
58
-
59
- - `textFragmentPlugin()` — plugin factory
60
- - `initTextFragmentShare()` — client initializer (also via
61
- `@riebeckite/plugin-text-fragment/client`)
62
- - `encodeTextFragment(text)` — percent-encodes one text fragment term
63
- - `buildTextFragmentUrl(pageUrl, selection, options?)` — builds the deep link;
64
- `options` is `{ prefix?, suffix? }`
65
- - `buildQuoteMarkdown({ url, title, selection })` — builds the Markdown quote
66
- - Type: `TextFragmentOptions`
67
-
68
- ## See also
69
-
70
- - [Plugin guide](../../../docs/en/plugin-system.md)
1
+ # @riebeckite/plugin-text-fragment
2
+
3
+ Copy a Text Fragment deep link (`#:~:text=`) or a Markdown quote for the text
4
+ you select in an article.
5
+
6
+ [日本語](./README_ja.md)
7
+
8
+ ## Overview
9
+
10
+ Client-only plugin. On page load it installs one selection popover with two
11
+ actions:
12
+
13
+ - **リンクをコピー** — builds a URL with a
14
+ [Text Fragment directive](https://wicg.github.io/scroll-to-text-fragment/)
15
+ that highlights the selected text.
16
+ - **引用をコピー** — builds a Markdown block quote with a link back to the page.
17
+
18
+ ## Usage
19
+
20
+ ```ts
21
+ import { defineConfig } from "@riebeckite/core";
22
+ import { textFragmentPlugin } from "@riebeckite/plugin-text-fragment";
23
+
24
+ export default defineConfig({
25
+ // ...
26
+ plugins: [textFragmentPlugin()],
27
+ });
28
+ ```
29
+
30
+ `textFragmentPlugin()` registers `style.css` and the `initTextFragmentShare`
31
+ client entry, which the app calls during page initialization.
32
+
33
+ ## Behavior
34
+
35
+ - A non-empty selection inside the article body shows the popover near the
36
+ selection. Selections inside `pre`, `code`, `a[href]`, or `[data-no-share]`
37
+ are ignored.
38
+ - Both actions write to the clipboard through `navigator.clipboard.writeText`
39
+ and fall back to a hidden textarea with `document.execCommand("copy")`.
40
+ - Failures are announced in a visible `aria-live="polite"` status region.
41
+ - `Escape` or a click outside closes the popover. The buttons are real
42
+ `<button>` elements, so they are reachable with the keyboard.
43
+ - The popover is installed once per page and does nothing when there is no
44
+ `document` (SSR-safe).
45
+
46
+ ### URL rules
47
+
48
+ The fragment follows `#:~:text=[prefix-,]start[,end][,-suffix]`:
49
+
50
+ - `,`, `-` and `&` are percent-encoded (`%2C`, `%2D`, `%26`).
51
+ - Other characters are encoded per UTF-8 (newlines become `%0A`).
52
+ - An existing hash on the page URL is dropped before the directive is appended.
53
+ - Selections longer than ~200 characters or containing a newline are reduced to
54
+ a `start,end` range built from the first and last token.
55
+ - An empty or whitespace-only selection produces `""`.
56
+
57
+ ## API
58
+
59
+ - `textFragmentPlugin()` — plugin factory
60
+ - `initTextFragmentShare()` — client initializer (also via
61
+ `@riebeckite/plugin-text-fragment/client`)
62
+ - `encodeTextFragment(text)` — percent-encodes one text fragment term
63
+ - `buildTextFragmentUrl(pageUrl, selection, options?)` — builds the deep link;
64
+ `options` is `{ prefix?, suffix? }`
65
+ - `buildQuoteMarkdown({ url, title, selection })` — builds the Markdown quote
66
+ - Type: `TextFragmentOptions`
67
+
68
+ ## See also
69
+
70
+ - [Plugin guide](../../../docs/en/reference/plugin-api.md)
package/README_ja.md CHANGED
@@ -1,57 +1,57 @@
1
- # @riebeckite/plugin-text-fragment
2
-
3
- 記事内で選択したテキストから、Text Fragment のディープリンク(`#:~:text=`)と Markdown の引用を作るプラグインです。
4
-
5
- [English](./README.md)
6
-
7
- ## できること
8
-
9
- クライアント専用のプラグインです。ページ表示時に、選択範囲のそばへ小さなポップオーバーを出し、次の二つをコピーできます。
10
-
11
- - **リンクをコピー**: 選択したテキストをハイライトする [Text Fragment](https://wicg.github.io/scroll-to-text-fragment/) 付き URL を作ります。
12
- - **引用をコピー**: ページへのリンク付きで Markdown の引用ブロックを作ります。
13
-
14
- ## 設定する
15
-
16
- ```ts
17
- import { defineConfig } from "@riebeckite/core";
18
- import { textFragmentPlugin } from "@riebeckite/plugin-text-fragment";
19
-
20
- export default defineConfig({
21
- // ...
22
- plugins: [textFragmentPlugin()],
23
- });
24
- ```
25
-
26
- `textFragmentPlugin()` はスタイルと `initTextFragmentShare` を登録します。初期化処理はアプリのページ初期化時に呼ばれます。
27
-
28
- ## 挙動
29
-
30
- - 記事本文内でテキストを選択すると、そのそばにポップオーバーが出ます。`pre`、`code`、`a[href]`、`[data-no-share]` の中の選択は対象外です。
31
- - コピーは `navigator.clipboard.writeText` を使い、失敗時は隠し textarea と `document.execCommand("copy")` に切り替えます。
32
- - コピーに失敗したときは `aria-live="polite"` の領域にメッセージを表示します。
33
- - `Escape` またはポップオーバーの外側をクリックすると閉じます。ボタンは実体の `<button>` なのでキーボードでも操作できます。
34
- - 初期化はページごとに一度だけで、`document` が無い環境では何もしません。
35
-
36
- ### URL の規則
37
-
38
- フラグメントは `#:~:text=[prefix-,]start[,end][,-suffix]` に従います。
39
-
40
- - `,`、`-`、`&` はパーセントエンコードします(`%2C`、`%2D`、`%26`)。
41
- - それ以外は UTF-8 単位でエンコードします(改行は `%0A`)。
42
- - ページ URL に既存のハッシュがあるときは、それを外してからディレクティブを付けます。
43
- - 200 文字前後より長い選択、または改行を含む選択は、先頭と末尾のトークンによる `start,end` に短縮します。
44
- - 空または空白だけの選択は `""` を返します。
45
-
46
- ## 公開 API
47
-
48
- - `textFragmentPlugin()` — プラグインファクトリ
49
- - `initTextFragmentShare()` — ブラウザ初期化関数(`@riebeckite/plugin-text-fragment/client` からも読み込める)
50
- - `encodeTextFragment(text)` — テキスト片をパーセントエンコードする
51
- - `buildTextFragmentUrl(pageUrl, selection, options?)` — ディープリンクを作る。`options` は `{ prefix?, suffix? }`
52
- - `buildQuoteMarkdown({ url, title, selection })` — 引用ブロックを作る
53
- - `TextFragmentOptions` — オプションの型
54
-
55
- ## 関連資料
56
-
57
- - [プラグインシステム](../../../docs/ja/plugin-system.md)
1
+ # @riebeckite/plugin-text-fragment
2
+
3
+ 記事内で選択したテキストから、Text Fragment のディープリンク(`#:~:text=`)と Markdown の引用を作るプラグインです。
4
+
5
+ [English](./README.md)
6
+
7
+ ## できること
8
+
9
+ クライアント専用のプラグインです。ページ表示時に、選択範囲のそばへ小さなポップオーバーを出し、次の二つをコピーできます。
10
+
11
+ - **リンクをコピー**: 選択したテキストをハイライトする [Text Fragment](https://wicg.github.io/scroll-to-text-fragment/) 付き URL を作ります。
12
+ - **引用をコピー**: ページへのリンク付きで Markdown の引用ブロックを作ります。
13
+
14
+ ## 設定する
15
+
16
+ ```ts
17
+ import { defineConfig } from "@riebeckite/core";
18
+ import { textFragmentPlugin } from "@riebeckite/plugin-text-fragment";
19
+
20
+ export default defineConfig({
21
+ // ...
22
+ plugins: [textFragmentPlugin()],
23
+ });
24
+ ```
25
+
26
+ `textFragmentPlugin()` はスタイルと `initTextFragmentShare` を登録します。初期化処理はアプリのページ初期化時に呼ばれます。
27
+
28
+ ## 挙動
29
+
30
+ - 記事本文内でテキストを選択すると、そのそばにポップオーバーが出ます。`pre`、`code`、`a[href]`、`[data-no-share]` の中の選択は対象外です。
31
+ - コピーは `navigator.clipboard.writeText` を使い、失敗時は隠し textarea と `document.execCommand("copy")` に切り替えます。
32
+ - コピーに失敗したときは `aria-live="polite"` の領域にメッセージを表示します。
33
+ - `Escape` またはポップオーバーの外側をクリックすると閉じます。ボタンは実体の `<button>` なのでキーボードでも操作できます。
34
+ - 初期化はページごとに一度だけで、`document` が無い環境では何もしません。
35
+
36
+ ### URL の規則
37
+
38
+ フラグメントは `#:~:text=[prefix-,]start[,end][,-suffix]` に従います。
39
+
40
+ - `,`、`-`、`&` はパーセントエンコードします(`%2C`、`%2D`、`%26`)。
41
+ - それ以外は UTF-8 単位でエンコードします(改行は `%0A`)。
42
+ - ページ URL に既存のハッシュがあるときは、それを外してからディレクティブを付けます。
43
+ - 200 文字前後より長い選択、または改行を含む選択は、先頭と末尾のトークンによる `start,end` に短縮します。
44
+ - 空または空白だけの選択は `""` を返します。
45
+
46
+ ## 公開 API
47
+
48
+ - `textFragmentPlugin()` — プラグインファクトリ
49
+ - `initTextFragmentShare()` — ブラウザ初期化関数(`@riebeckite/plugin-text-fragment/client` からも読み込める)
50
+ - `encodeTextFragment(text)` — テキスト片をパーセントエンコードする
51
+ - `buildTextFragmentUrl(pageUrl, selection, options?)` — ディープリンクを作る。`options` は `{ prefix?, suffix? }`
52
+ - `buildQuoteMarkdown({ url, title, selection })` — 引用ブロックを作る
53
+ - `TextFragmentOptions` — オプションの型
54
+
55
+ ## 関連資料
56
+
57
+ - [プラグインシステム](../../../docs/ja/reference/plugin-api.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-text-fragment",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "./style.css": "./style.css"
22
22
  },
23
23
  "dependencies": {
24
- "@riebeckite/core": "0.0.11"
24
+ "@riebeckite/core": "0.0.13"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsx": "^4.22.4"