@riebeckite/plugin-highlight 0.0.1
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.
- package/LICENSE +201 -0
- package/README.md +91 -0
- package/README_ja.md +91 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +103 -0
- package/dist/src/remark.d.ts +3 -0
- package/dist/src/types.d.ts +7 -0
- package/package.json +57 -0
- package/style.css +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright Rerurate_514
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @riebeckite/plugin-highlight
|
|
2
|
+
|
|
3
|
+
Inline `==highlight==` support. Text wrapped in double equals is rendered as a
|
|
4
|
+
`<mark>` element at build time.
|
|
5
|
+
|
|
6
|
+
[日本語](./README_ja.md)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
`highlight()` registers a remark transformer that rewrites `==text==` in
|
|
11
|
+
Markdown text nodes into raw HTML before the tree is converted to HTML. It
|
|
12
|
+
complements `remark-gfm` (which only understands `~~strikethrough~~`).
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { defineConfig } from "@riebeckite/core";
|
|
18
|
+
import { highlight } from "@riebeckite/plugin-highlight";
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
// ...
|
|
22
|
+
plugins: [highlight()],
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Syntax
|
|
27
|
+
|
|
28
|
+
```md
|
|
29
|
+
This sentence has a ==highlighted phrase== inside it.
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Output:
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
This sentence has a <mark class="rb-highlight">highlighted phrase</mark> inside it.
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Highlights are matched non-greedily, must stay on a single line, and are
|
|
39
|
+
ignored when they are empty or contain only whitespace. Matches inside code
|
|
40
|
+
blocks, inline code, raw HTML, and frontmatter are left untouched.
|
|
41
|
+
|
|
42
|
+
## Options
|
|
43
|
+
|
|
44
|
+
| Option | Type | Default | Description |
|
|
45
|
+
| ------ | ---- | ------- | ----------- |
|
|
46
|
+
| `className` | `string` | `"rb-highlight"` | CSS class on each generated element |
|
|
47
|
+
| `tag` | `string` | `"mark"` | HTML tag used for the highlight |
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
highlight({ className: "my-highlight", tag: "span" });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Styling
|
|
54
|
+
|
|
55
|
+
The package ships `style.css`, exposed as
|
|
56
|
+
`@riebeckite/plugin-highlight/style.css`. The default rule styles
|
|
57
|
+
`.rb-highlight` with a subtle accent background and falls back to the
|
|
58
|
+
`--rb-color-accent` theme variable when available:
|
|
59
|
+
|
|
60
|
+
```css
|
|
61
|
+
.rb-highlight {
|
|
62
|
+
--rb-highlight-accent: var(--rb-color-accent, #f6d365);
|
|
63
|
+
padding: 0.05em 0.25em;
|
|
64
|
+
border-radius: 0.2em;
|
|
65
|
+
background: color-mix(in srgb, var(--rb-highlight-accent) 45%, transparent);
|
|
66
|
+
color: inherit;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Because the plugin registers a style asset, the host site includes this
|
|
71
|
+
stylesheet automatically; override the class or supply your own CSS to change
|
|
72
|
+
the appearance.
|
|
73
|
+
|
|
74
|
+
## Limitations
|
|
75
|
+
|
|
76
|
+
- A highlight never spans multiple text nodes or lines, so `==` delimiters
|
|
77
|
+
cannot wrap other Markdown (links, emphasis, code) or line breaks.
|
|
78
|
+
- Nested highlights are not supported; the innermost `==` pair wins.
|
|
79
|
+
- The transformer emits raw HTML, so enable raw HTML output in the pipeline
|
|
80
|
+
(the default Riebeckite pipeline does).
|
|
81
|
+
|
|
82
|
+
## Exports
|
|
83
|
+
|
|
84
|
+
- `highlight(options?)` — plugin factory
|
|
85
|
+
- `highlightPlugin` — alias of `highlight`
|
|
86
|
+
- `remarkHighlight(options?)` — the underlying remark transformer
|
|
87
|
+
- Type: `HighlightOptions`
|
|
88
|
+
|
|
89
|
+
## See also
|
|
90
|
+
|
|
91
|
+
- [Plugin guide](../../../docs/en/plugin-system.md)
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @riebeckite/plugin-highlight
|
|
2
|
+
|
|
3
|
+
`==ハイライト==` を `<mark>` 要素として表示するプラグインです。Markdown の
|
|
4
|
+
テキストノードをビルド時に書き換えます。
|
|
5
|
+
|
|
6
|
+
[English](./README.md)
|
|
7
|
+
|
|
8
|
+
## 概要
|
|
9
|
+
|
|
10
|
+
`highlight()` は、Markdown のテキストノードにある `==テキスト==` を HTML に
|
|
11
|
+
変換する前に生の HTML へ置き換える remark トランスフォーマーを登録します。
|
|
12
|
+
`~~打ち消し線~~` だけを扱う `remark-gfm` を補完します。
|
|
13
|
+
|
|
14
|
+
## 設定する
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { defineConfig } from "@riebeckite/core";
|
|
18
|
+
import { highlight } from "@riebeckite/plugin-highlight";
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
// ...
|
|
22
|
+
plugins: [highlight()],
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 構文
|
|
27
|
+
|
|
28
|
+
```md
|
|
29
|
+
この文には ==ハイライトする語句== が含まれます。
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
出力:
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
この文には <mark class="rb-highlight">ハイライトする語句</mark> が含まれます。
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
ハイライトは非貪欲に一致し、改行をまたぎません。空、または空白だけの
|
|
39
|
+
ハイライトは無視します。コードブロック、インラインコード、生の HTML、
|
|
40
|
+
フロントマターの内部は変更しません。
|
|
41
|
+
|
|
42
|
+
## オプション
|
|
43
|
+
|
|
44
|
+
| 項目 | 型 | 既定値 | 説明 |
|
|
45
|
+
| --- | --- | --- | --- |
|
|
46
|
+
| `className` | `string` | `"rb-highlight"` | 生成する要素に付ける CSS クラス |
|
|
47
|
+
| `tag` | `string` | `"mark"` | ハイライトに使う HTML タグ |
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
highlight({ className: "my-highlight", tag: "span" });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## スタイル
|
|
54
|
+
|
|
55
|
+
このパッケージは `style.css` を同梱し、
|
|
56
|
+
`@riebeckite/plugin-highlight/style.css` として公開します。既定のルールは
|
|
57
|
+
`.rb-highlight` に控えめなアクセント背景を付け、テーマ変数
|
|
58
|
+
`--rb-color-accent` があればそれを使います。
|
|
59
|
+
|
|
60
|
+
```css
|
|
61
|
+
.rb-highlight {
|
|
62
|
+
--rb-highlight-accent: var(--rb-color-accent, #f6d365);
|
|
63
|
+
padding: 0.05em 0.25em;
|
|
64
|
+
border-radius: 0.2em;
|
|
65
|
+
background: color-mix(in srgb, var(--rb-highlight-accent) 45%, transparent);
|
|
66
|
+
color: inherit;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
プラグインはスタイルアセットを登録するため、ホスト側のサイトはこの
|
|
71
|
+
スタイルシートを自動的に取り込みます。見た目を変えたい場合はクラスを指定する
|
|
72
|
+
か、独自の CSS で上書きしてください。
|
|
73
|
+
|
|
74
|
+
## 制限
|
|
75
|
+
|
|
76
|
+
- ハイライトは複数のテキストノードや行をまたげません。`==` で他の Markdown
|
|
77
|
+
(リンク、強調、コード) や改行を囲むことはできません。
|
|
78
|
+
- 入れ子のハイライトには対応しません。最も内側の `==` の組が優先されます。
|
|
79
|
+
- 生の HTML を出力するため、パイプラインで生 HTML の出力を有効にする必要が
|
|
80
|
+
あります(Riebeckite の既定パイプラインでは有効です)。
|
|
81
|
+
|
|
82
|
+
## 主なエクスポート
|
|
83
|
+
|
|
84
|
+
- `highlight(options?)`: プラグインを作成する
|
|
85
|
+
- `highlightPlugin`: `highlight` の別名
|
|
86
|
+
- `remarkHighlight(options?)`: 内部の remark トランスフォーマー
|
|
87
|
+
- 型: `HighlightOptions`
|
|
88
|
+
|
|
89
|
+
## 関連資料
|
|
90
|
+
|
|
91
|
+
- [プラグインガイド](../../../docs/ja/plugin-system.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HighlightOptions } from "./src/types.js";
|
|
2
|
+
export { remarkHighlight } from "./src/remark.js";
|
|
3
|
+
export type { HighlightOptions } from "./src/types.js";
|
|
4
|
+
export declare function highlight(options?: HighlightOptions): import("@riebeckite/core").RiebeckitePlugin<HighlightOptions>;
|
|
5
|
+
/** Alias kept for parity with plugins that export a `…Plugin` factory. */
|
|
6
|
+
export declare const highlightPlugin: typeof highlight;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import {
|
|
3
|
+
createStyleAsset,
|
|
4
|
+
definePlugin
|
|
5
|
+
} from "@riebeckite/core";
|
|
6
|
+
|
|
7
|
+
// src/remark.ts
|
|
8
|
+
import { escapeHtml, escapeHtmlAttribute } from "@riebeckite/core";
|
|
9
|
+
import { visit } from "unist-util-visit";
|
|
10
|
+
var DEFAULT_CLASS_NAME = "rb-highlight";
|
|
11
|
+
var DEFAULT_TAG = "mark";
|
|
12
|
+
var HIGHLIGHT_PATTERN = /==([^=\n]+?)==/g;
|
|
13
|
+
var SKIPPED_PARENT_TYPES = /* @__PURE__ */ new Set([
|
|
14
|
+
"code",
|
|
15
|
+
"inlineCode",
|
|
16
|
+
"html",
|
|
17
|
+
"yaml",
|
|
18
|
+
"toml"
|
|
19
|
+
]);
|
|
20
|
+
var TAG_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9-]*$/;
|
|
21
|
+
function remarkHighlight(options = {}) {
|
|
22
|
+
const className = options.className ?? DEFAULT_CLASS_NAME;
|
|
23
|
+
const tag = resolveTag(options.tag);
|
|
24
|
+
return (tree) => {
|
|
25
|
+
visit(tree, "text", (node, index, parent) => {
|
|
26
|
+
if (!parent || index === void 0) return;
|
|
27
|
+
if (SKIPPED_PARENT_TYPES.has(parent.type)) return;
|
|
28
|
+
if (!node.value.includes("==")) return;
|
|
29
|
+
const newNodes = splitHighlights(node.value, className, tag);
|
|
30
|
+
if (!newNodes) return;
|
|
31
|
+
parent.children.splice(index, 1, ...newNodes);
|
|
32
|
+
return index + newNodes.length;
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function splitHighlights(value, className, tag) {
|
|
37
|
+
const newNodes = [];
|
|
38
|
+
let lastIndex = 0;
|
|
39
|
+
let matched = false;
|
|
40
|
+
const highlightRe = new RegExp(HIGHLIGHT_PATTERN.source, "g");
|
|
41
|
+
for (let match = highlightRe.exec(value); match !== null; match = highlightRe.exec(value)) {
|
|
42
|
+
const [full, highlighted] = match;
|
|
43
|
+
if (highlighted.trim().length === 0) continue;
|
|
44
|
+
const start = match.index;
|
|
45
|
+
if (start > lastIndex) {
|
|
46
|
+
newNodes.push({
|
|
47
|
+
type: "text",
|
|
48
|
+
value: value.slice(lastIndex, start)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
newNodes.push(createHighlightNode(highlighted, className, tag));
|
|
52
|
+
lastIndex = start + full.length;
|
|
53
|
+
matched = true;
|
|
54
|
+
}
|
|
55
|
+
if (!matched) return null;
|
|
56
|
+
if (lastIndex < value.length) {
|
|
57
|
+
newNodes.push({ type: "text", value: value.slice(lastIndex) });
|
|
58
|
+
}
|
|
59
|
+
return newNodes;
|
|
60
|
+
}
|
|
61
|
+
function createHighlightNode(value, className, tag) {
|
|
62
|
+
return {
|
|
63
|
+
type: "html",
|
|
64
|
+
value: `<${tag} class="${escapeHtmlAttribute(className)}">${escapeHtml(value)}</${tag}>`
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function resolveTag(tag) {
|
|
68
|
+
return tag && TAG_NAME_PATTERN.test(tag) ? tag : DEFAULT_TAG;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// index.ts
|
|
72
|
+
var TAG_NAME_PATTERN2 = /^[a-zA-Z][a-zA-Z0-9-]*$/;
|
|
73
|
+
function highlight(options = {}) {
|
|
74
|
+
return definePlugin({
|
|
75
|
+
name: "highlight",
|
|
76
|
+
options,
|
|
77
|
+
validateOptions: validateHighlightOptions,
|
|
78
|
+
extendMarkdownPipeline: (pipeline) => {
|
|
79
|
+
pipeline.use(remarkHighlight, options);
|
|
80
|
+
},
|
|
81
|
+
assets: [createStyleAsset("highlight")]
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
var highlightPlugin = highlight;
|
|
85
|
+
function validateHighlightOptions(options) {
|
|
86
|
+
if (!options) return [];
|
|
87
|
+
const issues = [];
|
|
88
|
+
if (options.className !== void 0 && typeof options.className !== "string") {
|
|
89
|
+
issues.push({ path: "className", message: "Expected a string." });
|
|
90
|
+
}
|
|
91
|
+
if (options.tag !== void 0 && (typeof options.tag !== "string" || !TAG_NAME_PATTERN2.test(options.tag))) {
|
|
92
|
+
issues.push({
|
|
93
|
+
path: "tag",
|
|
94
|
+
message: 'Expected an HTML tag name such as "mark".'
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return issues;
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
highlight,
|
|
101
|
+
highlightPlugin,
|
|
102
|
+
remarkHighlight
|
|
103
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@riebeckite/plugin-highlight",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"source": "./index.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./style.css": "./style.css"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@types/mdast": "^4.0.4",
|
|
19
|
+
"unist-util-visit": "^5.1.0",
|
|
20
|
+
"@riebeckite/core": "0.0.1"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"README.md",
|
|
28
|
+
"README_ja.md",
|
|
29
|
+
"dist",
|
|
30
|
+
"style.css"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/Rerurate514/riebeckite.git",
|
|
35
|
+
"directory": "packages/plugins/highlight"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/Rerurate514/riebeckite#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/Rerurate514/riebeckite/issues"
|
|
40
|
+
},
|
|
41
|
+
"description": "Obsidian-style inline text highlighting for Riebeckite.",
|
|
42
|
+
"keywords": [
|
|
43
|
+
"riebeckite",
|
|
44
|
+
"plugin",
|
|
45
|
+
"markdown",
|
|
46
|
+
"highlight"
|
|
47
|
+
],
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
50
|
+
},
|
|
51
|
+
"sideEffects": [
|
|
52
|
+
"./style.css"
|
|
53
|
+
],
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "node ../../../scripts/build_package.mjs"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/style.css
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.rb-highlight {
|
|
2
|
+
--rb-highlight-accent: var(--rb-color-accent, #f6d365);
|
|
3
|
+
padding: 0.05em 0.25em;
|
|
4
|
+
border-radius: 0.2em;
|
|
5
|
+
background: color-mix(in srgb, var(--rb-highlight-accent) 45%, transparent);
|
|
6
|
+
color: inherit;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
html[data-theme="dark"] .rb-highlight,
|
|
10
|
+
html.dark .rb-highlight {
|
|
11
|
+
--rb-highlight-accent: var(--rb-color-accent, #ffd166);
|
|
12
|
+
background: color-mix(in srgb, var(--rb-highlight-accent) 32%, transparent);
|
|
13
|
+
}
|