@peaceroad/markdown-it-cjk-breaks-mod 0.1.8 → 0.1.9
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/index.js +32 -21
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -239,7 +239,6 @@ function process_inlines(tokens, ctx, inlineToken) {
|
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
var lastTextContent = '';
|
|
242
|
-
var hasLastText = false;
|
|
243
242
|
var sawEmptySinceLast = false;
|
|
244
243
|
|
|
245
244
|
for (i = 0; i < tokens.length; i++) {
|
|
@@ -261,7 +260,7 @@ function process_inlines(tokens, ctx, inlineToken) {
|
|
|
261
260
|
skippedEmptyAfter = nextSkippedEmpty ? nextSkippedEmpty[i] : false;
|
|
262
261
|
}
|
|
263
262
|
|
|
264
|
-
if (
|
|
263
|
+
if (lastTextContent) {
|
|
265
264
|
c1 = lastTextContent.charCodeAt(lastTextContent.length - 2);
|
|
266
265
|
c2 = lastTextContent.charCodeAt(lastTextContent.length - 1);
|
|
267
266
|
last = lastTextContent.slice(is_surrogate(c1, c2) ? -2 : -1);
|
|
@@ -305,7 +304,7 @@ function process_inlines(tokens, ctx, inlineToken) {
|
|
|
305
304
|
|
|
306
305
|
if (remove_break) {
|
|
307
306
|
var insertPunctuationSpace = false;
|
|
308
|
-
if (needsPunctuation &&
|
|
307
|
+
if (needsPunctuation && lastTextContent && nextIdx !== -1 && next !== '\u200b') {
|
|
309
308
|
if (punctuationEndCharMap[last]) {
|
|
310
309
|
if (matches_punctuation_sequence(lastTextContent, punctuationConfig, true)) {
|
|
311
310
|
if (!nextWidthComputed) {
|
|
@@ -326,7 +325,6 @@ function process_inlines(tokens, ctx, inlineToken) {
|
|
|
326
325
|
if (considerInlineBoundaries) sawEmptySinceLast = true;
|
|
327
326
|
} else {
|
|
328
327
|
lastTextContent = token.content;
|
|
329
|
-
hasLastText = true;
|
|
330
328
|
if (considerInlineBoundaries) sawEmptySinceLast = false;
|
|
331
329
|
}
|
|
332
330
|
}
|
|
@@ -372,21 +370,29 @@ function split_text_token(token) {
|
|
|
372
370
|
var parts = [];
|
|
373
371
|
var content = token.content;
|
|
374
372
|
var start = 0;
|
|
373
|
+
var reusedToken = false;
|
|
374
|
+
|
|
375
|
+
function push_text_part(text) {
|
|
376
|
+
if (!text) return;
|
|
377
|
+
if (!reusedToken) {
|
|
378
|
+
token.content = text;
|
|
379
|
+
parts.push(token);
|
|
380
|
+
reusedToken = true;
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
parts.push(clone_text_token(TokenConstructor, token, text));
|
|
384
|
+
}
|
|
375
385
|
|
|
376
386
|
for (var pos = 0; pos < content.length; pos++) {
|
|
377
387
|
if (content.charCodeAt(pos) !== 0x0A) continue;
|
|
378
388
|
|
|
379
|
-
if (pos > start)
|
|
380
|
-
parts.push(clone_text_token(TokenConstructor, token, content.slice(start, pos)));
|
|
381
|
-
}
|
|
389
|
+
if (pos > start) push_text_part(content.slice(start, pos));
|
|
382
390
|
|
|
383
391
|
parts.push(create_softbreak_token(TokenConstructor, token));
|
|
384
392
|
start = pos + 1;
|
|
385
393
|
}
|
|
386
394
|
|
|
387
|
-
if (start < content.length)
|
|
388
|
-
parts.push(clone_text_token(TokenConstructor, token, content.slice(start)));
|
|
389
|
-
}
|
|
395
|
+
if (start < content.length) push_text_part(content.slice(start));
|
|
390
396
|
|
|
391
397
|
return parts;
|
|
392
398
|
}
|
|
@@ -450,7 +456,13 @@ function apply_missing_punctuation_spacing(tokens, inlineToken, punctuationSpace
|
|
|
450
456
|
if (nextInfo.token.type === 'text' && has_leading_whitespace(nextInfo.token.content)) continue;
|
|
451
457
|
if (nextInfo.hasActiveBreak) continue;
|
|
452
458
|
|
|
453
|
-
if (!raw_boundary_includes_newline(
|
|
459
|
+
if (!raw_boundary_includes_newline(
|
|
460
|
+
inlineToken.content,
|
|
461
|
+
current.content,
|
|
462
|
+
nextInfo.betweenMarkup,
|
|
463
|
+
nextInfo.fragment,
|
|
464
|
+
rawSearchState
|
|
465
|
+
)) {
|
|
454
466
|
continue;
|
|
455
467
|
}
|
|
456
468
|
|
|
@@ -460,13 +472,10 @@ function apply_missing_punctuation_spacing(tokens, inlineToken, punctuationSpace
|
|
|
460
472
|
|
|
461
473
|
}
|
|
462
474
|
|
|
463
|
-
function raw_boundary_includes_newline(source,
|
|
475
|
+
function raw_boundary_includes_newline(source, beforeFragment, betweenFragment, afterFragment, state) {
|
|
464
476
|
if (!source || !afterFragment) return false;
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
for (var k = fromIdx + 1; k < nextIdx; k++) {
|
|
468
|
-
if (tokens[k].markup) betweenFragment += tokens[k].markup;
|
|
469
|
-
}
|
|
477
|
+
if (!beforeFragment) return false;
|
|
478
|
+
betweenFragment = betweenFragment || '';
|
|
470
479
|
if (Array.isArray(afterFragment)) {
|
|
471
480
|
for (var i = 0; i < afterFragment.length; i++) {
|
|
472
481
|
var fragment = afterFragment[i];
|
|
@@ -480,7 +489,6 @@ function raw_boundary_includes_newline(source, tokens, fromIdx, nextIdx, afterFr
|
|
|
480
489
|
return false;
|
|
481
490
|
}
|
|
482
491
|
var fragment = afterFragment;
|
|
483
|
-
if (!fragment) return false;
|
|
484
492
|
var candidate = beforeFragment + betweenFragment + '\n' + fragment;
|
|
485
493
|
var startPos = source.indexOf(candidate, state.pos);
|
|
486
494
|
if (startPos === -1) return false;
|
|
@@ -491,6 +499,7 @@ function raw_boundary_includes_newline(source, tokens, fromIdx, nextIdx, afterFr
|
|
|
491
499
|
|
|
492
500
|
function find_next_visible_token(tokens, startIdx) {
|
|
493
501
|
var hasActiveBreak = false;
|
|
502
|
+
var betweenMarkup = '';
|
|
494
503
|
for (var idx = startIdx; idx < tokens.length; idx++) {
|
|
495
504
|
var token = tokens[idx];
|
|
496
505
|
if (!token) continue;
|
|
@@ -498,8 +507,11 @@ function find_next_visible_token(tokens, startIdx) {
|
|
|
498
507
|
hasActiveBreak = true;
|
|
499
508
|
}
|
|
500
509
|
var fragment = derive_after_fragment(token);
|
|
501
|
-
if (!fragment)
|
|
502
|
-
|
|
510
|
+
if (!fragment) {
|
|
511
|
+
if (token.markup) betweenMarkup += token.markup;
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
return { index: idx, token: token, fragment: fragment, hasActiveBreak: hasActiveBreak, betweenMarkup: betweenMarkup };
|
|
503
515
|
}
|
|
504
516
|
return null;
|
|
505
517
|
}
|
|
@@ -555,7 +567,6 @@ function apply_single_text_token_spacing(tokens, inlineToken, punctuationSpace,
|
|
|
555
567
|
if (maxPunctuationLength <= 0) return;
|
|
556
568
|
|
|
557
569
|
var segments = inlineToken.content.split('\n');
|
|
558
|
-
if (segments.length < 2) return;
|
|
559
570
|
var cumulativeLength = 0;
|
|
560
571
|
var offsetDelta = 0;
|
|
561
572
|
var updatedContent = token.content;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peaceroad/markdown-it-cjk-breaks-mod",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Suppress linebreaks between east asian (Especially Japanese) characters",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"eastasianwidth": "^0.3.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@peaceroad/markdown-it-strong-ja": "^0.8.
|
|
25
|
+
"@peaceroad/markdown-it-strong-ja": "^0.8.1",
|
|
26
26
|
"markdown-it": "^14.1.0"
|
|
27
27
|
}
|
|
28
28
|
}
|