micromark-extension-cjk-friendly 1.1.0 → 1.2.0-rc.2

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.
@@ -1,17 +1,5 @@
1
- import { Resolver, TokenizeContext, Effects, State } from 'micromark-util-types';
1
+ import { Construct } from 'micromark-util-types';
2
2
 
3
- /** @type {Construct} */
4
- declare const attention: {
5
- name: string;
6
- resolveAll: typeof resolveAllAttention;
7
- tokenize: typeof tokenizeAttention;
8
- };
9
- declare function resolveAllAttention(events: Parameters<Resolver>[0], context: Parameters<Resolver>[1]): ReturnType<Resolver>;
10
- /**
11
- * @this {TokenizeContext}
12
- * Context.
13
- * @type {Tokenizer}
14
- */
15
- declare function tokenizeAttention(this: TokenizeContext, effects: Effects, ok: State): State;
3
+ declare const attention: Construct;
16
4
 
17
5
  export { attention };
@@ -2,18 +2,18 @@
2
2
  import { ok as assert } from "devlop";
3
3
  import {
4
4
  classifyCharacter,
5
+ classifyPrecedingCharacter,
5
6
  isCjk,
7
+ isCjkOrIvs,
6
8
  isCodeHighSurrogate,
7
9
  isCodeLowSurrogate,
8
- isIvs,
9
10
  isNonCjkPunctuation,
10
11
  isSpaceOrPunctuation,
11
- isSvsFollowingCjk,
12
12
  isUnicodeWhitespace,
13
- tryGetCodeTwoBefore,
14
13
  tryGetGenuineNextCode,
15
14
  tryGetGenuinePreviousCode
16
15
  } from "micromark-extension-cjk-friendly-util";
16
+ import { TwoPreviousCode } from "micromark-extension-cjk-friendly-util";
17
17
  import { push, splice } from "micromark-util-chunked";
18
18
  import { resolveAll } from "micromark-util-resolve-all";
19
19
  import { codes, types } from "micromark-util-symbol";
@@ -131,16 +131,12 @@ function tokenizeAttention(effects, ok) {
131
131
  tryGetGenuinePreviousCode(tentativePrevious, now(), sliceSerialize)
132
132
  ) : tentativePrevious;
133
133
  const before = classifyCharacter(previous);
134
- let beforePrimary = before;
135
- if (isSvsFollowingCjk(before)) {
136
- const twoPrevious = tryGetCodeTwoBefore(
137
- // biome-ignore lint/style/noNonNullAssertion: if `previous` were null, before would be `undefined`
138
- previous,
139
- now(),
140
- sliceSerialize
141
- );
142
- if (twoPrevious !== null) beforePrimary = classifyCharacter(twoPrevious);
143
- }
134
+ const twoPrevious = new TwoPreviousCode(previous, now(), sliceSerialize);
135
+ const beforePrimary = classifyPrecedingCharacter(
136
+ before,
137
+ twoPrevious.value.bind(twoPrevious),
138
+ previous
139
+ );
144
140
  let marker;
145
141
  return start;
