@gmb/bitmark-parser-generator 5.39.0 → 5.41.0
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/dist/browser/bitmark-parser-generator.min.js +1 -1
- package/dist/browser/bundle-report.html +2 -2
- package/dist/browser/cjs/index.cjs +992 -279
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +17 -17
- package/dist/browser/esm/index.d.ts +17 -17
- package/dist/browser/esm/index.js +992 -279
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/cli/main.js +994 -282
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +995 -282
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -17
- package/dist/index.d.ts +17 -17
- package/dist/index.js +995 -282
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/main.js
CHANGED
|
@@ -14,6 +14,8 @@ var BitType = {
|
|
|
14
14
|
// Used to indicate a bit is commented out
|
|
15
15
|
_standard: "_standard",
|
|
16
16
|
// Not to be used as a bit, but as a base for other bit types
|
|
17
|
+
_standardLight: "_standard-light",
|
|
18
|
+
// PLAN-021: lightweight base (minimal tag set), not to be used as a bit
|
|
17
19
|
advertising: "advertising",
|
|
18
20
|
advertisingAdvertorial: "advertising-advertorial",
|
|
19
21
|
advertisingAdvertorialPage: "advertising-advertorial-page",
|
|
@@ -301,6 +303,7 @@ var BitType = {
|
|
|
301
303
|
handInSystemMedia: "hand-in-system-media",
|
|
302
304
|
handInVideo: "hand-in-video",
|
|
303
305
|
handInVoice: "hand-in-voice",
|
|
306
|
+
h: "h",
|
|
304
307
|
help: "help",
|
|
305
308
|
helpAlt: "help-alt",
|
|
306
309
|
highlightText: "highlight-text",
|
|
@@ -386,6 +389,7 @@ var BitType = {
|
|
|
386
389
|
leWatchVideoEmbed: "le-watch-video-embed",
|
|
387
390
|
lifeSkillSticker: "life-skill-sticker",
|
|
388
391
|
list: "list",
|
|
392
|
+
listAlt: "list-alt",
|
|
389
393
|
listItem: "list-item",
|
|
390
394
|
mark: "mark",
|
|
391
395
|
match: "match",
|
|
@@ -416,6 +420,8 @@ var BitType = {
|
|
|
416
420
|
notebookArticle: "notebook-article",
|
|
417
421
|
noteCollapsible: "note-collapsible",
|
|
418
422
|
output: "output",
|
|
423
|
+
p: "p",
|
|
424
|
+
pAlt: "p-alt",
|
|
419
425
|
page: "page",
|
|
420
426
|
pageAcademy: "page-academy",
|
|
421
427
|
pageArticle: "page-article",
|
|
@@ -538,6 +544,7 @@ var BitType = {
|
|
|
538
544
|
smartStandardNoteNonNormativeCollapsible: "smart-standard-note-non-normative-collapsible",
|
|
539
545
|
smartStandardNoteNormative: "smart-standard-note-normative",
|
|
540
546
|
smartStandardNoteNormativeCollapsible: "smart-standard-note-normative-collapsible",
|
|
547
|
+
smartStandardP: "smart-standard-p",
|
|
541
548
|
smartStandardRemarkLegend: "smart-standard-remark-legend",
|
|
542
549
|
smartStandardRemarkLegendNonNormative: "smart-standard-remark-legend-non-normative",
|
|
543
550
|
smartStandardRemarkLegendNormative: "smart-standard-remark-legend-normative",
|
|
@@ -1469,6 +1476,8 @@ ${this.cardSet.toString(opts)}`;
|
|
|
1469
1476
|
var groupKeys = {
|
|
1470
1477
|
group_accessibilityDecorative: "group_accessibilityDecorative",
|
|
1471
1478
|
group_standardAllBits: "group_standardAllBits",
|
|
1479
|
+
group_standardExample: "group_standardExample",
|
|
1480
|
+
group_standardItem: "group_standardItem",
|
|
1472
1481
|
group_standardItemLead: "group_standardItemLead",
|
|
1473
1482
|
group_standardItemLeadInstructionHint: "group_standardItemLeadInstructionHint",
|
|
1474
1483
|
group_standardInstructionHint: "group_standardInstructionHint",
|
|
@@ -4956,6 +4965,34 @@ var GROUPS = {
|
|
|
4956
4965
|
}
|
|
4957
4966
|
]
|
|
4958
4967
|
},
|
|
4968
|
+
[ConfigKey.group_standardExample]: {
|
|
4969
|
+
type: GroupConfigType.standard,
|
|
4970
|
+
description: "PLAN-021: Standard group for the bit-level example property only. Mirror of the group_standardTags property_example entry, used by the lightweight bits (_standardLight).",
|
|
4971
|
+
tags: [
|
|
4972
|
+
{
|
|
4973
|
+
key: ConfigKey.property_example,
|
|
4974
|
+
exportJsonKey: [{ "@keyonly": {} }, { "@absent": { isExample: true } }, { example: "$" }],
|
|
4975
|
+
description: "The example(s) for the bit",
|
|
4976
|
+
format: TagFormat.bitmarkText,
|
|
4977
|
+
nullable: true
|
|
4978
|
+
}
|
|
4979
|
+
]
|
|
4980
|
+
},
|
|
4981
|
+
[ConfigKey.group_standardItem]: {
|
|
4982
|
+
type: GroupConfigType.standard,
|
|
4983
|
+
description: "PLAN-021: Standard group for the item tag ONLY (no lead/pageNumber/marginNumber chain). Used by the lightweight bits (_standardLight).",
|
|
4984
|
+
tags: [
|
|
4985
|
+
{
|
|
4986
|
+
key: ConfigKey.tag_item,
|
|
4987
|
+
jsonKey: "item",
|
|
4988
|
+
exportJsonKey: { item: "$" },
|
|
4989
|
+
// PLAN-140 W3 (NISO import): the clause/note label of a mapped
|
|
4990
|
+
// source element ([%1], [%ANMERKUNG 1]) — same as group_standardItemLead.
|
|
4991
|
+
mappingKeys: { "xml-niso-iec": { "@el": "label", "@text": "$" } },
|
|
4992
|
+
description: "The item for the bit"
|
|
4993
|
+
}
|
|
4994
|
+
]
|
|
4995
|
+
},
|
|
4959
4996
|
[ConfigKey.group_standardItemLead]: {
|
|
4960
4997
|
type: GroupConfigType.standard,
|
|
4961
4998
|
description: "Standard group for item, lead, page number, and margin number tags",
|
|
@@ -7759,6 +7796,25 @@ var BITS = {
|
|
|
7759
7796
|
}
|
|
7760
7797
|
]
|
|
7761
7798
|
},
|
|
7799
|
+
[BitType._standardLight]: {
|
|
7800
|
+
since: "5.40.0",
|
|
7801
|
+
description: "PLAN-021: Lightweight standard base bit with a minimal tag set (item + example only \u2014 no instruction/hint/lead, no resource attachments), used as a base for other bits, should not be used directly",
|
|
7802
|
+
resourceAttachmentAllowed: false,
|
|
7803
|
+
tags: [
|
|
7804
|
+
{
|
|
7805
|
+
key: ConfigKey.group_standardAllBits,
|
|
7806
|
+
description: "Standard tags for all bits"
|
|
7807
|
+
},
|
|
7808
|
+
{
|
|
7809
|
+
key: ConfigKey.group_standardItem,
|
|
7810
|
+
description: "The item tag (no lead/pageNumber/marginNumber chain)"
|
|
7811
|
+
},
|
|
7812
|
+
{
|
|
7813
|
+
key: ConfigKey.group_standardExample,
|
|
7814
|
+
description: "The bit-level example property"
|
|
7815
|
+
}
|
|
7816
|
+
]
|
|
7817
|
+
},
|
|
7762
7818
|
[BitType.appFlashcards]: {
|
|
7763
7819
|
since: "1.3.0",
|
|
7764
7820
|
title: "Flashcards",
|
|
@@ -10586,6 +10642,23 @@ var BITS = {
|
|
|
10586
10642
|
baseBitType: BitType.article,
|
|
10587
10643
|
description: "Glossary term bit, used to define glossary terms in articles or books"
|
|
10588
10644
|
},
|
|
10645
|
+
[BitType.h]: {
|
|
10646
|
+
since: "5.40.0",
|
|
10647
|
+
title: "Heading",
|
|
10648
|
+
bitGroups: [BitGroup.static],
|
|
10649
|
+
baseBitType: BitType._standardLight,
|
|
10650
|
+
description: "Lightweight heading bit with chapter-style title levels 1-7; title/level + item only \u2014 no body, no footer",
|
|
10651
|
+
bodyAllowed: false,
|
|
10652
|
+
footerAllowed: false,
|
|
10653
|
+
tags: [
|
|
10654
|
+
{
|
|
10655
|
+
key: ConfigKey.tag_title,
|
|
10656
|
+
description: "The title of the heading",
|
|
10657
|
+
jsonKey: "title|setMulti(level)",
|
|
10658
|
+
exportJsonKey: { title: "$", level: "$level" }
|
|
10659
|
+
}
|
|
10660
|
+
]
|
|
10661
|
+
},
|
|
10589
10662
|
[BitType.help]: {
|
|
10590
10663
|
since: "1.3.0",
|
|
10591
10664
|
title: "Help",
|
|
@@ -10772,13 +10845,22 @@ var BITS = {
|
|
|
10772
10845
|
since: "1.22.0",
|
|
10773
10846
|
title: "List",
|
|
10774
10847
|
bitGroups: [BitGroup.static],
|
|
10775
|
-
|
|
10848
|
+
// PLAN-021: rebased from article onto the lightweight base
|
|
10849
|
+
baseBitType: BitType._standardLight,
|
|
10776
10850
|
description: "List bit, used to create lists in articles or books"
|
|
10777
10851
|
},
|
|
10852
|
+
[BitType.listAlt]: {
|
|
10853
|
+
since: "5.40.0",
|
|
10854
|
+
title: "List Alt",
|
|
10855
|
+
bitGroups: [BitGroup.static],
|
|
10856
|
+
baseBitType: BitType.list,
|
|
10857
|
+
description: "Lightweight list bit (alternative), based on list"
|
|
10858
|
+
},
|
|
10778
10859
|
[BitType.standardList]: {
|
|
10779
10860
|
since: "1.22.0",
|
|
10780
10861
|
bitGroups: [BitGroup.static],
|
|
10781
|
-
|
|
10862
|
+
// PLAN-021: re-rooted from article onto the lightweight list
|
|
10863
|
+
baseBitType: BitType.list,
|
|
10782
10864
|
description: "Standard list bit, used to create standard lists in articles or books"
|
|
10783
10865
|
},
|
|
10784
10866
|
[BitType.smartStandardList]: {
|
|
@@ -10794,6 +10876,13 @@ var BITS = {
|
|
|
10794
10876
|
"xml-niso-iec": { "@el": "ref-list", "@attr": { id: "$customerId" }, "\u25BC": "$anchor" }
|
|
10795
10877
|
}
|
|
10796
10878
|
},
|
|
10879
|
+
[BitType.smartStandardP]: {
|
|
10880
|
+
since: "5.40.0",
|
|
10881
|
+
title: "Smart Standard Paragraph",
|
|
10882
|
+
bitGroups: [BitGroup.static],
|
|
10883
|
+
baseBitType: BitType.p,
|
|
10884
|
+
description: "Smart standard paragraph bit, based on p"
|
|
10885
|
+
},
|
|
10797
10886
|
[BitType.smartStandardListCollapsible]: {
|
|
10798
10887
|
since: "1.28.0",
|
|
10799
10888
|
deprecated: "5.37.0",
|
|
@@ -13375,7 +13464,8 @@ var BITS = {
|
|
|
13375
13464
|
[BitType.listItem]: {
|
|
13376
13465
|
since: "1.22.0",
|
|
13377
13466
|
bitGroups: [BitGroup.static],
|
|
13378
|
-
|
|
13467
|
+
// PLAN-021: rebased from article onto the lightweight base
|
|
13468
|
+
baseBitType: BitType._standardLight,
|
|
13379
13469
|
description: "List item bit, used to create list items in articles or books",
|
|
13380
13470
|
tags: [
|
|
13381
13471
|
{
|
|
@@ -13780,6 +13870,20 @@ var BITS = {
|
|
|
13780
13870
|
baseBitType: BitType.multipleResponse,
|
|
13781
13871
|
description: "Coach self-reflection multiple response bit, used for self-reflection in coaching"
|
|
13782
13872
|
},
|
|
13873
|
+
[BitType.p]: {
|
|
13874
|
+
since: "5.40.0",
|
|
13875
|
+
title: "Paragraph",
|
|
13876
|
+
bitGroups: [BitGroup.static],
|
|
13877
|
+
baseBitType: BitType._standardLight,
|
|
13878
|
+
description: "Lightweight paragraph bit with a minimal tag set"
|
|
13879
|
+
},
|
|
13880
|
+
[BitType.pAlt]: {
|
|
13881
|
+
since: "5.40.0",
|
|
13882
|
+
title: "Paragraph Alt",
|
|
13883
|
+
bitGroups: [BitGroup.static],
|
|
13884
|
+
baseBitType: BitType.p,
|
|
13885
|
+
description: "Lightweight paragraph bit (alternative), based on p"
|
|
13886
|
+
},
|
|
13783
13887
|
[BitType.page]: {
|
|
13784
13888
|
since: "1.3.0",
|
|
13785
13889
|
title: "Page",
|
|
@@ -16510,7 +16614,7 @@ var instance2 = new Config();
|
|
|
16510
16614
|
// src/generated/package_info.ts
|
|
16511
16615
|
var PACKAGE_INFO = {
|
|
16512
16616
|
"name": "@gmb/bitmark-parser-generator",
|
|
16513
|
-
"version": "5.
|
|
16617
|
+
"version": "5.41.0",
|
|
16514
16618
|
"license": "ISC"};
|
|
16515
16619
|
var Environment = {
|
|
16516
16620
|
unknown: "",
|
|
@@ -18308,6 +18412,751 @@ var AstWalkerGenerator = class {
|
|
|
18308
18412
|
}
|
|
18309
18413
|
};
|
|
18310
18414
|
|
|
18415
|
+
// src/generator/text/TextGrammarConstraints.ts
|
|
18416
|
+
var COLORS = [
|
|
18417
|
+
"aqua",
|
|
18418
|
+
"black",
|
|
18419
|
+
"blue",
|
|
18420
|
+
"brown",
|
|
18421
|
+
"fuchsia",
|
|
18422
|
+
"lightgrey",
|
|
18423
|
+
"gray",
|
|
18424
|
+
"darkgray",
|
|
18425
|
+
"green",
|
|
18426
|
+
"lime",
|
|
18427
|
+
"magenta",
|
|
18428
|
+
"maroon",
|
|
18429
|
+
"navy",
|
|
18430
|
+
"olive",
|
|
18431
|
+
"orange",
|
|
18432
|
+
"pink",
|
|
18433
|
+
"purple",
|
|
18434
|
+
"red",
|
|
18435
|
+
"silver",
|
|
18436
|
+
"teal",
|
|
18437
|
+
"violet",
|
|
18438
|
+
"white",
|
|
18439
|
+
"yellow"
|
|
18440
|
+
];
|
|
18441
|
+
var HIGHLIGHT_COLORS = [
|
|
18442
|
+
"orange",
|
|
18443
|
+
"yellow",
|
|
18444
|
+
"green",
|
|
18445
|
+
"blue",
|
|
18446
|
+
"purple",
|
|
18447
|
+
"pink",
|
|
18448
|
+
"brown",
|
|
18449
|
+
"white",
|
|
18450
|
+
"black",
|
|
18451
|
+
"gray"
|
|
18452
|
+
];
|
|
18453
|
+
var ALTERNATIVE_STYLE_TAGS = [
|
|
18454
|
+
"bold",
|
|
18455
|
+
"italic",
|
|
18456
|
+
"light",
|
|
18457
|
+
"highlightOrange",
|
|
18458
|
+
"highlightYellow",
|
|
18459
|
+
"highlightGreen",
|
|
18460
|
+
"highlightBlue",
|
|
18461
|
+
"highlightPurple",
|
|
18462
|
+
"highlightPink",
|
|
18463
|
+
"highlightBrown",
|
|
18464
|
+
"highlightBlack",
|
|
18465
|
+
"highlightWhite",
|
|
18466
|
+
"highlightGray",
|
|
18467
|
+
"highlight",
|
|
18468
|
+
"strike",
|
|
18469
|
+
"subscript",
|
|
18470
|
+
"superscript",
|
|
18471
|
+
"ins",
|
|
18472
|
+
"del",
|
|
18473
|
+
"underline",
|
|
18474
|
+
"doubleUnderline",
|
|
18475
|
+
"smallcaps",
|
|
18476
|
+
"circle",
|
|
18477
|
+
"languageEmRed",
|
|
18478
|
+
"languageEmOrange",
|
|
18479
|
+
"languageEmYellow",
|
|
18480
|
+
"languageEmGreen",
|
|
18481
|
+
"languageEmBlue",
|
|
18482
|
+
"languageEmPurple",
|
|
18483
|
+
"languageEmPink",
|
|
18484
|
+
"languageEmBrown",
|
|
18485
|
+
"languageEmBlack",
|
|
18486
|
+
"languageEmWhite",
|
|
18487
|
+
"languageEmGray",
|
|
18488
|
+
"languageEm",
|
|
18489
|
+
"userUnderline",
|
|
18490
|
+
"userDoubleUnderline",
|
|
18491
|
+
"userStrike",
|
|
18492
|
+
"userCircle",
|
|
18493
|
+
"userHighlight",
|
|
18494
|
+
"notranslate"
|
|
18495
|
+
];
|
|
18496
|
+
var MEDIA_ALIGNMENTS = ["left", "center", "right"];
|
|
18497
|
+
var INLINE_MEDIA_ALIGNMENTS = [
|
|
18498
|
+
"top",
|
|
18499
|
+
"middle",
|
|
18500
|
+
"bottom",
|
|
18501
|
+
"baseline",
|
|
18502
|
+
"sub",
|
|
18503
|
+
"super",
|
|
18504
|
+
"text-bottom",
|
|
18505
|
+
"text-top"
|
|
18506
|
+
];
|
|
18507
|
+
var INLINE_MEDIA_SIZES = [
|
|
18508
|
+
"line-height",
|
|
18509
|
+
"font-height",
|
|
18510
|
+
"super",
|
|
18511
|
+
"sub",
|
|
18512
|
+
"explicit"
|
|
18513
|
+
];
|
|
18514
|
+
var LINE_TERMINATOR_REGEX = /[\n\r\u2028\u2029]/;
|
|
18515
|
+
var CHAIN_STRING_INVALID_REGEX = /[|\n\r\u2028\u2029]/;
|
|
18516
|
+
var URL_CHAR_CLASS = "a-zA-Z0-9!*'()=+,\\-./_?#@[\\]$&;%:{}~^";
|
|
18517
|
+
var URL_CHAR_REGEX = new RegExp(`^[${URL_CHAR_CLASS}]$`);
|
|
18518
|
+
var URL_HTTP_REGEX = new RegExp(`^https?://[${URL_CHAR_CLASS}]*$`);
|
|
18519
|
+
var URL_REGEX = new RegExp(`^(https?://|mailto:)[${URL_CHAR_CLASS}]*$`);
|
|
18520
|
+
function isChainString(v) {
|
|
18521
|
+
return typeof v === "string" && !CHAIN_STRING_INVALID_REGEX.test(v);
|
|
18522
|
+
}
|
|
18523
|
+
function isSingleLine(v) {
|
|
18524
|
+
return typeof v === "string" && !LINE_TERMINATOR_REGEX.test(v);
|
|
18525
|
+
}
|
|
18526
|
+
function hasLineTerminator(v) {
|
|
18527
|
+
return LINE_TERMINATOR_REGEX.test(v);
|
|
18528
|
+
}
|
|
18529
|
+
function isColor(v) {
|
|
18530
|
+
return typeof v === "string" && COLORS.indexOf(v) !== -1;
|
|
18531
|
+
}
|
|
18532
|
+
function isHighlightColor(v) {
|
|
18533
|
+
return typeof v === "string" && HIGHLIGHT_COLORS.indexOf(v) !== -1;
|
|
18534
|
+
}
|
|
18535
|
+
function isMediaAlignment(v) {
|
|
18536
|
+
return typeof v === "string" && MEDIA_ALIGNMENTS.indexOf(v) !== -1;
|
|
18537
|
+
}
|
|
18538
|
+
function isInlineMediaAlignment(v) {
|
|
18539
|
+
return typeof v === "string" && INLINE_MEDIA_ALIGNMENTS.indexOf(v) !== -1;
|
|
18540
|
+
}
|
|
18541
|
+
function isInlineMediaSize(v) {
|
|
18542
|
+
return typeof v === "string" && INLINE_MEDIA_SIZES.indexOf(v) !== -1;
|
|
18543
|
+
}
|
|
18544
|
+
function toUInt(v) {
|
|
18545
|
+
if (typeof v === "number") return Number.isInteger(v) && v >= 0 ? v : void 0;
|
|
18546
|
+
if (typeof v === "string" && /^[0-9]+$/.test(v)) return parseInt(v, 10);
|
|
18547
|
+
return void 0;
|
|
18548
|
+
}
|
|
18549
|
+
function toBoolean(v) {
|
|
18550
|
+
if (typeof v === "boolean") return v;
|
|
18551
|
+
if (v === "true") return true;
|
|
18552
|
+
if (v === "false") return false;
|
|
18553
|
+
return void 0;
|
|
18554
|
+
}
|
|
18555
|
+
function isDuration(v) {
|
|
18556
|
+
return isChainString(v) && v.trim().startsWith("P");
|
|
18557
|
+
}
|
|
18558
|
+
function isUrlHttp(v) {
|
|
18559
|
+
return typeof v === "string" && URL_HTTP_REGEX.test(v);
|
|
18560
|
+
}
|
|
18561
|
+
function isUrl(v) {
|
|
18562
|
+
return typeof v === "string" && URL_REGEX.test(v);
|
|
18563
|
+
}
|
|
18564
|
+
function isUrlChar(c) {
|
|
18565
|
+
return URL_CHAR_REGEX.test(c);
|
|
18566
|
+
}
|
|
18567
|
+
function bareUrlText(href) {
|
|
18568
|
+
return href.replace(/^(https?:\/\/|mailto:)/, "");
|
|
18569
|
+
}
|
|
18570
|
+
function isInlineAlt(v) {
|
|
18571
|
+
return typeof v === "string" && v.length > 0 && v.indexOf("==") === -1 && !v.startsWith("=") && !v.endsWith("=");
|
|
18572
|
+
}
|
|
18573
|
+
function isHeadingLevel(v) {
|
|
18574
|
+
return typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= 3;
|
|
18575
|
+
}
|
|
18576
|
+
function normalizeInlineCodeLanguage(v) {
|
|
18577
|
+
if (!isChainString(v)) return void 0;
|
|
18578
|
+
return v.trim().toLowerCase();
|
|
18579
|
+
}
|
|
18580
|
+
function normalizeBlockCodeLanguage(v) {
|
|
18581
|
+
if (!isSingleLine(v)) return void 0;
|
|
18582
|
+
return v.trim().toLowerCase();
|
|
18583
|
+
}
|
|
18584
|
+
|
|
18585
|
+
// src/generator/text/TextMediaAttrs.ts
|
|
18586
|
+
var uint = (v) => toUInt(v);
|
|
18587
|
+
var bool = (v) => toBoolean(v);
|
|
18588
|
+
var alignment = (v) => isMediaAlignment(v) ? v : void 0;
|
|
18589
|
+
var chainString = (v) => isChainString(v) ? v.trim() : void 0;
|
|
18590
|
+
var inlineAlignment = (v) => isInlineMediaAlignment(v) ? v : void 0;
|
|
18591
|
+
var inlineSize = (v) => isInlineMediaSize(v) ? v : void 0;
|
|
18592
|
+
var VALIDATORS = {
|
|
18593
|
+
image: {
|
|
18594
|
+
alt: chainString,
|
|
18595
|
+
title: chainString,
|
|
18596
|
+
alignment,
|
|
18597
|
+
textAlign: alignment,
|
|
18598
|
+
zoomDisabled: bool,
|
|
18599
|
+
width: uint,
|
|
18600
|
+
height: uint,
|
|
18601
|
+
comment: chainString
|
|
18602
|
+
},
|
|
18603
|
+
imageInline: {
|
|
18604
|
+
srcAlt: chainString,
|
|
18605
|
+
alignmentVertical: inlineAlignment,
|
|
18606
|
+
size: inlineSize,
|
|
18607
|
+
width: uint,
|
|
18608
|
+
height: uint,
|
|
18609
|
+
comment: chainString
|
|
18610
|
+
},
|
|
18611
|
+
symbol: {
|
|
18612
|
+
alt: chainString,
|
|
18613
|
+
title: chainString,
|
|
18614
|
+
caption: chainString,
|
|
18615
|
+
alignment,
|
|
18616
|
+
textAlign: alignment,
|
|
18617
|
+
captionAlign: alignment,
|
|
18618
|
+
zoomDisabled: bool,
|
|
18619
|
+
width: uint,
|
|
18620
|
+
height: uint,
|
|
18621
|
+
comment: chainString
|
|
18622
|
+
}
|
|
18623
|
+
};
|
|
18624
|
+
var TAG_NAMES = {
|
|
18625
|
+
textAlign: "captionAlign",
|
|
18626
|
+
title: "caption"
|
|
18627
|
+
};
|
|
18628
|
+
var DEFAULTS = {
|
|
18629
|
+
image: { alignment: "center", textAlign: "left", zoomDisabled: true },
|
|
18630
|
+
imageInline: { alignmentVertical: "top", size: "line-height" },
|
|
18631
|
+
symbol: {}
|
|
18632
|
+
};
|
|
18633
|
+
function sanitizeMediaAttrs(kind, attrs) {
|
|
18634
|
+
const result = {};
|
|
18635
|
+
if (!attrs || typeof attrs !== "object") return result;
|
|
18636
|
+
const validators = VALIDATORS[kind];
|
|
18637
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
18638
|
+
const validator = validators[k];
|
|
18639
|
+
if (!validator || v == null) continue;
|
|
18640
|
+
const valid = validator(v);
|
|
18641
|
+
if (valid !== void 0) result[k] = valid;
|
|
18642
|
+
}
|
|
18643
|
+
if (kind === "symbol") {
|
|
18644
|
+
if ("caption" in result) delete result.title;
|
|
18645
|
+
if ("captionAlign" in result) delete result.textAlign;
|
|
18646
|
+
}
|
|
18647
|
+
return result;
|
|
18648
|
+
}
|
|
18649
|
+
function serializeMediaChain(kind, attrs) {
|
|
18650
|
+
const defaults = DEFAULTS[kind];
|
|
18651
|
+
let s = "";
|
|
18652
|
+
for (const k of Object.keys(VALIDATORS[kind])) {
|
|
18653
|
+
const v = attrs[k];
|
|
18654
|
+
if (v == null) continue;
|
|
18655
|
+
if (k in defaults && defaults[k] === v) continue;
|
|
18656
|
+
if (k === "comment") {
|
|
18657
|
+
if (v) s += `|#${v}`;
|
|
18658
|
+
} else if (typeof v === "string" && v === "") {
|
|
18659
|
+
continue;
|
|
18660
|
+
} else {
|
|
18661
|
+
s += `|${TAG_NAMES[k] ?? k}:${v}`;
|
|
18662
|
+
}
|
|
18663
|
+
}
|
|
18664
|
+
return s;
|
|
18665
|
+
}
|
|
18666
|
+
|
|
18667
|
+
// src/generator/text/TextMarkSanitizer.ts
|
|
18668
|
+
var STANDARD_SHORT_FORM_MARKS = [
|
|
18669
|
+
TextMarkType.bold,
|
|
18670
|
+
TextMarkType.italic,
|
|
18671
|
+
TextMarkType.light,
|
|
18672
|
+
TextMarkType.highlight
|
|
18673
|
+
];
|
|
18674
|
+
function attrsOf(mark2) {
|
|
18675
|
+
const a = mark2.attrs;
|
|
18676
|
+
return a && typeof a === "object" && !Array.isArray(a) ? a : {};
|
|
18677
|
+
}
|
|
18678
|
+
function chainValue(v) {
|
|
18679
|
+
if (v == null) return "";
|
|
18680
|
+
return isChainString(v) ? v.trim() : void 0;
|
|
18681
|
+
}
|
|
18682
|
+
function mark(type, attrs) {
|
|
18683
|
+
return attrs ? { type, attrs } : { type };
|
|
18684
|
+
}
|
|
18685
|
+
function sanitizeMark(m, options) {
|
|
18686
|
+
const attrs = attrsOf(m);
|
|
18687
|
+
switch (m.type) {
|
|
18688
|
+
case TextMarkType.highlight:
|
|
18689
|
+
case TextMarkType.userHighlight: {
|
|
18690
|
+
const color = attrs.color;
|
|
18691
|
+
return isHighlightColor(color) ? mark(m.type, { color }) : mark(m.type);
|
|
18692
|
+
}
|
|
18693
|
+
case TextMarkType.textStyle:
|
|
18694
|
+
case TextMarkType.color: {
|
|
18695
|
+
const color = attrs.color;
|
|
18696
|
+
return isColor(color) ? mark(TextMarkType.textStyle, { color }) : void 0;
|
|
18697
|
+
}
|
|
18698
|
+
case TextMarkType.link: {
|
|
18699
|
+
const href = chainValue(attrs.href);
|
|
18700
|
+
return href === void 0 ? void 0 : mark(m.type, { href });
|
|
18701
|
+
}
|
|
18702
|
+
case TextMarkType.ref: {
|
|
18703
|
+
const reference = chainValue(attrs.reference);
|
|
18704
|
+
return reference === void 0 ? void 0 : mark(m.type, { reference });
|
|
18705
|
+
}
|
|
18706
|
+
case TextMarkType.xref: {
|
|
18707
|
+
const xref = chainValue(attrs.xref);
|
|
18708
|
+
if (xref === void 0) return void 0;
|
|
18709
|
+
const reference = chainValue(attrs.reference) ?? "";
|
|
18710
|
+
return mark(m.type, { xref, reference });
|
|
18711
|
+
}
|
|
18712
|
+
case TextMarkType.extref: {
|
|
18713
|
+
const extref = chainValue(attrs.extref);
|
|
18714
|
+
const provider = chainValue(attrs.provider);
|
|
18715
|
+
if (extref === void 0 || provider === void 0) return void 0;
|
|
18716
|
+
const refs = Array.isArray(attrs.references) ? attrs.references : [];
|
|
18717
|
+
const references = refs.map((r) => chainValue(r)).filter((r) => r !== void 0);
|
|
18718
|
+
return mark(m.type, { extref, references, provider });
|
|
18719
|
+
}
|
|
18720
|
+
case TextMarkType.footnote:
|
|
18721
|
+
case TextMarkType.footnoteStar: {
|
|
18722
|
+
const content = options.normalizeChainValue ? options.normalizeChainValue(attrs.content) : Array.isArray(attrs.content) ? attrs.content : [];
|
|
18723
|
+
return content === void 0 ? void 0 : mark(m.type, { content });
|
|
18724
|
+
}
|
|
18725
|
+
case TextMarkType.symbol: {
|
|
18726
|
+
const src = chainValue(attrs.src);
|
|
18727
|
+
if (src === void 0) return void 0;
|
|
18728
|
+
return mark(m.type, { src, ...sanitizeMediaAttrs("symbol", attrs) });
|
|
18729
|
+
}
|
|
18730
|
+
case TextMarkType.var: {
|
|
18731
|
+
const name = chainValue(attrs.name);
|
|
18732
|
+
return name === void 0 ? void 0 : mark(m.type, { name });
|
|
18733
|
+
}
|
|
18734
|
+
case TextMarkType.code: {
|
|
18735
|
+
const language = normalizeInlineCodeLanguage(attrs.language);
|
|
18736
|
+
return language === void 0 ? mark(m.type) : mark(m.type, { language });
|
|
18737
|
+
}
|
|
18738
|
+
case TextMarkType.timer: {
|
|
18739
|
+
const duration = attrs.duration;
|
|
18740
|
+
if (!isDuration(duration)) return void 0;
|
|
18741
|
+
const name = chainValue(attrs.name) ?? "";
|
|
18742
|
+
return mark(m.type, { name, duration: duration.trim() });
|
|
18743
|
+
}
|
|
18744
|
+
case TextMarkType.colorPicker: {
|
|
18745
|
+
const propertyRef = chainValue(attrs.propertyRef);
|
|
18746
|
+
return propertyRef === void 0 ? void 0 : mark(m.type, { propertyRef });
|
|
18747
|
+
}
|
|
18748
|
+
case TextMarkType.comment: {
|
|
18749
|
+
const comment = chainValue(m.comment);
|
|
18750
|
+
return comment === void 0 ? void 0 : { type: m.type, comment };
|
|
18751
|
+
}
|
|
18752
|
+
default:
|
|
18753
|
+
if (ALTERNATIVE_STYLE_TAGS.indexOf(m.type) !== -1) return mark(m.type);
|
|
18754
|
+
return void 0;
|
|
18755
|
+
}
|
|
18756
|
+
}
|
|
18757
|
+
function mergeLegacyTimer(marks) {
|
|
18758
|
+
const timer = marks.find((m) => m.type === TextMarkType.timer);
|
|
18759
|
+
const duration = marks.find((m) => m.type === TextMarkType.duration);
|
|
18760
|
+
if (!timer || !duration || attrsOf(timer).duration) return marks;
|
|
18761
|
+
return marks.map(
|
|
18762
|
+
(m) => m === timer ? { ...timer, attrs: { ...attrsOf(timer), duration: attrsOf(duration).duration } } : m
|
|
18763
|
+
);
|
|
18764
|
+
}
|
|
18765
|
+
function orderMarks(marks) {
|
|
18766
|
+
const a = (m) => m.attrs ?? {};
|
|
18767
|
+
const isBareHighlight = (m) => (m.type === TextMarkType.highlight || m.type === TextMarkType.userHighlight) && !a(m).color;
|
|
18768
|
+
const isHighlightColorStyle = (m) => m.type === TextMarkType.textStyle && isHighlightColor(a(m).color);
|
|
18769
|
+
const isEmptyXref = (m) => m.type === TextMarkType.xref && !a(m).reference;
|
|
18770
|
+
const result = [];
|
|
18771
|
+
for (const m of marks) {
|
|
18772
|
+
if (m.type === TextMarkType.ref) {
|
|
18773
|
+
const xrefIdx = result.findIndex(isEmptyXref);
|
|
18774
|
+
if (xrefIdx !== -1) {
|
|
18775
|
+
result.splice(xrefIdx, 0, m);
|
|
18776
|
+
continue;
|
|
18777
|
+
}
|
|
18778
|
+
}
|
|
18779
|
+
result.push(m);
|
|
18780
|
+
}
|
|
18781
|
+
for (let i = 0; i < result.length - 1; i++) {
|
|
18782
|
+
if (isBareHighlight(result[i]) && isHighlightColorStyle(result[i + 1])) {
|
|
18783
|
+
[result[i], result[i + 1]] = [result[i + 1], result[i]];
|
|
18784
|
+
}
|
|
18785
|
+
}
|
|
18786
|
+
const symbols = result.filter((m) => m.type === TextMarkType.symbol);
|
|
18787
|
+
if (symbols.length === 0) return result;
|
|
18788
|
+
return [...result.filter((m) => m.type !== TextMarkType.symbol), symbols[0]];
|
|
18789
|
+
}
|
|
18790
|
+
function sanitizeMarks(marks, options = {}) {
|
|
18791
|
+
if (!Array.isArray(marks)) return [];
|
|
18792
|
+
let loose = marks.filter(
|
|
18793
|
+
(m) => !!m && typeof m === "object" && typeof m.type === "string"
|
|
18794
|
+
);
|
|
18795
|
+
loose = mergeLegacyTimer(loose);
|
|
18796
|
+
const result = [];
|
|
18797
|
+
for (const m of loose) {
|
|
18798
|
+
const s = sanitizeMark(m, options);
|
|
18799
|
+
if (s) result.push(s);
|
|
18800
|
+
}
|
|
18801
|
+
if (options.chainValue) {
|
|
18802
|
+
if (result.length === 1 && STANDARD_SHORT_FORM_MARKS.indexOf(result[0].type) !== -1) {
|
|
18803
|
+
return [mark(result[0].type)];
|
|
18804
|
+
}
|
|
18805
|
+
if (result.length === 1 && result[0].type === TextMarkType.link) return result;
|
|
18806
|
+
return [];
|
|
18807
|
+
}
|
|
18808
|
+
return orderMarks(result);
|
|
18809
|
+
}
|
|
18810
|
+
|
|
18811
|
+
// src/generator/text/TextAstNormalizer.ts
|
|
18812
|
+
var LIST_TYPES = [
|
|
18813
|
+
TextNodeType.noBulletList,
|
|
18814
|
+
TextNodeType.bulletList,
|
|
18815
|
+
TextNodeType.orderedList,
|
|
18816
|
+
TextNodeType.orderedListRoman,
|
|
18817
|
+
TextNodeType.orderedListRomanLower,
|
|
18818
|
+
TextNodeType.letteredList,
|
|
18819
|
+
TextNodeType.letteredListLower,
|
|
18820
|
+
TextNodeType.taskList
|
|
18821
|
+
];
|
|
18822
|
+
var ORDERED_LIST_TYPES = [
|
|
18823
|
+
TextNodeType.orderedList,
|
|
18824
|
+
TextNodeType.orderedListRoman,
|
|
18825
|
+
TextNodeType.orderedListRomanLower
|
|
18826
|
+
];
|
|
18827
|
+
var BODY_BIT_TYPES = [
|
|
18828
|
+
TextNodeType.gap,
|
|
18829
|
+
TextNodeType.select,
|
|
18830
|
+
TextNodeType.highlight,
|
|
18831
|
+
TextNodeType.mark
|
|
18832
|
+
];
|
|
18833
|
+
var LEADING_TAB_REGEX = /(^|[\n\r\u2028\u2029])\t+/g;
|
|
18834
|
+
var isList = (n) => LIST_TYPES.indexOf(n.type) !== -1;
|
|
18835
|
+
var isListItem = (n) => n.type === TextNodeType.listItem || n.type === TextNodeType.taskItem;
|
|
18836
|
+
var isBodyBit = (n) => BODY_BIT_TYPES.indexOf(n.type) !== -1;
|
|
18837
|
+
var isNode = (n) => !!n && typeof n === "object" && typeof n.type === "string";
|
|
18838
|
+
var contentOf = (n) => Array.isArray(n.content) ? n.content.filter(isNode) : [];
|
|
18839
|
+
var attrsOf2 = (n) => n.attrs && typeof n.attrs === "object" ? n.attrs : {};
|
|
18840
|
+
var asNode = (n) => n;
|
|
18841
|
+
var paragraph = (content) => asNode({ type: TextNodeType.paragraph, attrs: {}, content });
|
|
18842
|
+
var hardBreak = () => ({ type: TextNodeType.hardBreak });
|
|
18843
|
+
var isHardBreak = (n) => n?.type === TextNodeType.hardBreak;
|
|
18844
|
+
var hasText = (nodes) => nodes.some(
|
|
18845
|
+
(n) => n.type !== TextNodeType.hardBreak && (n.type !== TextNodeType.text || typeof n.text === "string" && n.text.trim() !== "")
|
|
18846
|
+
);
|
|
18847
|
+
function canFollowBareUrl(next) {
|
|
18848
|
+
if (!next) return true;
|
|
18849
|
+
if (next.type === TextNodeType.hardBreak) return true;
|
|
18850
|
+
if (next.type !== TextNodeType.text) return false;
|
|
18851
|
+
if (next.marks && next.marks.length > 0) return false;
|
|
18852
|
+
const first = (next.text ?? "").charAt(0);
|
|
18853
|
+
return first === "" || !isUrlChar(first);
|
|
18854
|
+
}
|
|
18855
|
+
function isSimpleLinkNode(node, next) {
|
|
18856
|
+
if (node.type !== TextNodeType.text || node.marks?.length !== 1) return false;
|
|
18857
|
+
const m = node.marks[0];
|
|
18858
|
+
if (m.type !== TextMarkType.link) return false;
|
|
18859
|
+
const href = m.attrs?.href;
|
|
18860
|
+
return isUrl(href) && bareUrlText(href) === node.text && canFollowBareUrl(next);
|
|
18861
|
+
}
|
|
18862
|
+
var FLATTENED_BLOCK_TYPES = [
|
|
18863
|
+
TextNodeType.paragraph,
|
|
18864
|
+
TextNodeType.heading,
|
|
18865
|
+
TextNodeType.section,
|
|
18866
|
+
TextNodeType.listItem,
|
|
18867
|
+
TextNodeType.taskItem,
|
|
18868
|
+
TextNodeType.codeBlock
|
|
18869
|
+
];
|
|
18870
|
+
var TextAstNormalizer = class {
|
|
18871
|
+
options;
|
|
18872
|
+
constructor(options) {
|
|
18873
|
+
this.options = options;
|
|
18874
|
+
}
|
|
18875
|
+
normalize(ast) {
|
|
18876
|
+
if (!Array.isArray(ast)) return [];
|
|
18877
|
+
const nodes = ast.filter(isNode);
|
|
18878
|
+
if (this.options.chainValue) return this.inline(nodes, { plain: true, chainValue: true });
|
|
18879
|
+
if (this.options.location === TextLocation.tag) {
|
|
18880
|
+
return nodes.flatMap((n) => this.inlineRootNode(n, {}));
|
|
18881
|
+
}
|
|
18882
|
+
return nodes.flatMap((n) => this.block(n));
|
|
18883
|
+
}
|
|
18884
|
+
//
|
|
18885
|
+
// Block context
|
|
18886
|
+
//
|
|
18887
|
+
block(n) {
|
|
18888
|
+
switch (n.type) {
|
|
18889
|
+
case TextNodeType.paragraph:
|
|
18890
|
+
return [{ ...n, content: this.inline(contentOf(n)) }];
|
|
18891
|
+
case TextNodeType.heading:
|
|
18892
|
+
return this.heading(n);
|
|
18893
|
+
case TextNodeType.section:
|
|
18894
|
+
return [paragraph(this.inline(contentOf(n)))];
|
|
18895
|
+
case TextNodeType.image: {
|
|
18896
|
+
const image = this.image(n);
|
|
18897
|
+
return image ? [image] : [];
|
|
18898
|
+
}
|
|
18899
|
+
case TextNodeType.codeBlock:
|
|
18900
|
+
return [{ ...n, content: this.code(contentOf(n)) }];
|
|
18901
|
+
case TextNodeType.text:
|
|
18902
|
+
case TextNodeType.hardBreak:
|
|
18903
|
+
case TextNodeType.imageInline:
|
|
18904
|
+
case TextNodeType.latex:
|
|
18905
|
+
return this.inline([n]);
|
|
18906
|
+
default:
|
|
18907
|
+
if (isList(n)) return this.list(n);
|
|
18908
|
+
if (isListItem(n)) return [paragraph(this.inline(contentOf(n)))];
|
|
18909
|
+
if (isBodyBit(n)) return [n];
|
|
18910
|
+
if (Array.isArray(n.content))
|
|
18911
|
+
return [{ ...n, content: this.blocks(contentOf(n)) }];
|
|
18912
|
+
return [n];
|
|
18913
|
+
}
|
|
18914
|
+
}
|
|
18915
|
+
blocks(nodes) {
|
|
18916
|
+
return nodes.flatMap((n) => this.block(n));
|
|
18917
|
+
}
|
|
18918
|
+
heading(n) {
|
|
18919
|
+
const level = attrsOf2(n).level;
|
|
18920
|
+
if (level != null && !isHeadingLevel(level)) {
|
|
18921
|
+
return [paragraph(this.inline(contentOf(n)))];
|
|
18922
|
+
}
|
|
18923
|
+
const content = this.inline(contentOf(n), { singleLine: true });
|
|
18924
|
+
if (!hasText(content)) return [];
|
|
18925
|
+
return [{ ...n, content }];
|
|
18926
|
+
}
|
|
18927
|
+
image(n) {
|
|
18928
|
+
const attrs = attrsOf2(n);
|
|
18929
|
+
if (!isUrlHttp(attrs.src)) return void 0;
|
|
18930
|
+
return asNode({ ...n, attrs: { src: attrs.src, ...sanitizeMediaAttrs("image", attrs) } });
|
|
18931
|
+
}
|
|
18932
|
+
code(nodes) {
|
|
18933
|
+
const result = [];
|
|
18934
|
+
for (const n of nodes) {
|
|
18935
|
+
if (n.type === TextNodeType.text) {
|
|
18936
|
+
if (typeof n.text === "string" && n.text) {
|
|
18937
|
+
result.push({ type: TextNodeType.text, text: n.text });
|
|
18938
|
+
}
|
|
18939
|
+
} else if (n.type === TextNodeType.hardBreak) {
|
|
18940
|
+
result.push(hardBreak());
|
|
18941
|
+
} else {
|
|
18942
|
+
result.push(...this.code(contentOf(n)));
|
|
18943
|
+
}
|
|
18944
|
+
}
|
|
18945
|
+
return result;
|
|
18946
|
+
}
|
|
18947
|
+
//
|
|
18948
|
+
// List context
|
|
18949
|
+
//
|
|
18950
|
+
list(n) {
|
|
18951
|
+
const attrs = attrsOf2(n);
|
|
18952
|
+
const ordered = ORDERED_LIST_TYPES.indexOf(n.type) !== -1;
|
|
18953
|
+
let start;
|
|
18954
|
+
if (ordered && attrs.start != null) {
|
|
18955
|
+
start = toUInt(attrs.start);
|
|
18956
|
+
if (start === void 0) {
|
|
18957
|
+
return contentOf(n).map(
|
|
18958
|
+
(item) => paragraph(this.inline([item], { stripLeadingTabs: true }))
|
|
18959
|
+
);
|
|
18960
|
+
}
|
|
18961
|
+
}
|
|
18962
|
+
const items = [];
|
|
18963
|
+
for (const child of contentOf(n)) {
|
|
18964
|
+
if (isListItem(child)) {
|
|
18965
|
+
items.push(...this.listItem(child));
|
|
18966
|
+
} else {
|
|
18967
|
+
items.push(...this.listItem({ type: TextNodeType.listItem, content: [child] }));
|
|
18968
|
+
}
|
|
18969
|
+
}
|
|
18970
|
+
if (items.length === 0) return [];
|
|
18971
|
+
const newAttrs = { ...attrs };
|
|
18972
|
+
if (ordered && start !== void 0) newAttrs.start = start;
|
|
18973
|
+
return [asNode({ ...n, attrs: newAttrs, content: items })];
|
|
18974
|
+
}
|
|
18975
|
+
/**
|
|
18976
|
+
* A list item holds a paragraph, then at most one sublist. Everything else is merged into the
|
|
18977
|
+
* paragraph; further sublists become new items (with an empty paragraph, which keeps them
|
|
18978
|
+
* attached). Returns the resulting item(s).
|
|
18979
|
+
*/
|
|
18980
|
+
listItem(item) {
|
|
18981
|
+
const inlineOpts = { stripLeadingTabs: true };
|
|
18982
|
+
const acc = {};
|
|
18983
|
+
let sublist;
|
|
18984
|
+
const extraItems = [];
|
|
18985
|
+
const merge = (inline) => {
|
|
18986
|
+
if (!acc.para) acc.para = inline;
|
|
18987
|
+
else if (inline.length > 0) acc.para.push(hardBreak(), ...inline);
|
|
18988
|
+
};
|
|
18989
|
+
for (const child of contentOf(item)) {
|
|
18990
|
+
if (isList(child)) {
|
|
18991
|
+
for (const list of this.list(child)) {
|
|
18992
|
+
if (list.type === TextNodeType.paragraph) {
|
|
18993
|
+
merge(list.content ?? []);
|
|
18994
|
+
} else if (!sublist) {
|
|
18995
|
+
sublist = list;
|
|
18996
|
+
} else {
|
|
18997
|
+
extraItems.push({ ...item, content: [paragraph([]), list] });
|
|
18998
|
+
}
|
|
18999
|
+
}
|
|
19000
|
+
} else if (child.type === TextNodeType.image) ; else {
|
|
19001
|
+
merge(this.inline([child], inlineOpts));
|
|
19002
|
+
}
|
|
19003
|
+
}
|
|
19004
|
+
const paraContent = acc.para ?? [];
|
|
19005
|
+
if (!hasText(paraContent) && !sublist) return extraItems;
|
|
19006
|
+
const content = [paragraph(paraContent)];
|
|
19007
|
+
if (sublist) content.push(sublist);
|
|
19008
|
+
return [{ ...item, content }, ...extraItems];
|
|
19009
|
+
}
|
|
19010
|
+
//
|
|
19011
|
+
// Inline context
|
|
19012
|
+
//
|
|
19013
|
+
/** A root node at tag location: paragraphs of inline content only */
|
|
19014
|
+
inlineRootNode(n, opts) {
|
|
19015
|
+
switch (n.type) {
|
|
19016
|
+
case TextNodeType.text:
|
|
19017
|
+
case TextNodeType.hardBreak:
|
|
19018
|
+
case TextNodeType.imageInline:
|
|
19019
|
+
case TextNodeType.latex:
|
|
19020
|
+
return this.inline([n], opts);
|
|
19021
|
+
case TextNodeType.image:
|
|
19022
|
+
return [];
|
|
19023
|
+
default:
|
|
19024
|
+
if (isBodyBit(n)) return [n];
|
|
19025
|
+
if (isList(n)) {
|
|
19026
|
+
return contentOf(n).map(
|
|
19027
|
+
(item) => paragraph(this.inline([item], { ...opts, stripLeadingTabs: true }))
|
|
19028
|
+
);
|
|
19029
|
+
}
|
|
19030
|
+
return [paragraph(this.inline(contentOf(n), opts))];
|
|
19031
|
+
}
|
|
19032
|
+
}
|
|
19033
|
+
inline(nodes, opts = {}) {
|
|
19034
|
+
const result = [];
|
|
19035
|
+
const separator = () => opts.singleLine ? this.spaceText() : hardBreak();
|
|
19036
|
+
const separate = () => {
|
|
19037
|
+
if (result.length > 0 && !isHardBreak(result[result.length - 1])) result.push(separator());
|
|
19038
|
+
};
|
|
19039
|
+
for (const n of nodes) {
|
|
19040
|
+
switch (n.type) {
|
|
19041
|
+
case TextNodeType.text: {
|
|
19042
|
+
const text = this.text(n, opts);
|
|
19043
|
+
if (text) result.push(text);
|
|
19044
|
+
break;
|
|
19045
|
+
}
|
|
19046
|
+
case TextNodeType.hardBreak:
|
|
19047
|
+
result.push(separator());
|
|
19048
|
+
break;
|
|
19049
|
+
case TextNodeType.imageInline: {
|
|
19050
|
+
if (opts.plain) break;
|
|
19051
|
+
const image = this.imageInline(n);
|
|
19052
|
+
if (image) result.push(image);
|
|
19053
|
+
break;
|
|
19054
|
+
}
|
|
19055
|
+
case TextNodeType.latex:
|
|
19056
|
+
if (opts.plain) break;
|
|
19057
|
+
if (typeof attrsOf2(n).formula === "string") result.push(n);
|
|
19058
|
+
break;
|
|
19059
|
+
case TextNodeType.image:
|
|
19060
|
+
break;
|
|
19061
|
+
default:
|
|
19062
|
+
if (isBodyBit(n)) {
|
|
19063
|
+
result.push(n);
|
|
19064
|
+
} else if (isList(n)) {
|
|
19065
|
+
for (const item of contentOf(n)) {
|
|
19066
|
+
separate();
|
|
19067
|
+
result.push(...this.inline([item], opts));
|
|
19068
|
+
}
|
|
19069
|
+
} else if (FLATTENED_BLOCK_TYPES.indexOf(n.type) !== -1) {
|
|
19070
|
+
separate();
|
|
19071
|
+
result.push(...this.inline(contentOf(n), opts));
|
|
19072
|
+
} else if (Array.isArray(n.content)) {
|
|
19073
|
+
result.push({ ...n, content: this.inline(contentOf(n), opts) });
|
|
19074
|
+
} else {
|
|
19075
|
+
result.push(n);
|
|
19076
|
+
}
|
|
19077
|
+
}
|
|
19078
|
+
}
|
|
19079
|
+
return this.dropSymbolsBeforePipes(result);
|
|
19080
|
+
}
|
|
19081
|
+
/**
|
|
19082
|
+
* A symbol's media chain swallows every following `...|` segment on its line (even when sealed
|
|
19083
|
+
* with `^`), so a symbol mark has no representable form when the rest of the line contains `|`.
|
|
19084
|
+
*/
|
|
19085
|
+
dropSymbolsBeforePipes(nodes) {
|
|
19086
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
19087
|
+
const n = nodes[i];
|
|
19088
|
+
if (!n.marks?.some((m) => m.type === TextMarkType.symbol)) continue;
|
|
19089
|
+
let pipeFollows = false;
|
|
19090
|
+
for (let j = i + 1; j < nodes.length && !isHardBreak(nodes[j]); j++) {
|
|
19091
|
+
const text = nodes[j].text;
|
|
19092
|
+
if (typeof text !== "string") continue;
|
|
19093
|
+
const firstLine = text.split(/[\n\r\u2028\u2029]/, 1)[0];
|
|
19094
|
+
if (firstLine.indexOf("|") !== -1) pipeFollows = true;
|
|
19095
|
+
if (hasLineTerminator(text)) break;
|
|
19096
|
+
}
|
|
19097
|
+
if (pipeFollows) {
|
|
19098
|
+
const marks = n.marks.filter((m) => m.type !== TextMarkType.symbol);
|
|
19099
|
+
const { marks: _m, ...rest } = n;
|
|
19100
|
+
nodes[i] = marks.length > 0 ? { ...rest, marks } : rest;
|
|
19101
|
+
}
|
|
19102
|
+
}
|
|
19103
|
+
return nodes;
|
|
19104
|
+
}
|
|
19105
|
+
text(n, opts) {
|
|
19106
|
+
if (typeof n.text !== "string") return void 0;
|
|
19107
|
+
let text = n.text;
|
|
19108
|
+
if (opts.stripLeadingTabs) text = text.replace(LEADING_TAB_REGEX, "$1");
|
|
19109
|
+
if (opts.singleLine) text = text.replace(/[\n\r\u2028\u2029]+/g, " ");
|
|
19110
|
+
if (!text) return void 0;
|
|
19111
|
+
const marks = sanitizeMarks(n.marks, {
|
|
19112
|
+
chainValue: opts.chainValue,
|
|
19113
|
+
normalizeChainValue: (content) => this.chainValue(content)
|
|
19114
|
+
});
|
|
19115
|
+
const { marks: _m, ...rest } = n;
|
|
19116
|
+
return marks.length > 0 ? { ...rest, text, marks } : { ...rest, text };
|
|
19117
|
+
}
|
|
19118
|
+
spaceText() {
|
|
19119
|
+
return { type: TextNodeType.text, text: " " };
|
|
19120
|
+
}
|
|
19121
|
+
imageInline(n) {
|
|
19122
|
+
const attrs = attrsOf2(n);
|
|
19123
|
+
if (!isUrl(attrs.src)) return void 0;
|
|
19124
|
+
const alt = attrs.alt;
|
|
19125
|
+
if (!isInlineAlt(alt)) return void 0;
|
|
19126
|
+
return asNode({
|
|
19127
|
+
...n,
|
|
19128
|
+
attrs: { src: attrs.src, alt, ...sanitizeMediaAttrs("imageInline", attrs) }
|
|
19129
|
+
});
|
|
19130
|
+
}
|
|
19131
|
+
/**
|
|
19132
|
+
* Footnote content: a `|`-free single line of plain text with short-form standard marks.
|
|
19133
|
+
* Returns undefined when the content cannot be represented.
|
|
19134
|
+
*/
|
|
19135
|
+
chainValue(content) {
|
|
19136
|
+
if (!Array.isArray(content)) return [];
|
|
19137
|
+
const nodes = this.inline(content.filter(isNode), {
|
|
19138
|
+
plain: true,
|
|
19139
|
+
chainValue: true,
|
|
19140
|
+
singleLine: true
|
|
19141
|
+
});
|
|
19142
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
19143
|
+
const n = nodes[i];
|
|
19144
|
+
const text = n.text;
|
|
19145
|
+
if (typeof text === "string" && (text.indexOf("|") !== -1 || hasLineTerminator(text))) {
|
|
19146
|
+
return void 0;
|
|
19147
|
+
}
|
|
19148
|
+
if (n.marks?.some((m) => m.type === TextMarkType.link) && !isSimpleLinkNode(n, nodes[i + 1])) {
|
|
19149
|
+
const { marks: _m, ...rest } = n;
|
|
19150
|
+
nodes[i] = rest;
|
|
19151
|
+
}
|
|
19152
|
+
}
|
|
19153
|
+
return nodes;
|
|
19154
|
+
}
|
|
19155
|
+
};
|
|
19156
|
+
function normalizeTextAst(ast, options) {
|
|
19157
|
+
return new TextAstNormalizer(options).normalize(ast);
|
|
19158
|
+
}
|
|
19159
|
+
|
|
18311
19160
|
// src/generator/text/TextGenerator.ts
|
|
18312
19161
|
var DEFAULT_OPTIONS = {
|
|
18313
19162
|
bodyBitCallback: void 0,
|
|
@@ -18400,21 +19249,9 @@ var INLINE_MARK_TYPES = [
|
|
|
18400
19249
|
TextMarkType.colorPicker,
|
|
18401
19250
|
TextMarkType.comment
|
|
18402
19251
|
];
|
|
18403
|
-
var HIGHLIGHT_COLORS = [
|
|
18404
|
-
"orange",
|
|
18405
|
-
"yellow",
|
|
18406
|
-
"green",
|
|
18407
|
-
"blue",
|
|
18408
|
-
"purple",
|
|
18409
|
-
"pink",
|
|
18410
|
-
"brown",
|
|
18411
|
-
"white",
|
|
18412
|
-
"black",
|
|
18413
|
-
"gray"
|
|
18414
|
-
];
|
|
18415
19252
|
var INDENTATION_REGEX = new RegExp(/(\n|\r\n)/, "g");
|
|
18416
|
-
var LINK_REGEX = new RegExp(/https?:\/\/|mailto:(.*)/, "g");
|
|
18417
19253
|
var LINK_BREAKSCAPE_REGEX = new RegExp(/\]/, "g");
|
|
19254
|
+
var CHAIN_CONTINUATION_REGEX = /^[^\n\r\u2028\u2029]*\|/;
|
|
18418
19255
|
var Stage = {
|
|
18419
19256
|
enter: "enter",
|
|
18420
19257
|
between: "between",
|
|
@@ -18443,6 +19280,8 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18443
19280
|
textDepth = 0;
|
|
18444
19281
|
placeholderIndex = 0;
|
|
18445
19282
|
placeholders = {};
|
|
19283
|
+
chainJustClosed = false;
|
|
19284
|
+
simpleLinkAllowed = true;
|
|
18446
19285
|
// For pre-text
|
|
18447
19286
|
rootParagraphNodeContentIndex = 0;
|
|
18448
19287
|
previousRootParagraphContextType = TextNodeType.text;
|
|
@@ -18494,6 +19333,11 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18494
19333
|
generateSync(ast, textFormat, textLocation, options) {
|
|
18495
19334
|
if (!ast || !Array.isArray(ast)) return "";
|
|
18496
19335
|
this.generateOptions = Object.assign({}, options);
|
|
19336
|
+
ast = normalizeTextAst(ast, {
|
|
19337
|
+
format: textFormat ?? TextFormat.bitmarkText,
|
|
19338
|
+
location: textLocation,
|
|
19339
|
+
chainValue: this.generateOptions.chainValueContext
|
|
19340
|
+
});
|
|
18497
19341
|
this.validateGenerateOptions(ast);
|
|
18498
19342
|
if (!this.generateOptions.plainTextDividerAllowed) {
|
|
18499
19343
|
this.resetState(textFormat, textLocation);
|
|
@@ -18537,6 +19381,8 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18537
19381
|
this.textDepth = 0;
|
|
18538
19382
|
this.placeholderIndex = 0;
|
|
18539
19383
|
this.placeholders = {};
|
|
19384
|
+
this.chainJustClosed = false;
|
|
19385
|
+
this.simpleLinkAllowed = true;
|
|
18540
19386
|
this.rootParagraphNodeContentIndex = 0;
|
|
18541
19387
|
this.previousRootParagraphContextType = TextNodeType.hardBreak;
|
|
18542
19388
|
this.inPreText = false;
|
|
@@ -18602,6 +19448,7 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18602
19448
|
this.writeHardBreak(node);
|
|
18603
19449
|
break;
|
|
18604
19450
|
case TextNodeType.text: {
|
|
19451
|
+
this.simpleLinkAllowed = this.isSimpleLinkAllowedAfter(route);
|
|
18605
19452
|
this.writeMarks(node, Stage.enter);
|
|
18606
19453
|
this.writeText(node);
|
|
18607
19454
|
this.writeMarks(node, Stage.between);
|
|
@@ -18615,9 +19462,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18615
19462
|
this.writeHeading(node);
|
|
18616
19463
|
this.inHeading = true;
|
|
18617
19464
|
break;
|
|
18618
|
-
case TextNodeType.section:
|
|
18619
|
-
this.writeSection(node);
|
|
18620
|
-
break;
|
|
18621
19465
|
case TextNodeType.listItem:
|
|
18622
19466
|
case TextNodeType.taskItem:
|
|
18623
19467
|
this.writeBullet(node, route);
|
|
@@ -18673,7 +19517,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18673
19517
|
break;
|
|
18674
19518
|
case TextNodeType.heading:
|
|
18675
19519
|
this.inHeading = false;
|
|
18676
|
-
case TextNodeType.section:
|
|
18677
19520
|
case TextNodeType.image:
|
|
18678
19521
|
if (!this.inParagraph) {
|
|
18679
19522
|
this.writeNL();
|
|
@@ -18782,9 +19625,9 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18782
19625
|
*/
|
|
18783
19626
|
getLinkHref(node) {
|
|
18784
19627
|
if (node.type === TextNodeType.text && node.marks) {
|
|
18785
|
-
const href = node.marks.reduce((acc,
|
|
18786
|
-
if (
|
|
18787
|
-
const linkMark =
|
|
19628
|
+
const href = node.marks.reduce((acc, mark2) => {
|
|
19629
|
+
if (mark2.type === TextMarkType.link) {
|
|
19630
|
+
const linkMark = mark2;
|
|
18788
19631
|
const href2 = linkMark.attrs?.href;
|
|
18789
19632
|
if (href2) return href2;
|
|
18790
19633
|
}
|
|
@@ -18849,6 +19692,9 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18849
19692
|
const indentationString = this.getIndentationString();
|
|
18850
19693
|
s = s.replace(INDENTATION_REGEX, `$1${indentationString}`);
|
|
18851
19694
|
}
|
|
19695
|
+
if (this.chainJustClosed && CHAIN_CONTINUATION_REGEX.test(s)) {
|
|
19696
|
+
s = `^${s}`;
|
|
19697
|
+
}
|
|
18852
19698
|
if (this.havePreText && this.rootParagraphNodeContentIndex === this.preTextIndex) {
|
|
18853
19699
|
this.writePlainTextDivider();
|
|
18854
19700
|
this.writeNL();
|
|
@@ -18878,14 +19724,14 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18878
19724
|
* @returns true if a simple link, otherwise false
|
|
18879
19725
|
*/
|
|
18880
19726
|
isSimpleLink(node) {
|
|
18881
|
-
|
|
18882
|
-
|
|
18883
|
-
|
|
18884
|
-
|
|
18885
|
-
|
|
18886
|
-
|
|
18887
|
-
|
|
18888
|
-
return
|
|
19727
|
+
return this.simpleLinkAllowed && isSimpleLinkNode(node, void 0);
|
|
19728
|
+
}
|
|
19729
|
+
/**
|
|
19730
|
+
* The bare-URL link short form is only safe when whatever is written next cannot be read as
|
|
19731
|
+
* part of the URL (the parser's Url rule consumes every following UrlChar).
|
|
19732
|
+
*/
|
|
19733
|
+
isSimpleLinkAllowedAfter(route) {
|
|
19734
|
+
return canFollowBareUrl(this.getSiblingNodes(route).right);
|
|
18889
19735
|
}
|
|
18890
19736
|
/**
|
|
18891
19737
|
* Get the link text if the node is a link, otherwise return false
|
|
@@ -18897,15 +19743,8 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18897
19743
|
if (node.text == null) return false;
|
|
18898
19744
|
const href = this.getLinkHref(node);
|
|
18899
19745
|
if (href) {
|
|
18900
|
-
|
|
18901
|
-
|
|
18902
|
-
if (hrefText === node.text) {
|
|
18903
|
-
res = href;
|
|
18904
|
-
} else {
|
|
18905
|
-
res = node.text;
|
|
18906
|
-
}
|
|
18907
|
-
res = (res ?? "").replace(LINK_BREAKSCAPE_REGEX, "^]");
|
|
18908
|
-
return res;
|
|
19746
|
+
const res = this.isSimpleLink(node) ? href : node.text;
|
|
19747
|
+
return res.replace(LINK_BREAKSCAPE_REGEX, "^]");
|
|
18909
19748
|
}
|
|
18910
19749
|
return false;
|
|
18911
19750
|
}
|
|
@@ -18962,22 +19801,17 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18962
19801
|
writeMarks(node, stage) {
|
|
18963
19802
|
if (node.marks) {
|
|
18964
19803
|
const forceSingleMark = this.generateOptions.forceInline || !!(this.inInline || this.inHeading);
|
|
18965
|
-
|
|
18966
|
-
const emptyMarks = node.marks.length === 0;
|
|
18967
|
-
if (emptyMarks) {
|
|
18968
|
-
this.writeMarkTextWrapper(INLINE_MARK);
|
|
18969
|
-
return;
|
|
18970
|
-
}
|
|
18971
|
-
const marks = this.getWritableMarks(node.marks);
|
|
19804
|
+
const marks = node.marks;
|
|
18972
19805
|
if (marks.length === 0) return;
|
|
19806
|
+
this.thisNodeIsPreText = false;
|
|
18973
19807
|
const singleMark = marks.length === 1 && forceSingleMark;
|
|
18974
19808
|
const markStartEnd = marks.reduce(
|
|
18975
|
-
(acc,
|
|
19809
|
+
(acc, mark2) => {
|
|
18976
19810
|
if (acc) return acc;
|
|
18977
|
-
if (this.isStandardMark(
|
|
18978
|
-
if (singleMark) return STANDARD_MARKS[
|
|
19811
|
+
if (this.isStandardMark(mark2)) {
|
|
19812
|
+
if (singleMark) return STANDARD_MARKS[mark2.type];
|
|
18979
19813
|
return INLINE_MARK;
|
|
18980
|
-
} else if (this.isInlineMark(
|
|
19814
|
+
} else if (this.isInlineMark(mark2)) {
|
|
18981
19815
|
return INLINE_MARK;
|
|
18982
19816
|
} else ;
|
|
18983
19817
|
return acc;
|
|
@@ -18991,54 +19825,57 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18991
19825
|
this.writeMarkTextWrapper(markStartEnd);
|
|
18992
19826
|
}
|
|
18993
19827
|
if (stage == Stage.between) {
|
|
18994
|
-
for (const
|
|
18995
|
-
if (this.isStandardMark(
|
|
19828
|
+
for (const mark2 of marks) {
|
|
19829
|
+
if (this.isStandardMark(mark2)) {
|
|
18996
19830
|
if (!singleMark) {
|
|
18997
19831
|
this.writeInlineMarkStartEnd();
|
|
18998
|
-
this.writeInlineMark(
|
|
19832
|
+
this.writeInlineMark(mark2);
|
|
18999
19833
|
}
|
|
19000
|
-
} else if (TextMarkType.comment ===
|
|
19834
|
+
} else if (TextMarkType.comment === mark2.type) {
|
|
19001
19835
|
this.writeInlineMarkStartEnd();
|
|
19002
|
-
this.writeCommentMark(
|
|
19003
|
-
} else if (TextMarkType.link ===
|
|
19836
|
+
this.writeCommentMark(mark2);
|
|
19837
|
+
} else if (TextMarkType.link === mark2.type) {
|
|
19004
19838
|
this.writeInlineMarkStartEnd();
|
|
19005
|
-
this.writeLinkMark(
|
|
19006
|
-
} else if (TextMarkType.ref ===
|
|
19839
|
+
this.writeLinkMark(mark2);
|
|
19840
|
+
} else if (TextMarkType.ref === mark2.type) {
|
|
19007
19841
|
this.writeInlineMarkStartEnd();
|
|
19008
|
-
this.writeRefMark(
|
|
19009
|
-
} else if (TextMarkType.xref ===
|
|
19842
|
+
this.writeRefMark(mark2);
|
|
19843
|
+
} else if (TextMarkType.xref === mark2.type) {
|
|
19010
19844
|
this.writeInlineMarkStartEnd();
|
|
19011
|
-
this.writeXRefMark(
|
|
19012
|
-
} else if (TextMarkType.extref ===
|
|
19845
|
+
this.writeXRefMark(mark2);
|
|
19846
|
+
} else if (TextMarkType.extref === mark2.type) {
|
|
19013
19847
|
this.writeInlineMarkStartEnd();
|
|
19014
|
-
this.writeExtRefMark(
|
|
19015
|
-
} else if (TextMarkType.footnote ===
|
|
19848
|
+
this.writeExtRefMark(mark2);
|
|
19849
|
+
} else if (TextMarkType.footnote === mark2.type) {
|
|
19016
19850
|
this.writeInlineMarkStartEnd();
|
|
19017
|
-
this.writeFootnoteMark(
|
|
19018
|
-
} else if (TextMarkType.footnoteStar ===
|
|
19851
|
+
this.writeFootnoteMark(mark2);
|
|
19852
|
+
} else if (TextMarkType.footnoteStar === mark2.type) {
|
|
19019
19853
|
this.writeInlineMarkStartEnd();
|
|
19020
|
-
this.writeFootnoteStarMark(
|
|
19021
|
-
} else if (TextMarkType.symbol ===
|
|
19854
|
+
this.writeFootnoteStarMark(mark2);
|
|
19855
|
+
} else if (TextMarkType.symbol === mark2.type) {
|
|
19022
19856
|
this.writeInlineMarkStartEnd();
|
|
19023
|
-
this.writeSymbolMark(
|
|
19024
|
-
} else if (this.isInlineMark(
|
|
19857
|
+
this.writeSymbolMark(mark2);
|
|
19858
|
+
} else if (this.isInlineMark(mark2)) {
|
|
19025
19859
|
this.writeInlineMarkStartEnd();
|
|
19026
|
-
this.writeInlineMark(
|
|
19860
|
+
this.writeInlineMark(mark2);
|
|
19027
19861
|
} else ;
|
|
19028
19862
|
}
|
|
19029
19863
|
}
|
|
19030
19864
|
if (stage == Stage.exit) {
|
|
19031
19865
|
let inlineMarkWritten = false;
|
|
19032
|
-
for (const
|
|
19033
|
-
if (this.isStandardMark(
|
|
19866
|
+
for (const mark2 of marks) {
|
|
19867
|
+
if (this.isStandardMark(mark2)) {
|
|
19034
19868
|
if (!singleMark) {
|
|
19035
19869
|
inlineMarkWritten = true;
|
|
19036
19870
|
}
|
|
19037
|
-
} else if (TextMarkType.comment ===
|
|
19871
|
+
} else if (TextMarkType.comment === mark2.type || TextMarkType.link === mark2.type || TextMarkType.ref === mark2.type || TextMarkType.xref === mark2.type || TextMarkType.footnote === mark2.type || TextMarkType.footnoteStar === mark2.type || this.isInlineMark(mark2)) {
|
|
19038
19872
|
inlineMarkWritten = true;
|
|
19039
19873
|
} else ;
|
|
19040
19874
|
}
|
|
19041
|
-
if (inlineMarkWritten)
|
|
19875
|
+
if (inlineMarkWritten) {
|
|
19876
|
+
this.writeInlineMarkStartEnd();
|
|
19877
|
+
this.chainJustClosed = true;
|
|
19878
|
+
}
|
|
19042
19879
|
}
|
|
19043
19880
|
}
|
|
19044
19881
|
}
|
|
@@ -19074,15 +19911,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19074
19911
|
s += " ";
|
|
19075
19912
|
this.write(s);
|
|
19076
19913
|
}
|
|
19077
|
-
writeSection(node) {
|
|
19078
|
-
let s = "";
|
|
19079
|
-
if (node.section) {
|
|
19080
|
-
s = `|${node.section}: `;
|
|
19081
|
-
} else {
|
|
19082
|
-
s = "|";
|
|
19083
|
-
}
|
|
19084
|
-
this.write(s);
|
|
19085
|
-
}
|
|
19086
19914
|
writeBullet(node, route) {
|
|
19087
19915
|
let bullet = this.getIndentationString();
|
|
19088
19916
|
const listParent = this.getParentNode(route, 2);
|
|
@@ -19105,7 +19933,7 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19105
19933
|
bullet += "\u2022a ";
|
|
19106
19934
|
} else if (listType === TextNodeType.taskList) {
|
|
19107
19935
|
const taskList = node;
|
|
19108
|
-
const checked = taskList.attrs?.checked
|
|
19936
|
+
const checked = taskList.attrs?.checked === true;
|
|
19109
19937
|
bullet += checked ? "\u2022+ " : "\u2022- ";
|
|
19110
19938
|
}
|
|
19111
19939
|
if (bullet) this.write(bullet);
|
|
@@ -19114,28 +19942,20 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19114
19942
|
if (node.attrs == null || !node.attrs.src) return;
|
|
19115
19943
|
const attrs = node.attrs;
|
|
19116
19944
|
const inlineImage = node.type === TextNodeType.imageInline;
|
|
19117
|
-
|
|
19118
|
-
|
|
19119
|
-
ignoreAttributes = /* @__PURE__ */ new Set(["alt", "zoomDisabled", "title"]);
|
|
19120
|
-
const a = attrs;
|
|
19121
|
-
if (a.alignmentVertical === "top") ignoreAttributes.add("alignmentVertical");
|
|
19122
|
-
if (a.size === "line-height") ignoreAttributes.add("size");
|
|
19123
|
-
}
|
|
19124
|
-
const mediaAttrs = this.getMediaAttrs(inlineImage ? "imageInline" : "image", attrs, {
|
|
19125
|
-
ignoreAttributes
|
|
19126
|
-
});
|
|
19945
|
+
const kind = inlineImage ? "imageInline" : "image";
|
|
19946
|
+
const chain = serializeMediaChain(kind, attrs);
|
|
19127
19947
|
let s = "";
|
|
19128
19948
|
if (inlineImage) {
|
|
19129
19949
|
s = `==${attrs.alt ?? ""}==`;
|
|
19130
19950
|
}
|
|
19131
|
-
s +=
|
|
19951
|
+
s += `|${kind}:${attrs.src}${chain}|`;
|
|
19132
19952
|
this.write(s);
|
|
19133
19953
|
}
|
|
19134
19954
|
writeCodeBlock(node) {
|
|
19135
|
-
|
|
19136
|
-
const
|
|
19137
|
-
const s = `|code:${
|
|
19138
|
-
|
|
19955
|
+
const raw = node.attrs?.language ?? node.language;
|
|
19956
|
+
const language = normalizeBlockCodeLanguage(raw) ?? "";
|
|
19957
|
+
const s = language ? `|code:${language}
|
|
19958
|
+
` : "|code\n";
|
|
19139
19959
|
this.write(s);
|
|
19140
19960
|
}
|
|
19141
19961
|
writeLatex(node) {
|
|
@@ -19151,10 +19971,10 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19151
19971
|
writeMarkTextWrapper(s) {
|
|
19152
19972
|
if (s) this.write(s);
|
|
19153
19973
|
}
|
|
19154
|
-
writeInlineMark(
|
|
19155
|
-
const attrs =
|
|
19974
|
+
writeInlineMark(mark2) {
|
|
19975
|
+
const attrs = mark2.attrs ?? {};
|
|
19156
19976
|
let s;
|
|
19157
|
-
switch (
|
|
19977
|
+
switch (mark2.type) {
|
|
19158
19978
|
case TextMarkType.textStyle:
|
|
19159
19979
|
case TextMarkType.color:
|
|
19160
19980
|
s = `color:${attrs.color ?? ""}`;
|
|
@@ -19165,10 +19985,10 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19165
19985
|
break;
|
|
19166
19986
|
case TextMarkType.highlight:
|
|
19167
19987
|
case TextMarkType.userHighlight:
|
|
19168
|
-
s = attrs.color ? `${
|
|
19988
|
+
s = attrs.color ? `${mark2.type}|color:${attrs.color}` : `${mark2.type}`;
|
|
19169
19989
|
break;
|
|
19170
19990
|
default: {
|
|
19171
|
-
s = `${
|
|
19991
|
+
s = `${mark2.type}`;
|
|
19172
19992
|
for (const [k, v] of Object.entries(attrs)) {
|
|
19173
19993
|
if (k === "language" && v !== "plain text" || k === "propertyRef" || k === "name") {
|
|
19174
19994
|
s = `${s}:${v}`;
|
|
@@ -19178,88 +19998,49 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19178
19998
|
}
|
|
19179
19999
|
this.write(s);
|
|
19180
20000
|
}
|
|
19181
|
-
/**
|
|
19182
|
-
* Resolve the marks of a text node into the marks that will actually be written.
|
|
19183
|
-
*
|
|
19184
|
-
* - Merges a legacy standalone 'duration' mark into its sibling 'timer' mark.
|
|
19185
|
-
* - Drops marks the current grammar cannot express (standalone 'duration', 'timer'
|
|
19186
|
-
* without a duration).
|
|
19187
|
-
* - Moves a 'textStyle'/'color' mark before a preceding bare 'highlight'/'userHighlight'
|
|
19188
|
-
* mark when its color is a valid highlight color; written in the original order the
|
|
19189
|
-
* output would re-parse as a highlight-with-color compound mark and change meaning.
|
|
19190
|
-
*/
|
|
19191
|
-
getWritableMarks(nodeMarks) {
|
|
19192
|
-
const attrsOf = (m) => m.attrs ?? {};
|
|
19193
|
-
let marks = [...nodeMarks];
|
|
19194
|
-
const timer = marks.find((m) => m.type === TextMarkType.timer);
|
|
19195
|
-
const duration = marks.find((m) => m.type === TextMarkType.duration);
|
|
19196
|
-
if (timer && duration && !attrsOf(timer).duration) {
|
|
19197
|
-
marks = marks.map(
|
|
19198
|
-
(m) => m === timer ? {
|
|
19199
|
-
...timer,
|
|
19200
|
-
attrs: { ...attrsOf(timer), duration: attrsOf(duration).duration }
|
|
19201
|
-
} : m
|
|
19202
|
-
);
|
|
19203
|
-
}
|
|
19204
|
-
marks = marks.filter((m) => {
|
|
19205
|
-
if (m.type === TextMarkType.duration) return false;
|
|
19206
|
-
if (m.type === TextMarkType.timer) return !!attrsOf(m).duration;
|
|
19207
|
-
return true;
|
|
19208
|
-
});
|
|
19209
|
-
const isBareHighlight = (m) => (m.type === TextMarkType.highlight || m.type === TextMarkType.userHighlight) && !attrsOf(m).color;
|
|
19210
|
-
const isHighlightColorStyle = (m) => (m.type === TextMarkType.textStyle || m.type === TextMarkType.color) && HIGHLIGHT_COLORS.indexOf(attrsOf(m).color) !== -1;
|
|
19211
|
-
for (let i = 0; i < marks.length - 1; i++) {
|
|
19212
|
-
if (isBareHighlight(marks[i]) && isHighlightColorStyle(marks[i + 1])) {
|
|
19213
|
-
const tmp = marks[i];
|
|
19214
|
-
marks[i] = marks[i + 1];
|
|
19215
|
-
marks[i + 1] = tmp;
|
|
19216
|
-
}
|
|
19217
|
-
}
|
|
19218
|
-
return marks;
|
|
19219
|
-
}
|
|
19220
20001
|
/**
|
|
19221
20002
|
* True if the mark is written using its standard form (e.g. **bold**, !!highlight!!)
|
|
19222
20003
|
* when it is the only mark. A highlight mark with a color attribute is excluded - it
|
|
19223
20004
|
* can only be expressed using the inline chain form (==text==|highlight|color:x|).
|
|
19224
20005
|
*/
|
|
19225
|
-
isStandardMark(
|
|
19226
|
-
if (STANDARD_MARK_TYPES.indexOf(
|
|
19227
|
-
return !(
|
|
20006
|
+
isStandardMark(mark2) {
|
|
20007
|
+
if (STANDARD_MARK_TYPES.indexOf(mark2.type) === -1) return false;
|
|
20008
|
+
return !(mark2.attrs && mark2.attrs.color);
|
|
19228
20009
|
}
|
|
19229
20010
|
/**
|
|
19230
20011
|
* True if the mark is written using the inline chain form (==text==|mark|).
|
|
19231
20012
|
*/
|
|
19232
|
-
isInlineMark(
|
|
19233
|
-
if (INLINE_MARK_TYPES.indexOf(
|
|
19234
|
-
return
|
|
20013
|
+
isInlineMark(mark2) {
|
|
20014
|
+
if (INLINE_MARK_TYPES.indexOf(mark2.type) !== -1) return true;
|
|
20015
|
+
return mark2.type === TextMarkType.highlight && !!(mark2.attrs && mark2.attrs.color);
|
|
19235
20016
|
}
|
|
19236
|
-
writeCommentMark(
|
|
19237
|
-
const comment =
|
|
20017
|
+
writeCommentMark(mark2) {
|
|
20018
|
+
const comment = mark2.comment || "";
|
|
19238
20019
|
const s = `#${comment}`;
|
|
19239
20020
|
this.write(s);
|
|
19240
20021
|
}
|
|
19241
|
-
writeLinkMark(
|
|
19242
|
-
const href =
|
|
20022
|
+
writeLinkMark(mark2) {
|
|
20023
|
+
const href = mark2.attrs?.href || "";
|
|
19243
20024
|
const linkText = (href ?? "").replace(LINK_BREAKSCAPE_REGEX, "^]");
|
|
19244
20025
|
const s = `link:${linkText}`;
|
|
19245
20026
|
this.write(s);
|
|
19246
20027
|
}
|
|
19247
|
-
writeRefMark(
|
|
19248
|
-
const ref =
|
|
20028
|
+
writeRefMark(mark2) {
|
|
20029
|
+
const ref = mark2.attrs?.reference ?? "";
|
|
19249
20030
|
const s = `\u25BA${ref}`;
|
|
19250
20031
|
this.write(s);
|
|
19251
20032
|
}
|
|
19252
|
-
writeXRefMark(
|
|
19253
|
-
const xref =
|
|
19254
|
-
const ref =
|
|
20033
|
+
writeXRefMark(mark2) {
|
|
20034
|
+
const xref = mark2.attrs?.xref ?? "";
|
|
20035
|
+
const ref = mark2.attrs?.reference ?? "";
|
|
19255
20036
|
let s = `xref:${xref}`;
|
|
19256
20037
|
if (ref) s += `|\u25BA${ref}`;
|
|
19257
20038
|
this.write(s);
|
|
19258
20039
|
}
|
|
19259
|
-
writeExtRefMark(
|
|
19260
|
-
const extref =
|
|
19261
|
-
const refs =
|
|
19262
|
-
const provider =
|
|
20040
|
+
writeExtRefMark(mark2) {
|
|
20041
|
+
const extref = mark2.attrs?.extref ?? "";
|
|
20042
|
+
const refs = mark2.attrs?.references ?? [];
|
|
20043
|
+
const provider = mark2.attrs?.provider ?? "";
|
|
19263
20044
|
let s = `extref:${extref}`;
|
|
19264
20045
|
for (const ref of refs) {
|
|
19265
20046
|
s += `|\u25BA${ref ?? ""}`;
|
|
@@ -19267,39 +20048,39 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19267
20048
|
s += `|provider:${provider}`;
|
|
19268
20049
|
this.write(s);
|
|
19269
20050
|
}
|
|
19270
|
-
writeFootnoteMark(
|
|
20051
|
+
writeFootnoteMark(mark2) {
|
|
19271
20052
|
const s = `footnote:`;
|
|
19272
20053
|
this.write(s);
|
|
19273
20054
|
const text = this.internalTextGenerator?.generateSync(
|
|
19274
|
-
|
|
20055
|
+
mark2.attrs?.content,
|
|
19275
20056
|
this.textFormat,
|
|
19276
20057
|
this.textLocation,
|
|
19277
20058
|
{
|
|
19278
20059
|
...this.generateOptions,
|
|
19279
|
-
forceInline: true
|
|
20060
|
+
forceInline: true,
|
|
20061
|
+
chainValueContext: true
|
|
19280
20062
|
}
|
|
19281
20063
|
) ?? "";
|
|
19282
20064
|
this.write(text);
|
|
19283
20065
|
}
|
|
19284
|
-
writeFootnoteStarMark(
|
|
20066
|
+
writeFootnoteStarMark(mark2) {
|
|
19285
20067
|
const s = `footnote*:`;
|
|
19286
20068
|
this.write(s);
|
|
19287
20069
|
const text = this.internalTextGenerator?.generateSync(
|
|
19288
|
-
|
|
20070
|
+
mark2.attrs?.content,
|
|
19289
20071
|
this.textFormat,
|
|
19290
20072
|
this.textLocation,
|
|
19291
20073
|
{
|
|
19292
20074
|
...this.generateOptions,
|
|
19293
|
-
forceInline: true
|
|
20075
|
+
forceInline: true,
|
|
20076
|
+
chainValueContext: true
|
|
19294
20077
|
}
|
|
19295
20078
|
) ?? "";
|
|
19296
20079
|
this.write(text);
|
|
19297
20080
|
}
|
|
19298
|
-
writeSymbolMark(
|
|
19299
|
-
|
|
19300
|
-
const
|
|
19301
|
-
const mediaAttrs = this.getMediaAttrs("symbol", attrs);
|
|
19302
|
-
const s = mediaAttrs ?? "";
|
|
20081
|
+
writeSymbolMark(mark2) {
|
|
20082
|
+
const attrs = mark2.attrs ?? {};
|
|
20083
|
+
const s = `symbol:${attrs.src ?? ""}${serializeMediaChain("symbol", attrs)}`;
|
|
19303
20084
|
this.write(s);
|
|
19304
20085
|
}
|
|
19305
20086
|
writeInlineMarkStartEnd() {
|
|
@@ -19329,52 +20110,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19329
20110
|
}
|
|
19330
20111
|
this.writeString(tag);
|
|
19331
20112
|
}
|
|
19332
|
-
getMediaAttrs(mediaType, attrs, options) {
|
|
19333
|
-
if (!mediaType) return void 0;
|
|
19334
|
-
const opts = Object.assign({}, options);
|
|
19335
|
-
const ignoreAttributes = opts.ignoreAttributes ?? /* @__PURE__ */ new Set();
|
|
19336
|
-
let s = `${mediaType}:${attrs?.src ?? ""}`;
|
|
19337
|
-
const entries = Object.entries(attrs).filter(([k, _v]) => k !== "src");
|
|
19338
|
-
for (let i = 0; i < entries.length; i++) {
|
|
19339
|
-
const [k, v] = entries[i];
|
|
19340
|
-
if (ignoreAttributes.has(k)) continue;
|
|
19341
|
-
switch (k) {
|
|
19342
|
-
case "textAlign":
|
|
19343
|
-
if (v !== "left") s += `|captionAlign:${v}`;
|
|
19344
|
-
break;
|
|
19345
|
-
case "alignment":
|
|
19346
|
-
if (v !== "center") {
|
|
19347
|
-
if (v) s += `|alignment:${v}`;
|
|
19348
|
-
}
|
|
19349
|
-
break;
|
|
19350
|
-
case "title":
|
|
19351
|
-
if (v) s += `|caption:${v}`;
|
|
19352
|
-
break;
|
|
19353
|
-
case "class":
|
|
19354
|
-
if (v !== "center") {
|
|
19355
|
-
if (v) s += `|align:${v}`;
|
|
19356
|
-
}
|
|
19357
|
-
break;
|
|
19358
|
-
case "comment":
|
|
19359
|
-
if (v) s += `|#${v}`;
|
|
19360
|
-
break;
|
|
19361
|
-
case "":
|
|
19362
|
-
if (stringUtils.isString(v)) s += `|:${v}`;
|
|
19363
|
-
else s += `|`;
|
|
19364
|
-
break;
|
|
19365
|
-
case "zoomDisabled":
|
|
19366
|
-
if (!v) s += "|zoomDisabled:false";
|
|
19367
|
-
break;
|
|
19368
|
-
case "alt":
|
|
19369
|
-
case "width":
|
|
19370
|
-
case "height":
|
|
19371
|
-
default:
|
|
19372
|
-
if (k && v) s += `|${k}:${v}`;
|
|
19373
|
-
break;
|
|
19374
|
-
}
|
|
19375
|
-
}
|
|
19376
|
-
return s;
|
|
19377
|
-
}
|
|
19378
20113
|
//
|
|
19379
20114
|
// Helper functions
|
|
19380
20115
|
//
|
|
@@ -19400,6 +20135,7 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19400
20135
|
*/
|
|
19401
20136
|
write(value) {
|
|
19402
20137
|
value = this.getInterTextBreakscape(value) + value;
|
|
20138
|
+
this.chainJustClosed = false;
|
|
19403
20139
|
if (this.options.writeCallback) {
|
|
19404
20140
|
this.options.writeCallback(value);
|
|
19405
20141
|
}
|
|
@@ -33432,8 +34168,8 @@ var Builder = class extends BaseBuilder {
|
|
|
33432
34168
|
break;
|
|
33433
34169
|
}
|
|
33434
34170
|
case BodyBitType.mark: {
|
|
33435
|
-
const
|
|
33436
|
-
instance7.fillBooleanExample([
|
|
34171
|
+
const mark2 = part;
|
|
34172
|
+
instance7.fillBooleanExample([mark2], __isDefaultExample, example, false);
|
|
33437
34173
|
break;
|
|
33438
34174
|
}
|
|
33439
34175
|
case BodyBitType.select: {
|
|
@@ -34203,10 +34939,10 @@ var BitmarkGenerator = class extends AstWalkerGenerator {
|
|
|
34203
34939
|
const markConfig = node.value;
|
|
34204
34940
|
const parent = this.getParentNode(route);
|
|
34205
34941
|
if (parent?.key !== NodeType.markConfig) return true;
|
|
34206
|
-
const { mark, color, emphasis } = markConfig;
|
|
34207
|
-
if (
|
|
34942
|
+
const { mark: mark2, color, emphasis } = markConfig;
|
|
34943
|
+
if (mark2) {
|
|
34208
34944
|
this.writeNL();
|
|
34209
|
-
this.writeProperty("mark",
|
|
34945
|
+
this.writeProperty("mark", mark2, route, {
|
|
34210
34946
|
format: TagFormat.plainText
|
|
34211
34947
|
});
|
|
34212
34948
|
if (color) {
|
|
@@ -34423,9 +35159,9 @@ var BitmarkGenerator = class extends AstWalkerGenerator {
|
|
|
34423
35159
|
}
|
|
34424
35160
|
// bodyBit -> mark
|
|
34425
35161
|
enter_mark(node, _route) {
|
|
34426
|
-
const
|
|
35162
|
+
const mark2 = node.value;
|
|
34427
35163
|
this.writeOPE();
|
|
34428
|
-
this.writeTextOrValue(
|
|
35164
|
+
this.writeTextOrValue(mark2.solution, TextFormat.plainText, TextLocation.tag);
|
|
34429
35165
|
this.writeCL();
|
|
34430
35166
|
return true;
|
|
34431
35167
|
}
|
|
@@ -34483,9 +35219,9 @@ var BitmarkGenerator = class extends AstWalkerGenerator {
|
|
|
34483
35219
|
leaf_mark(node, route) {
|
|
34484
35220
|
const root = route[0];
|
|
34485
35221
|
if (root?.key !== NodeType.mark) return;
|
|
34486
|
-
const
|
|
34487
|
-
if (
|
|
34488
|
-
this.writeProperty("mark",
|
|
35222
|
+
const mark2 = node.value;
|
|
35223
|
+
if (mark2) {
|
|
35224
|
+
this.writeProperty("mark", mark2, route, {
|
|
34489
35225
|
format: TagFormat.plainText
|
|
34490
35226
|
});
|
|
34491
35227
|
}
|
|
@@ -35198,7 +35934,7 @@ var BitmarkGenerator = class extends AstWalkerGenerator {
|
|
|
35198
35934
|
leaf_level(node, route) {
|
|
35199
35935
|
const parent = this.getParentNode(route);
|
|
35200
35936
|
if (parent?.key !== NodeType.bitsValue) return true;
|
|
35201
|
-
if (!instance2.isOfBitType(this.bitType, [BitType.chapter])) return true;
|
|
35937
|
+
if (!instance2.isOfBitType(this.bitType, [BitType.chapter, BitType.h])) return true;
|
|
35202
35938
|
const level = node.value;
|
|
35203
35939
|
const bit = parent?.value;
|
|
35204
35940
|
if (level > 0 && bit.title == null) {
|
|
@@ -36237,8 +36973,6 @@ var MARK_TO_TAG = {
|
|
|
36237
36973
|
highlight: "mark",
|
|
36238
36974
|
code: "code"
|
|
36239
36975
|
};
|
|
36240
|
-
var INLINE_IMAGE_RE = /==([^=]*(?:=(?!=)[^=]*)*)==\|imageInline:([^|\s]+)((?:\|(?:@?[A-Za-z][A-Za-z0-9_-]*:[^|\s]+|#[^|\s]*))*)\|?/g;
|
|
36241
|
-
var MAX_IMAGE_DIMENSION = 9999;
|
|
36242
36976
|
var HtmlTableGenerator = class {
|
|
36243
36977
|
indentUnit = " ";
|
|
36244
36978
|
/**
|
|
@@ -36378,13 +37112,13 @@ var HtmlTableGenerator = class {
|
|
|
36378
37112
|
if (!marks || marks.length === 0) return text;
|
|
36379
37113
|
let open = "";
|
|
36380
37114
|
let close = "";
|
|
36381
|
-
for (const
|
|
36382
|
-
if (
|
|
36383
|
-
const href =
|
|
37115
|
+
for (const mark2 of marks) {
|
|
37116
|
+
if (mark2.type === "link") {
|
|
37117
|
+
const href = mark2.attrs?.href ?? "";
|
|
36384
37118
|
open += `<a href="${this.escapeAttr(href)}">`;
|
|
36385
37119
|
close = `</a>${close}`;
|
|
36386
37120
|
} else {
|
|
36387
|
-
const tag = MARK_TO_TAG[
|
|
37121
|
+
const tag = MARK_TO_TAG[mark2.type];
|
|
36388
37122
|
if (tag) {
|
|
36389
37123
|
open += `<${tag}>`;
|
|
36390
37124
|
close = `</${tag}>${close}`;
|
|
@@ -36448,37 +37182,7 @@ var HtmlTableGenerator = class {
|
|
|
36448
37182
|
return `<img ${parts.join(" ")}>`;
|
|
36449
37183
|
}
|
|
36450
37184
|
textToHtml(text) {
|
|
36451
|
-
|
|
36452
|
-
let lastIndex = 0;
|
|
36453
|
-
for (const match of text.matchAll(INLINE_IMAGE_RE)) {
|
|
36454
|
-
const index = match.index ?? 0;
|
|
36455
|
-
html += this.escapeText(text.slice(lastIndex, index));
|
|
36456
|
-
html += this.inlineImageTokenToHtml(match);
|
|
36457
|
-
lastIndex = index + match[0].length;
|
|
36458
|
-
}
|
|
36459
|
-
html += this.escapeText(text.slice(lastIndex));
|
|
36460
|
-
return html;
|
|
36461
|
-
}
|
|
36462
|
-
inlineImageTokenToHtml(match) {
|
|
36463
|
-
const attrs = {
|
|
36464
|
-
alt: match[1],
|
|
36465
|
-
src: match[2]
|
|
36466
|
-
};
|
|
36467
|
-
const rawAttrs = match[3] ?? "";
|
|
36468
|
-
for (const attr of rawAttrs.split("|")) {
|
|
36469
|
-
if (!attr || attr.startsWith("#")) continue;
|
|
36470
|
-
const colon = attr.indexOf(":");
|
|
36471
|
-
if (colon < 1) continue;
|
|
36472
|
-
const key = attr.slice(0, colon).replace(/^@/, "");
|
|
36473
|
-
const value = attr.slice(colon + 1);
|
|
36474
|
-
if (key === "width" || key === "height") {
|
|
36475
|
-
const n = Number.parseInt(value, 10);
|
|
36476
|
-
if (!Number.isNaN(n) && n > 0 && n <= MAX_IMAGE_DIMENSION) attrs[key] = n;
|
|
36477
|
-
} else if (key === "class" || key === "title") {
|
|
36478
|
-
attrs[key] = value;
|
|
36479
|
-
}
|
|
36480
|
-
}
|
|
36481
|
-
return this.imageToHtml({ type: "imageInline", attrs });
|
|
37185
|
+
return this.escapeText(text);
|
|
36482
37186
|
}
|
|
36483
37187
|
// --- formulas -------------------------------------------------------------
|
|
36484
37188
|
latexToHtml(node) {
|
|
@@ -40891,13 +41595,13 @@ function markChainContentProcessor(context, contentDepth, tagsConfig, content, t
|
|
|
40891
41595
|
if (contentDepth === ContentDepth.Chain) {
|
|
40892
41596
|
markTagContentProcessor(context, ContentDepth.Chain, content, target);
|
|
40893
41597
|
} else {
|
|
40894
|
-
const
|
|
41598
|
+
const mark2 = buildMark(
|
|
40895
41599
|
context,
|
|
40896
41600
|
contentDepth,
|
|
40897
41601
|
tagsConfig,
|
|
40898
41602
|
content
|
|
40899
41603
|
);
|
|
40900
|
-
if (
|
|
41604
|
+
if (mark2) bodyParts.push(mark2);
|
|
40901
41605
|
}
|
|
40902
41606
|
}
|
|
40903
41607
|
function buildMark(context, _contentDepth, tagsConfig, content) {
|
|
@@ -40912,13 +41616,13 @@ function buildMark(context, _contentDepth, tagsConfig, content) {
|
|
|
40912
41616
|
if (context.DEBUG_CHAIN_TAGS) context.debugPrint("mark TAGS", chainTags);
|
|
40913
41617
|
const { solution } = tags2;
|
|
40914
41618
|
const { mark: markType, ...rest } = chainTags;
|
|
40915
|
-
const
|
|
41619
|
+
const mark2 = {
|
|
40916
41620
|
type: BodyBitType.mark,
|
|
40917
41621
|
solution: solution ?? "",
|
|
40918
41622
|
mark: instance4.asSingle(markType) ?? "",
|
|
40919
41623
|
...rest
|
|
40920
41624
|
};
|
|
40921
|
-
return
|
|
41625
|
+
return mark2;
|
|
40922
41626
|
}
|
|
40923
41627
|
|
|
40924
41628
|
// src/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.ts
|
|
@@ -41160,7 +41864,7 @@ function markConfigChainContentProcessor(context, _contentDepth, tagsConfig, con
|
|
|
41160
41864
|
content.chain
|
|
41161
41865
|
);
|
|
41162
41866
|
if (context.DEBUG_CHAIN_TAGS) context.debugPrint("mark TAGS", tags2);
|
|
41163
|
-
const
|
|
41867
|
+
const mark2 = instance3.unbreakscape(
|
|
41164
41868
|
stringUtils.trimmedString(content.value) ?? "unknown",
|
|
41165
41869
|
{
|
|
41166
41870
|
format: TextFormat.bitmarkText,
|
|
@@ -41168,7 +41872,7 @@ function markConfigChainContentProcessor(context, _contentDepth, tagsConfig, con
|
|
|
41168
41872
|
}
|
|
41169
41873
|
);
|
|
41170
41874
|
const config = {
|
|
41171
|
-
mark,
|
|
41875
|
+
mark: mark2,
|
|
41172
41876
|
emphasis: "underline",
|
|
41173
41877
|
...tags2
|
|
41174
41878
|
};
|
|
@@ -41632,15 +42336,23 @@ function titleTagContentProcessor(context, _contentDepth, _tagsConfig, content,
|
|
|
41632
42336
|
titleString: titleText ?? ""
|
|
41633
42337
|
};
|
|
41634
42338
|
}
|
|
41635
|
-
|
|
42339
|
+
var H_TITLE_LEVEL_MAX = 7;
|
|
42340
|
+
function buildTitles(context, bitType, title) {
|
|
41636
42341
|
title = title ?? [];
|
|
41637
|
-
if (instance2.isOfBitType(bitType, BitType.chapter)) {
|
|
42342
|
+
if (instance2.isOfBitType(bitType, [BitType.chapter, BitType.h])) {
|
|
41638
42343
|
let t;
|
|
41639
42344
|
if (title.length > 0) t = title[title.length - 1];
|
|
42345
|
+
let level = title.length > 0 ? title.length - 1 : void 0;
|
|
42346
|
+
if (level != null && level > H_TITLE_LEVEL_MAX && instance2.isOfBitType(bitType, BitType.h)) {
|
|
42347
|
+
context.addWarning(
|
|
42348
|
+
`Title level of ${level} too high, setting to max value of ${H_TITLE_LEVEL_MAX}`
|
|
42349
|
+
);
|
|
42350
|
+
level = H_TITLE_LEVEL_MAX;
|
|
42351
|
+
}
|
|
41640
42352
|
return {
|
|
41641
42353
|
title: t?.titleAst ?? [],
|
|
41642
42354
|
titleString: t?.titleString ?? "",
|
|
41643
|
-
level
|
|
42355
|
+
level
|
|
41644
42356
|
};
|
|
41645
42357
|
} else {
|
|
41646
42358
|
if (Array.isArray(title)) {
|
|
@@ -46905,9 +47617,9 @@ ${nested}` : line;
|
|
|
46905
47617
|
parts.push(href);
|
|
46906
47618
|
}
|
|
46907
47619
|
if (marks) {
|
|
46908
|
-
for (const
|
|
46909
|
-
if (
|
|
46910
|
-
const footnote =
|
|
47620
|
+
for (const mark2 of marks) {
|
|
47621
|
+
if (mark2.type === "footnote") {
|
|
47622
|
+
const footnote = mark2;
|
|
46911
47623
|
if (footnote.attrs?.content) {
|
|
46912
47624
|
const footnoteText = footnote.attrs.content.map((c) => this.textNodeToPlainText(c)).join("");
|
|
46913
47625
|
if (footnoteText) parts.push(footnoteText);
|