146
142
  function start(code) {
@@ -161,15 +157,15 @@ function tokenizeAttention(effects, ok) {
161
157
  const next = isCodeHighSurrogate(code) ? tryGetGenuineNextCode(code, now(), sliceSerialize) : code;
162
158
  const after = classifyCharacter(next);
163
159
  assert(attentionMarkers, "expected `attentionMarkers` to be populated");
164
- const beforeNonCjkPunctuation = isNonCjkPunctuation(before);
165
- const beforeSpaceOrNonCjkPunctuation = beforeNonCjkPunctuation || isUnicodeWhitespace(before);
160
+ const beforeNonCjkPunctuation = isNonCjkPunctuation(beforePrimary);
161
+ const beforeSpaceOrNonCjkPunctuation = beforeNonCjkPunctuation || isUnicodeWhitespace(beforePrimary);
166
162
  const afterNonCjkPunctuation = isNonCjkPunctuation(after);
167
163
  const afterSpaceOrNonCjkPunctuation = afterNonCjkPunctuation || isUnicodeWhitespace(after);
168
- const beforeCjkOrIvs = isCjk(beforePrimary) || isIvs(before);
164
+ const beforeCjkOrIvs = isCjkOrIvs(beforePrimary);
169
165
  const open = !afterSpaceOrNonCjkPunctuation || afterNonCjkPunctuation && (beforeSpaceOrNonCjkPunctuation || beforeCjkOrIvs) || attentionMarkers.includes(code);
170
166
  const close = !beforeSpaceOrNonCjkPunctuation || beforeNonCjkPunctuation && (afterSpaceOrNonCjkPunctuation || isCjk(after)) || attentionMarkers.includes(previous);
171
167
  token._open = Boolean(
172
- marker === codes.asterisk ? open : open && (isSpaceOrPunctuation(before) || !close)
168
+ marker === codes.asterisk ? open : open && (isSpaceOrPunctuation(beforePrimary) || !close)
173
169
  );
174
170
  token._close = Boolean(
175
171
  marker === codes.asterisk ? close : close && (isSpaceOrPunctuation(after) || !open)
package/dist/index.js CHANGED
@@ -5,18 +5,18 @@ import { codes as codes2 } from "micromark-util-symbol";
5
5
  import { ok as assert } from "devlop";
6
6
  import {
7
7
  classifyCharacter,
8
+ classifyPrecedingCharacter,
8
9
  isCjk,
10
+ isCjkOrIvs,
9
11
  isCodeHighSurrogate,
10
12
  isCodeLowSurrogate,
11
- isIvs,
12
13
  isNonCjkPunctuation,
13
14
  isSpaceOrPunctuation,
14
- isSvsFollowingCjk,
15
15
  isUnicodeWhitespace,
16
- tryGetCodeTwoBefore,
17
16
  tryGetGenuineNextCode,
18
17
  tryGetGenuinePreviousCode
19
18
  } from "micromark-extension-cjk-friendly-util";
19
+ import { TwoPreviousCode } from "micromark-extension-cjk-friendly-util";
20
20
  import { push, splice } from "micromark-util-chunked";
21
21
  import { resolveAll } from "micromark-util-resolve-all";
22
22
  import { codes, types } from "micromark-util-symbol";
@@ -134,16 +134,12 @@ function tokenizeAttention(effects, ok) {
134
134
  tryGetGenuinePreviousCode(tentativePrevious, now(), sliceSerialize)
135
135
  ) : tentativePrevious;
136
136
  const before = classifyCharacter(previous);
137
- let beforePrimary = before;
138
- if (isSvsFollowingCjk(before)) {
139
- const twoPrevious = tryGetCodeTwoBefore(
140
- // biome-ignore lint/style/noNonNullAssertion: if `previous` were null, before would be `undefined`
141
- previous,
142
- now(),
143
- sliceSerialize
144
- );
145
- if (twoPrevious !== null) beforePrimary = classifyCharacter(twoPrevious);
146
- }
137
+ const twoPrevious = new TwoPreviousCode(previous, now(), sliceSerialize);
138
+ const beforePrimary = classifyPrecedingCharacter(
139
+ before,
140
+ twoPrevious.value.bind(twoPrevious),
141
+ previous
142
+ );
147
143
  let marker;
148
144
  return start;
149
145
  function start(code) {
@@ -164,15 +160,15 @@ function tokenizeAttention(effects, ok) {
164
160
  const next = isCodeHighSurrogate(code) ? tryGetGenuineNextCode(code, now(), sliceSerialize) : code;
165
161
  const after = classifyCharacter(next);
166
162
  assert(attentionMarkers, "expected `attentionMarkers` to be populated");
167
- const beforeNonCjkPunctuation = isNonCjkPunctuation(before);
168
- const beforeSpaceOrNonCjkPunctuation = beforeNonCjkPunctuation || isUnicodeWhitespace(before);
163
+ const beforeNonCjkPunctuation = isNonCjkPunctuation(beforePrimary);
164
+ const beforeSpaceOrNonCjkPunctuation = beforeNonCjkPunctuation || isUnicodeWhitespace(beforePrimary);
169
165
  const afterNonCjkPunctuation = isNonCjkPunctuation(after);
170
166
  const afterSpaceOrNonCjkPunctuation = afterNonCjkPunctuation || isUnicodeWhitespace(after);
171
- const beforeCjkOrIvs = isCjk(beforePrimary) || isIvs(before);
167
+ const beforeCjkOrIvs = isCjkOrIvs(beforePrimary);
172
168
  const open = !afterSpaceOrNonCjkPunctuation || afterNonCjkPunctuation && (beforeSpaceOrNonCjkPunctuation || beforeCjkOrIvs) || attentionMarkers.includes(code);
173
169
  const close = !beforeSpaceOrNonCjkPunctuation || beforeNonCjkPunctuation && (afterSpaceOrNonCjkPunctuation || isCjk(after)) || attentionMarkers.includes(previous);
174
170
  token._open = Boolean(
175
- marker === codes.asterisk ? open : open && (isSpaceOrPunctuation(before) || !close)
171
+ marker === codes.asterisk ? open : open && (isSpaceOrPunctuation(beforePrimary) || !close)
176
172
  );
177
173
  token._close = Boolean(
178
174
  marker === codes.asterisk ? close : close && (isSpaceOrPunctuation(after) || !open)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "micromark-extension-cjk-friendly",
3
- "version": "1.1.0",
3
+ "version": "1.2.0-rc.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -37,7 +37,7 @@
37
37
  "micromark-util-chunked": "^2.0.0",
38
38
  "micromark-util-resolve-all": "^2.0.0",
39
39
  "micromark-util-symbol": "^2.0.0",
40
- "micromark-extension-cjk-friendly-util": "^1.1.0"
40
+ "micromark-extension-cjk-friendly-util": "^2.0.0-rc.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "micromark": "^4.0.1",