@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
|
@@ -14,6 +14,8 @@ var BitType2 = {
|
|
|
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 BitType2 = {
|
|
|
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 BitType2 = {
|
|
|
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 BitType2 = {
|
|
|
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 BitType2 = {
|
|
|
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",
|
|
@@ -1507,6 +1514,8 @@ import "@ncoderz/superenum";
|
|
|
1507
1514
|
var groupKeys = {
|
|
1508
1515
|
group_accessibilityDecorative: "group_accessibilityDecorative",
|
|
1509
1516
|
group_standardAllBits: "group_standardAllBits",
|
|
1517
|
+
group_standardExample: "group_standardExample",
|
|
1518
|
+
group_standardItem: "group_standardItem",
|
|
1510
1519
|
group_standardItemLead: "group_standardItemLead",
|
|
1511
1520
|
group_standardItemLeadInstructionHint: "group_standardItemLeadInstructionHint",
|
|
1512
1521
|
group_standardInstructionHint: "group_standardInstructionHint",
|
|
@@ -5006,6 +5015,34 @@ var GROUPS = {
|
|
|
5006
5015
|
}
|
|
5007
5016
|
]
|
|
5008
5017
|
},
|
|
5018
|
+
[ConfigKey.group_standardExample]: {
|
|
5019
|
+
type: GroupConfigType.standard,
|
|
5020
|
+
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).",
|
|
5021
|
+
tags: [
|
|
5022
|
+
{
|
|
5023
|
+
key: ConfigKey.property_example,
|
|
5024
|
+
exportJsonKey: [{ "@keyonly": {} }, { "@absent": { isExample: true } }, { example: "$" }],
|
|
5025
|
+
description: "The example(s) for the bit",
|
|
5026
|
+
format: TagFormat.bitmarkText,
|
|
5027
|
+
nullable: true
|
|
5028
|
+
}
|
|
5029
|
+
]
|
|
5030
|
+
},
|
|
5031
|
+
[ConfigKey.group_standardItem]: {
|
|
5032
|
+
type: GroupConfigType.standard,
|
|
5033
|
+
description: "PLAN-021: Standard group for the item tag ONLY (no lead/pageNumber/marginNumber chain). Used by the lightweight bits (_standardLight).",
|
|
5034
|
+
tags: [
|
|
5035
|
+
{
|
|
5036
|
+
key: ConfigKey.tag_item,
|
|
5037
|
+
jsonKey: "item",
|
|
5038
|
+
exportJsonKey: { item: "$" },
|
|
5039
|
+
// PLAN-140 W3 (NISO import): the clause/note label of a mapped
|
|
5040
|
+
// source element ([%1], [%ANMERKUNG 1]) — same as group_standardItemLead.
|
|
5041
|
+
mappingKeys: { "xml-niso-iec": { "@el": "label", "@text": "$" } },
|
|
5042
|
+
description: "The item for the bit"
|
|
5043
|
+
}
|
|
5044
|
+
]
|
|
5045
|
+
},
|
|
5009
5046
|
[ConfigKey.group_standardItemLead]: {
|
|
5010
5047
|
type: GroupConfigType.standard,
|
|
5011
5048
|
description: "Standard group for item, lead, page number, and margin number tags",
|
|
@@ -7809,6 +7846,25 @@ var BITS = {
|
|
|
7809
7846
|
}
|
|
7810
7847
|
]
|
|
7811
7848
|
},
|
|
7849
|
+
[BitType2._standardLight]: {
|
|
7850
|
+
since: "5.40.0",
|
|
7851
|
+
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",
|
|
7852
|
+
resourceAttachmentAllowed: false,
|
|
7853
|
+
tags: [
|
|
7854
|
+
{
|
|
7855
|
+
key: ConfigKey.group_standardAllBits,
|
|
7856
|
+
description: "Standard tags for all bits"
|
|
7857
|
+
},
|
|
7858
|
+
{
|
|
7859
|
+
key: ConfigKey.group_standardItem,
|
|
7860
|
+
description: "The item tag (no lead/pageNumber/marginNumber chain)"
|
|
7861
|
+
},
|
|
7862
|
+
{
|
|
7863
|
+
key: ConfigKey.group_standardExample,
|
|
7864
|
+
description: "The bit-level example property"
|
|
7865
|
+
}
|
|
7866
|
+
]
|
|
7867
|
+
},
|
|
7812
7868
|
[BitType2.appFlashcards]: {
|
|
7813
7869
|
since: "1.3.0",
|
|
7814
7870
|
title: "Flashcards",
|
|
@@ -10636,6 +10692,23 @@ var BITS = {
|
|
|
10636
10692
|
baseBitType: BitType2.article,
|
|
10637
10693
|
description: "Glossary term bit, used to define glossary terms in articles or books"
|
|
10638
10694
|
},
|
|
10695
|
+
[BitType2.h]: {
|
|
10696
|
+
since: "5.40.0",
|
|
10697
|
+
title: "Heading",
|
|
10698
|
+
bitGroups: [BitGroup.static],
|
|
10699
|
+
baseBitType: BitType2._standardLight,
|
|
10700
|
+
description: "Lightweight heading bit with chapter-style title levels 1-7; title/level + item only \u2014 no body, no footer",
|
|
10701
|
+
bodyAllowed: false,
|
|
10702
|
+
footerAllowed: false,
|
|
10703
|
+
tags: [
|
|
10704
|
+
{
|
|
10705
|
+
key: ConfigKey.tag_title,
|
|
10706
|
+
description: "The title of the heading",
|
|
10707
|
+
jsonKey: "title|setMulti(level)",
|
|
10708
|
+
exportJsonKey: { title: "$", level: "$level" }
|
|
10709
|
+
}
|
|
10710
|
+
]
|
|
10711
|
+
},
|
|
10639
10712
|
[BitType2.help]: {
|
|
10640
10713
|
since: "1.3.0",
|
|
10641
10714
|
title: "Help",
|
|
@@ -10822,13 +10895,22 @@ var BITS = {
|
|
|
10822
10895
|
since: "1.22.0",
|
|
10823
10896
|
title: "List",
|
|
10824
10897
|
bitGroups: [BitGroup.static],
|
|
10825
|
-
|
|
10898
|
+
// PLAN-021: rebased from article onto the lightweight base
|
|
10899
|
+
baseBitType: BitType2._standardLight,
|
|
10826
10900
|
description: "List bit, used to create lists in articles or books"
|
|
10827
10901
|
},
|
|
10902
|
+
[BitType2.listAlt]: {
|
|
10903
|
+
since: "5.40.0",
|
|
10904
|
+
title: "List Alt",
|
|
10905
|
+
bitGroups: [BitGroup.static],
|
|
10906
|
+
baseBitType: BitType2.list,
|
|
10907
|
+
description: "Lightweight list bit (alternative), based on list"
|
|
10908
|
+
},
|
|
10828
10909
|
[BitType2.standardList]: {
|
|
10829
10910
|
since: "1.22.0",
|
|
10830
10911
|
bitGroups: [BitGroup.static],
|
|
10831
|
-
|
|
10912
|
+
// PLAN-021: re-rooted from article onto the lightweight list
|
|
10913
|
+
baseBitType: BitType2.list,
|
|
10832
10914
|
description: "Standard list bit, used to create standard lists in articles or books"
|
|
10833
10915
|
},
|
|
10834
10916
|
[BitType2.smartStandardList]: {
|
|
@@ -10844,6 +10926,13 @@ var BITS = {
|
|
|
10844
10926
|
"xml-niso-iec": { "@el": "ref-list", "@attr": { id: "$customerId" }, "\u25BC": "$anchor" }
|
|
10845
10927
|
}
|
|
10846
10928
|
},
|
|
10929
|
+
[BitType2.smartStandardP]: {
|
|
10930
|
+
since: "5.40.0",
|
|
10931
|
+
title: "Smart Standard Paragraph",
|
|
10932
|
+
bitGroups: [BitGroup.static],
|
|
10933
|
+
baseBitType: BitType2.p,
|
|
10934
|
+
description: "Smart standard paragraph bit, based on p"
|
|
10935
|
+
},
|
|
10847
10936
|
[BitType2.smartStandardListCollapsible]: {
|
|
10848
10937
|
since: "1.28.0",
|
|
10849
10938
|
deprecated: "5.37.0",
|
|
@@ -13425,7 +13514,8 @@ var BITS = {
|
|
|
13425
13514
|
[BitType2.listItem]: {
|
|
13426
13515
|
since: "1.22.0",
|
|
13427
13516
|
bitGroups: [BitGroup.static],
|
|
13428
|
-
|
|
13517
|
+
// PLAN-021: rebased from article onto the lightweight base
|
|
13518
|
+
baseBitType: BitType2._standardLight,
|
|
13429
13519
|
description: "List item bit, used to create list items in articles or books",
|
|
13430
13520
|
tags: [
|
|
13431
13521
|
{
|
|
@@ -13830,6 +13920,20 @@ var BITS = {
|
|
|
13830
13920
|
baseBitType: BitType2.multipleResponse,
|
|
13831
13921
|
description: "Coach self-reflection multiple response bit, used for self-reflection in coaching"
|
|
13832
13922
|
},
|
|
13923
|
+
[BitType2.p]: {
|
|
13924
|
+
since: "5.40.0",
|
|
13925
|
+
title: "Paragraph",
|
|
13926
|
+
bitGroups: [BitGroup.static],
|
|
13927
|
+
baseBitType: BitType2._standardLight,
|
|
13928
|
+
description: "Lightweight paragraph bit with a minimal tag set"
|
|
13929
|
+
},
|
|
13930
|
+
[BitType2.pAlt]: {
|
|
13931
|
+
since: "5.40.0",
|
|
13932
|
+
title: "Paragraph Alt",
|
|
13933
|
+
bitGroups: [BitGroup.static],
|
|
13934
|
+
baseBitType: BitType2.p,
|
|
13935
|
+
description: "Lightweight paragraph bit (alternative), based on p"
|
|
13936
|
+
},
|
|
13833
13937
|
[BitType2.page]: {
|
|
13834
13938
|
since: "1.3.0",
|
|
13835
13939
|
title: "Page",
|
|
@@ -16560,7 +16664,7 @@ var instance2 = new Config();
|
|
|
16560
16664
|
// src/generated/package_info.ts
|
|
16561
16665
|
var PACKAGE_INFO = {
|
|
16562
16666
|
"name": "@gmb/bitmark-parser-generator",
|
|
16563
|
-
"version": "5.
|
|
16667
|
+
"version": "5.41.0",
|
|
16564
16668
|
"author": "Get More Brain Ltd",
|
|
16565
16669
|
"license": "ISC",
|
|
16566
16670
|
"description": "A bitmark parser and generator using Peggy.js"
|
|
@@ -18414,6 +18518,752 @@ var AstWalkerGenerator = class {
|
|
|
18414
18518
|
}
|
|
18415
18519
|
};
|
|
18416
18520
|
|
|
18521
|
+
// src/generator/text/TextGrammarConstraints.ts
|
|
18522
|
+
var COLORS = [
|
|
18523
|
+
"aqua",
|
|
18524
|
+
"black",
|
|
18525
|
+
"blue",
|
|
18526
|
+
"brown",
|
|
18527
|
+
"fuchsia",
|
|
18528
|
+
"lightgrey",
|
|
18529
|
+
"gray",
|
|
18530
|
+
"darkgray",
|
|
18531
|
+
"green",
|
|
18532
|
+
"lime",
|
|
18533
|
+
"magenta",
|
|
18534
|
+
"maroon",
|
|
18535
|
+
"navy",
|
|
18536
|
+
"olive",
|
|
18537
|
+
"orange",
|
|
18538
|
+
"pink",
|
|
18539
|
+
"purple",
|
|
18540
|
+
"red",
|
|
18541
|
+
"silver",
|
|
18542
|
+
"teal",
|
|
18543
|
+
"violet",
|
|
18544
|
+
"white",
|
|
18545
|
+
"yellow"
|
|
18546
|
+
];
|
|
18547
|
+
var HIGHLIGHT_COLORS = [
|
|
18548
|
+
"orange",
|
|
18549
|
+
"yellow",
|
|
18550
|
+
"green",
|
|
18551
|
+
"blue",
|
|
18552
|
+
"purple",
|
|
18553
|
+
"pink",
|
|
18554
|
+
"brown",
|
|
18555
|
+
"white",
|
|
18556
|
+
"black",
|
|
18557
|
+
"gray"
|
|
18558
|
+
];
|
|
18559
|
+
var ALTERNATIVE_STYLE_TAGS = [
|
|
18560
|
+
"bold",
|
|
18561
|
+
"italic",
|
|
18562
|
+
"light",
|
|
18563
|
+
"highlightOrange",
|
|
18564
|
+
"highlightYellow",
|
|
18565
|
+
"highlightGreen",
|
|
18566
|
+
"highlightBlue",
|
|
18567
|
+
"highlightPurple",
|
|
18568
|
+
"highlightPink",
|
|
18569
|
+
"highlightBrown",
|
|
18570
|
+
"highlightBlack",
|
|
18571
|
+
"highlightWhite",
|
|
18572
|
+
"highlightGray",
|
|
18573
|
+
"highlight",
|
|
18574
|
+
"strike",
|
|
18575
|
+
"subscript",
|
|
18576
|
+
"superscript",
|
|
18577
|
+
"ins",
|
|
18578
|
+
"del",
|
|
18579
|
+
"underline",
|
|
18580
|
+
"doubleUnderline",
|
|
18581
|
+
"smallcaps",
|
|
18582
|
+
"circle",
|
|
18583
|
+
"languageEmRed",
|
|
18584
|
+
"languageEmOrange",
|
|
18585
|
+
"languageEmYellow",
|
|
18586
|
+
"languageEmGreen",
|
|
18587
|
+
"languageEmBlue",
|
|
18588
|
+
"languageEmPurple",
|
|
18589
|
+
"languageEmPink",
|
|
18590
|
+
"languageEmBrown",
|
|
18591
|
+
"languageEmBlack",
|
|
18592
|
+
"languageEmWhite",
|
|
18593
|
+
"languageEmGray",
|
|
18594
|
+
"languageEm",
|
|
18595
|
+
"userUnderline",
|
|
18596
|
+
"userDoubleUnderline",
|
|
18597
|
+
"userStrike",
|
|
18598
|
+
"userCircle",
|
|
18599
|
+
"userHighlight",
|
|
18600
|
+
"notranslate"
|
|
18601
|
+
];
|
|
18602
|
+
var MEDIA_ALIGNMENTS = ["left", "center", "right"];
|
|
18603
|
+
var INLINE_MEDIA_ALIGNMENTS = [
|
|
18604
|
+
"top",
|
|
18605
|
+
"middle",
|
|
18606
|
+
"bottom",
|
|
18607
|
+
"baseline",
|
|
18608
|
+
"sub",
|
|
18609
|
+
"super",
|
|
18610
|
+
"text-bottom",
|
|
18611
|
+
"text-top"
|
|
18612
|
+
];
|
|
18613
|
+
var INLINE_MEDIA_SIZES = [
|
|
18614
|
+
"line-height",
|
|
18615
|
+
"font-height",
|
|
18616
|
+
"super",
|
|
18617
|
+
"sub",
|
|
18618
|
+
"explicit"
|
|
18619
|
+
];
|
|
18620
|
+
var LINE_TERMINATOR_REGEX = /[\n\r\u2028\u2029]/;
|
|
18621
|
+
var CHAIN_STRING_INVALID_REGEX = /[|\n\r\u2028\u2029]/;
|
|
18622
|
+
var URL_CHAR_CLASS = "a-zA-Z0-9!*'()=+,\\-./_?#@[\\]$&;%:{}~^";
|
|
18623
|
+
var URL_CHAR_REGEX = new RegExp(`^[${URL_CHAR_CLASS}]$`);
|
|
18624
|
+
var URL_HTTP_REGEX = new RegExp(`^https?://[${URL_CHAR_CLASS}]*$`);
|
|
18625
|
+
var URL_REGEX = new RegExp(`^(https?://|mailto:)[${URL_CHAR_CLASS}]*$`);
|
|
18626
|
+
function isChainString(v) {
|
|
18627
|
+
return typeof v === "string" && !CHAIN_STRING_INVALID_REGEX.test(v);
|
|
18628
|
+
}
|
|
18629
|
+
function isSingleLine(v) {
|
|
18630
|
+
return typeof v === "string" && !LINE_TERMINATOR_REGEX.test(v);
|
|
18631
|
+
}
|
|
18632
|
+
function hasLineTerminator(v) {
|
|
18633
|
+
return LINE_TERMINATOR_REGEX.test(v);
|
|
18634
|
+
}
|
|
18635
|
+
function isColor(v) {
|
|
18636
|
+
return typeof v === "string" && COLORS.indexOf(v) !== -1;
|
|
18637
|
+
}
|
|
18638
|
+
function isHighlightColor(v) {
|
|
18639
|
+
return typeof v === "string" && HIGHLIGHT_COLORS.indexOf(v) !== -1;
|
|
18640
|
+
}
|
|
18641
|
+
function isMediaAlignment(v) {
|
|
18642
|
+
return typeof v === "string" && MEDIA_ALIGNMENTS.indexOf(v) !== -1;
|
|
18643
|
+
}
|
|
18644
|
+
function isInlineMediaAlignment(v) {
|
|
18645
|
+
return typeof v === "string" && INLINE_MEDIA_ALIGNMENTS.indexOf(v) !== -1;
|
|
18646
|
+
}
|
|
18647
|
+
function isInlineMediaSize(v) {
|
|
18648
|
+
return typeof v === "string" && INLINE_MEDIA_SIZES.indexOf(v) !== -1;
|
|
18649
|
+
}
|
|
18650
|
+
function toUInt(v) {
|
|
18651
|
+
if (typeof v === "number") return Number.isInteger(v) && v >= 0 ? v : void 0;
|
|
18652
|
+
if (typeof v === "string" && /^[0-9]+$/.test(v)) return parseInt(v, 10);
|
|
18653
|
+
return void 0;
|
|
18654
|
+
}
|
|
18655
|
+
function toBoolean(v) {
|
|
18656
|
+
if (typeof v === "boolean") return v;
|
|
18657
|
+
if (v === "true") return true;
|
|
18658
|
+
if (v === "false") return false;
|
|
18659
|
+
return void 0;
|
|
18660
|
+
}
|
|
18661
|
+
function isDuration(v) {
|
|
18662
|
+
return isChainString(v) && v.trim().startsWith("P");
|
|
18663
|
+
}
|
|
18664
|
+
function isUrlHttp(v) {
|
|
18665
|
+
return typeof v === "string" && URL_HTTP_REGEX.test(v);
|
|
18666
|
+
}
|
|
18667
|
+
function isUrl(v) {
|
|
18668
|
+
return typeof v === "string" && URL_REGEX.test(v);
|
|
18669
|
+
}
|
|
18670
|
+
function isUrlChar(c) {
|
|
18671
|
+
return URL_CHAR_REGEX.test(c);
|
|
18672
|
+
}
|
|
18673
|
+
function bareUrlText(href) {
|
|
18674
|
+
return href.replace(/^(https?:\/\/|mailto:)/, "");
|
|
18675
|
+
}
|
|
18676
|
+
function isInlineAlt(v) {
|
|
18677
|
+
return typeof v === "string" && v.length > 0 && v.indexOf("==") === -1 && !v.startsWith("=") && !v.endsWith("=");
|
|
18678
|
+
}
|
|
18679
|
+
function isHeadingLevel(v) {
|
|
18680
|
+
return typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= 3;
|
|
18681
|
+
}
|
|
18682
|
+
function normalizeInlineCodeLanguage(v) {
|
|
18683
|
+
if (!isChainString(v)) return void 0;
|
|
18684
|
+
return v.trim().toLowerCase();
|
|
18685
|
+
}
|
|
18686
|
+
function normalizeBlockCodeLanguage(v) {
|
|
18687
|
+
if (!isSingleLine(v)) return void 0;
|
|
18688
|
+
return v.trim().toLowerCase();
|
|
18689
|
+
}
|
|
18690
|
+
|
|
18691
|
+
// src/generator/text/TextMediaAttrs.ts
|
|
18692
|
+
var uint = (v) => toUInt(v);
|
|
18693
|
+
var bool = (v) => toBoolean(v);
|
|
18694
|
+
var alignment = (v) => isMediaAlignment(v) ? v : void 0;
|
|
18695
|
+
var chainString = (v) => isChainString(v) ? v.trim() : void 0;
|
|
18696
|
+
var inlineAlignment = (v) => isInlineMediaAlignment(v) ? v : void 0;
|
|
18697
|
+
var inlineSize = (v) => isInlineMediaSize(v) ? v : void 0;
|
|
18698
|
+
var VALIDATORS = {
|
|
18699
|
+
image: {
|
|
18700
|
+
alt: chainString,
|
|
18701
|
+
title: chainString,
|
|
18702
|
+
alignment,
|
|
18703
|
+
textAlign: alignment,
|
|
18704
|
+
zoomDisabled: bool,
|
|
18705
|
+
width: uint,
|
|
18706
|
+
height: uint,
|
|
18707
|
+
comment: chainString
|
|
18708
|
+
},
|
|
18709
|
+
imageInline: {
|
|
18710
|
+
srcAlt: chainString,
|
|
18711
|
+
alignmentVertical: inlineAlignment,
|
|
18712
|
+
size: inlineSize,
|
|
18713
|
+
width: uint,
|
|
18714
|
+
height: uint,
|
|
18715
|
+
comment: chainString
|
|
18716
|
+
},
|
|
18717
|
+
symbol: {
|
|
18718
|
+
alt: chainString,
|
|
18719
|
+
title: chainString,
|
|
18720
|
+
caption: chainString,
|
|
18721
|
+
alignment,
|
|
18722
|
+
textAlign: alignment,
|
|
18723
|
+
captionAlign: alignment,
|
|
18724
|
+
zoomDisabled: bool,
|
|
18725
|
+
width: uint,
|
|
18726
|
+
height: uint,
|
|
18727
|
+
comment: chainString
|
|
18728
|
+
}
|
|
18729
|
+
};
|
|
18730
|
+
var TAG_NAMES = {
|
|
18731
|
+
textAlign: "captionAlign",
|
|
18732
|
+
title: "caption"
|
|
18733
|
+
};
|
|
18734
|
+
var DEFAULTS = {
|
|
18735
|
+
image: { alignment: "center", textAlign: "left", zoomDisabled: true },
|
|
18736
|
+
imageInline: { alignmentVertical: "top", size: "line-height" },
|
|
18737
|
+
symbol: {}
|
|
18738
|
+
};
|
|
18739
|
+
function sanitizeMediaAttrs(kind, attrs) {
|
|
18740
|
+
const result = {};
|
|
18741
|
+
if (!attrs || typeof attrs !== "object") return result;
|
|
18742
|
+
const validators = VALIDATORS[kind];
|
|
18743
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
18744
|
+
const validator = validators[k];
|
|
18745
|
+
if (!validator || v == null) continue;
|
|
18746
|
+
const valid = validator(v);
|
|
18747
|
+
if (valid !== void 0) result[k] = valid;
|
|
18748
|
+
}
|
|
18749
|
+
if (kind === "symbol") {
|
|
18750
|
+
if ("caption" in result) delete result.title;
|
|
18751
|
+
if ("captionAlign" in result) delete result.textAlign;
|
|
18752
|
+
}
|
|
18753
|
+
return result;
|
|
18754
|
+
}
|
|
18755
|
+
function serializeMediaChain(kind, attrs) {
|
|
18756
|
+
const defaults = DEFAULTS[kind];
|
|
18757
|
+
let s = "";
|
|
18758
|
+
for (const k of Object.keys(VALIDATORS[kind])) {
|
|
18759
|
+
const v = attrs[k];
|
|
18760
|
+
if (v == null) continue;
|
|
18761
|
+
if (k in defaults && defaults[k] === v) continue;
|
|
18762
|
+
if (k === "comment") {
|
|
18763
|
+
if (v) s += `|#${v}`;
|
|
18764
|
+
} else if (typeof v === "string" && v === "") {
|
|
18765
|
+
continue;
|
|
18766
|
+
} else {
|
|
18767
|
+
s += `|${TAG_NAMES[k] ?? k}:${v}`;
|
|
18768
|
+
}
|
|
18769
|
+
}
|
|
18770
|
+
return s;
|
|
18771
|
+
}
|
|
18772
|
+
|
|
18773
|
+
// src/generator/text/TextMarkSanitizer.ts
|
|
18774
|
+
var STANDARD_SHORT_FORM_MARKS = [
|
|
18775
|
+
TextMarkType.bold,
|
|
18776
|
+
TextMarkType.italic,
|
|
18777
|
+
TextMarkType.light,
|
|
18778
|
+
TextMarkType.highlight
|
|
18779
|
+
];
|
|
18780
|
+
function attrsOf(mark2) {
|
|
18781
|
+
const a = mark2.attrs;
|
|
18782
|
+
return a && typeof a === "object" && !Array.isArray(a) ? a : {};
|
|
18783
|
+
}
|
|
18784
|
+
function chainValue(v) {
|
|
18785
|
+
if (v == null) return "";
|
|
18786
|
+
return isChainString(v) ? v.trim() : void 0;
|
|
18787
|
+
}
|
|
18788
|
+
function mark(type, attrs) {
|
|
18789
|
+
return attrs ? { type, attrs } : { type };
|
|
18790
|
+
}
|
|
18791
|
+
function sanitizeMark(m, options) {
|
|
18792
|
+
const attrs = attrsOf(m);
|
|
18793
|
+
switch (m.type) {
|
|
18794
|
+
case TextMarkType.highlight:
|
|
18795
|
+
case TextMarkType.userHighlight: {
|
|
18796
|
+
const color = attrs.color;
|
|
18797
|
+
return isHighlightColor(color) ? mark(m.type, { color }) : mark(m.type);
|
|
18798
|
+
}
|
|
18799
|
+
case TextMarkType.textStyle:
|
|
18800
|
+
case TextMarkType.color: {
|
|
18801
|
+
const color = attrs.color;
|
|
18802
|
+
return isColor(color) ? mark(TextMarkType.textStyle, { color }) : void 0;
|
|
18803
|
+
}
|
|
18804
|
+
case TextMarkType.link: {
|
|
18805
|
+
const href = chainValue(attrs.href);
|
|
18806
|
+
return href === void 0 ? void 0 : mark(m.type, { href });
|
|
18807
|
+
}
|
|
18808
|
+
case TextMarkType.ref: {
|
|
18809
|
+
const reference = chainValue(attrs.reference);
|
|
18810
|
+
return reference === void 0 ? void 0 : mark(m.type, { reference });
|
|
18811
|
+
}
|
|
18812
|
+
case TextMarkType.xref: {
|
|
18813
|
+
const xref = chainValue(attrs.xref);
|
|
18814
|
+
if (xref === void 0) return void 0;
|
|
18815
|
+
const reference = chainValue(attrs.reference) ?? "";
|
|
18816
|
+
return mark(m.type, { xref, reference });
|
|
18817
|
+
}
|
|
18818
|
+
case TextMarkType.extref: {
|
|
18819
|
+
const extref = chainValue(attrs.extref);
|
|
18820
|
+
const provider = chainValue(attrs.provider);
|
|
18821
|
+
if (extref === void 0 || provider === void 0) return void 0;
|
|
18822
|
+
const refs = Array.isArray(attrs.references) ? attrs.references : [];
|
|
18823
|
+
const references = refs.map((r) => chainValue(r)).filter((r) => r !== void 0);
|
|
18824
|
+
return mark(m.type, { extref, references, provider });
|
|
18825
|
+
}
|
|
18826
|
+
case TextMarkType.footnote:
|
|
18827
|
+
case TextMarkType.footnoteStar: {
|
|
18828
|
+
const content = options.normalizeChainValue ? options.normalizeChainValue(attrs.content) : Array.isArray(attrs.content) ? attrs.content : [];
|
|
18829
|
+
return content === void 0 ? void 0 : mark(m.type, { content });
|
|
18830
|
+
}
|
|
18831
|
+
case TextMarkType.symbol: {
|
|
18832
|
+
const src = chainValue(attrs.src);
|
|
18833
|
+
if (src === void 0) return void 0;
|
|
18834
|
+
return mark(m.type, { src, ...sanitizeMediaAttrs("symbol", attrs) });
|
|
18835
|
+
}
|
|
18836
|
+
case TextMarkType.var: {
|
|
18837
|
+
const name = chainValue(attrs.name);
|
|
18838
|
+
return name === void 0 ? void 0 : mark(m.type, { name });
|
|
18839
|
+
}
|
|
18840
|
+
case TextMarkType.code: {
|
|
18841
|
+
const language = normalizeInlineCodeLanguage(attrs.language);
|
|
18842
|
+
return language === void 0 ? mark(m.type) : mark(m.type, { language });
|
|
18843
|
+
}
|
|
18844
|
+
case TextMarkType.timer: {
|
|
18845
|
+
const duration = attrs.duration;
|
|
18846
|
+
if (!isDuration(duration)) return void 0;
|
|
18847
|
+
const name = chainValue(attrs.name) ?? "";
|
|
18848
|
+
return mark(m.type, { name, duration: duration.trim() });
|
|
18849
|
+
}
|
|
18850
|
+
case TextMarkType.colorPicker: {
|
|
18851
|
+
const propertyRef = chainValue(attrs.propertyRef);
|
|
18852
|
+
return propertyRef === void 0 ? void 0 : mark(m.type, { propertyRef });
|
|
18853
|
+
}
|
|
18854
|
+
case TextMarkType.comment: {
|
|
18855
|
+
const comment = chainValue(m.comment);
|
|
18856
|
+
return comment === void 0 ? void 0 : { type: m.type, comment };
|
|
18857
|
+
}
|
|
18858
|
+
default:
|
|
18859
|
+
if (ALTERNATIVE_STYLE_TAGS.indexOf(m.type) !== -1) return mark(m.type);
|
|
18860
|
+
return void 0;
|
|
18861
|
+
}
|
|
18862
|
+
}
|
|
18863
|
+
function mergeLegacyTimer(marks) {
|
|
18864
|
+
const timer = marks.find((m) => m.type === TextMarkType.timer);
|
|
18865
|
+
const duration = marks.find((m) => m.type === TextMarkType.duration);
|
|
18866
|
+
if (!timer || !duration || attrsOf(timer).duration) return marks;
|
|
18867
|
+
return marks.map(
|
|
18868
|
+
(m) => m === timer ? { ...timer, attrs: { ...attrsOf(timer), duration: attrsOf(duration).duration } } : m
|
|
18869
|
+
);
|
|
18870
|
+
}
|
|
18871
|
+
function orderMarks(marks) {
|
|
18872
|
+
const a = (m) => m.attrs ?? {};
|
|
18873
|
+
const isBareHighlight = (m) => (m.type === TextMarkType.highlight || m.type === TextMarkType.userHighlight) && !a(m).color;
|
|
18874
|
+
const isHighlightColorStyle = (m) => m.type === TextMarkType.textStyle && isHighlightColor(a(m).color);
|
|
18875
|
+
const isEmptyXref = (m) => m.type === TextMarkType.xref && !a(m).reference;
|
|
18876
|
+
const result = [];
|
|
18877
|
+
for (const m of marks) {
|
|
18878
|
+
if (m.type === TextMarkType.ref) {
|
|
18879
|
+
const xrefIdx = result.findIndex(isEmptyXref);
|
|
18880
|
+
if (xrefIdx !== -1) {
|
|
18881
|
+
result.splice(xrefIdx, 0, m);
|
|
18882
|
+
continue;
|
|
18883
|
+
}
|
|
18884
|
+
}
|
|
18885
|
+
result.push(m);
|
|
18886
|
+
}
|
|
18887
|
+
for (let i = 0; i < result.length - 1; i++) {
|
|
18888
|
+
if (isBareHighlight(result[i]) && isHighlightColorStyle(result[i + 1])) {
|
|
18889
|
+
[result[i], result[i + 1]] = [result[i + 1], result[i]];
|
|
18890
|
+
}
|
|
18891
|
+
}
|
|
18892
|
+
const symbols = result.filter((m) => m.type === TextMarkType.symbol);
|
|
18893
|
+
if (symbols.length === 0) return result;
|
|
18894
|
+
return [...result.filter((m) => m.type !== TextMarkType.symbol), symbols[0]];
|
|
18895
|
+
}
|
|
18896
|
+
function sanitizeMarks(marks, options = {}) {
|
|
18897
|
+
if (!Array.isArray(marks)) return [];
|
|
18898
|
+
let loose = marks.filter(
|
|
18899
|
+
(m) => !!m && typeof m === "object" && typeof m.type === "string"
|
|
18900
|
+
);
|
|
18901
|
+
loose = mergeLegacyTimer(loose);
|
|
18902
|
+
const result = [];
|
|
18903
|
+
for (const m of loose) {
|
|
18904
|
+
const s = sanitizeMark(m, options);
|
|
18905
|
+
if (s) result.push(s);
|
|
18906
|
+
}
|
|
18907
|
+
if (options.chainValue) {
|
|
18908
|
+
if (result.length === 1 && STANDARD_SHORT_FORM_MARKS.indexOf(result[0].type) !== -1) {
|
|
18909
|
+
return [mark(result[0].type)];
|
|
18910
|
+
}
|
|
18911
|
+
if (result.length === 1 && result[0].type === TextMarkType.link) return result;
|
|
18912
|
+
return [];
|
|
18913
|
+
}
|
|
18914
|
+
return orderMarks(result);
|
|
18915
|
+
}
|
|
18916
|
+
|
|
18917
|
+
// src/generator/text/TextAstNormalizer.ts
|
|
18918
|
+
var LIST_TYPES = [
|
|
18919
|
+
TextNodeType.noBulletList,
|
|
18920
|
+
TextNodeType.bulletList,
|
|
18921
|
+
TextNodeType.orderedList,
|
|
18922
|
+
TextNodeType.orderedListRoman,
|
|
18923
|
+
TextNodeType.orderedListRomanLower,
|
|
18924
|
+
TextNodeType.letteredList,
|
|
18925
|
+
TextNodeType.letteredListLower,
|
|
18926
|
+
TextNodeType.taskList
|
|
18927
|
+
];
|
|
18928
|
+
var ORDERED_LIST_TYPES = [
|
|
18929
|
+
TextNodeType.orderedList,
|
|
18930
|
+
TextNodeType.orderedListRoman,
|
|
18931
|
+
TextNodeType.orderedListRomanLower
|
|
18932
|
+
];
|
|
18933
|
+
var BODY_BIT_TYPES = [
|
|
18934
|
+
TextNodeType.gap,
|
|
18935
|
+
TextNodeType.select,
|
|
18936
|
+
TextNodeType.highlight,
|
|
18937
|
+
TextNodeType.mark
|
|
18938
|
+
];
|
|
18939
|
+
var LEADING_TAB_REGEX = /(^|[\n\r\u2028\u2029])\t+/g;
|
|
18940
|
+
var isList = (n) => LIST_TYPES.indexOf(n.type) !== -1;
|
|
18941
|
+
var isListItem = (n) => n.type === TextNodeType.listItem || n.type === TextNodeType.taskItem;
|
|
18942
|
+
var isBodyBit = (n) => BODY_BIT_TYPES.indexOf(n.type) !== -1;
|
|
18943
|
+
var isNode = (n) => !!n && typeof n === "object" && typeof n.type === "string";
|
|
18944
|
+
var contentOf = (n) => Array.isArray(n.content) ? n.content.filter(isNode) : [];
|
|
18945
|
+
var attrsOf2 = (n) => n.attrs && typeof n.attrs === "object" ? n.attrs : {};
|
|
18946
|
+
var asNode = (n) => n;
|
|
18947
|
+
var paragraph = (content) => asNode({ type: TextNodeType.paragraph, attrs: {}, content });
|
|
18948
|
+
var hardBreak = () => ({ type: TextNodeType.hardBreak });
|
|
18949
|
+
var isHardBreak = (n) => n?.type === TextNodeType.hardBreak;
|
|
18950
|
+
var hasText = (nodes) => nodes.some(
|
|
18951
|
+
(n) => n.type !== TextNodeType.hardBreak && (n.type !== TextNodeType.text || typeof n.text === "string" && n.text.trim() !== "")
|
|
18952
|
+
);
|
|
18953
|
+
function canFollowBareUrl(next) {
|
|
18954
|
+
if (!next) return true;
|
|
18955
|
+
if (next.type === TextNodeType.hardBreak) return true;
|
|
18956
|
+
if (next.type !== TextNodeType.text) return false;
|
|
18957
|
+
if (next.marks && next.marks.length > 0) return false;
|
|
18958
|
+
const first = (next.text ?? "").charAt(0);
|
|
18959
|
+
return first === "" || !isUrlChar(first);
|
|
18960
|
+
}
|
|
18961
|
+
function isSimpleLinkNode(node, next) {
|
|
18962
|
+
if (node.type !== TextNodeType.text || node.marks?.length !== 1) return false;
|
|
18963
|
+
const m = node.marks[0];
|
|
18964
|
+
if (m.type !== TextMarkType.link) return false;
|
|
18965
|
+
const href = m.attrs?.href;
|
|
18966
|
+
return isUrl(href) && bareUrlText(href) === node.text && canFollowBareUrl(next);
|
|
18967
|
+
}
|
|
18968
|
+
var FLATTENED_BLOCK_TYPES = [
|
|
18969
|
+
TextNodeType.paragraph,
|
|
18970
|
+
TextNodeType.heading,
|
|
18971
|
+
TextNodeType.section,
|
|
18972
|
+
TextNodeType.listItem,
|
|
18973
|
+
TextNodeType.taskItem,
|
|
18974
|
+
TextNodeType.codeBlock
|
|
18975
|
+
];
|
|
18976
|
+
var TextAstNormalizer = class {
|
|
18977
|
+
constructor(options) {
|
|
18978
|
+
__publicField(this, "options");
|
|
18979
|
+
this.options = options;
|
|
18980
|
+
}
|
|
18981
|
+
normalize(ast) {
|
|
18982
|
+
if (!Array.isArray(ast)) return [];
|
|
18983
|
+
const nodes = ast.filter(isNode);
|
|
18984
|
+
if (this.options.chainValue) return this.inline(nodes, { plain: true, chainValue: true });
|
|
18985
|
+
if (this.options.location === TextLocation2.tag) {
|
|
18986
|
+
return nodes.flatMap((n) => this.inlineRootNode(n, {}));
|
|
18987
|
+
}
|
|
18988
|
+
return nodes.flatMap((n) => this.block(n));
|
|
18989
|
+
}
|
|
18990
|
+
//
|
|
18991
|
+
// Block context
|
|
18992
|
+
//
|
|
18993
|
+
block(n) {
|
|
18994
|
+
switch (n.type) {
|
|
18995
|
+
case TextNodeType.paragraph:
|
|
18996
|
+
return [{ ...n, content: this.inline(contentOf(n)) }];
|
|
18997
|
+
case TextNodeType.heading:
|
|
18998
|
+
return this.heading(n);
|
|
18999
|
+
case TextNodeType.section:
|
|
19000
|
+
return [paragraph(this.inline(contentOf(n)))];
|
|
19001
|
+
case TextNodeType.image: {
|
|
19002
|
+
const image = this.image(n);
|
|
19003
|
+
return image ? [image] : [];
|
|
19004
|
+
}
|
|
19005
|
+
case TextNodeType.codeBlock:
|
|
19006
|
+
return [{ ...n, content: this.code(contentOf(n)) }];
|
|
19007
|
+
case TextNodeType.text:
|
|
19008
|
+
case TextNodeType.hardBreak:
|
|
19009
|
+
case TextNodeType.imageInline:
|
|
19010
|
+
case TextNodeType.latex:
|
|
19011
|
+
return this.inline([n]);
|
|
19012
|
+
default:
|
|
19013
|
+
if (isList(n)) return this.list(n);
|
|
19014
|
+
if (isListItem(n)) return [paragraph(this.inline(contentOf(n)))];
|
|
19015
|
+
if (isBodyBit(n)) return [n];
|
|
19016
|
+
if (Array.isArray(n.content))
|
|
19017
|
+
return [{ ...n, content: this.blocks(contentOf(n)) }];
|
|
19018
|
+
return [n];
|
|
19019
|
+
}
|
|
19020
|
+
}
|
|
19021
|
+
blocks(nodes) {
|
|
19022
|
+
return nodes.flatMap((n) => this.block(n));
|
|
19023
|
+
}
|
|
19024
|
+
heading(n) {
|
|
19025
|
+
const level = attrsOf2(n).level;
|
|
19026
|
+
if (level != null && !isHeadingLevel(level)) {
|
|
19027
|
+
return [paragraph(this.inline(contentOf(n)))];
|
|
19028
|
+
}
|
|
19029
|
+
const content = this.inline(contentOf(n), { singleLine: true });
|
|
19030
|
+
if (!hasText(content)) return [];
|
|
19031
|
+
return [{ ...n, content }];
|
|
19032
|
+
}
|
|
19033
|
+
image(n) {
|
|
19034
|
+
const attrs = attrsOf2(n);
|
|
19035
|
+
if (!isUrlHttp(attrs.src)) return void 0;
|
|
19036
|
+
return asNode({ ...n, attrs: { src: attrs.src, ...sanitizeMediaAttrs("image", attrs) } });
|
|
19037
|
+
}
|
|
19038
|
+
code(nodes) {
|
|
19039
|
+
const result = [];
|
|
19040
|
+
for (const n of nodes) {
|
|
19041
|
+
if (n.type === TextNodeType.text) {
|
|
19042
|
+
if (typeof n.text === "string" && n.text) {
|
|
19043
|
+
result.push({ type: TextNodeType.text, text: n.text });
|
|
19044
|
+
}
|
|
19045
|
+
} else if (n.type === TextNodeType.hardBreak) {
|
|
19046
|
+
result.push(hardBreak());
|
|
19047
|
+
} else {
|
|
19048
|
+
result.push(...this.code(contentOf(n)));
|
|
19049
|
+
}
|
|
19050
|
+
}
|
|
19051
|
+
return result;
|
|
19052
|
+
}
|
|
19053
|
+
//
|
|
19054
|
+
// List context
|
|
19055
|
+
//
|
|
19056
|
+
list(n) {
|
|
19057
|
+
const attrs = attrsOf2(n);
|
|
19058
|
+
const ordered = ORDERED_LIST_TYPES.indexOf(n.type) !== -1;
|
|
19059
|
+
let start;
|
|
19060
|
+
if (ordered && attrs.start != null) {
|
|
19061
|
+
start = toUInt(attrs.start);
|
|
19062
|
+
if (start === void 0) {
|
|
19063
|
+
return contentOf(n).map(
|
|
19064
|
+
(item) => paragraph(this.inline([item], { stripLeadingTabs: true }))
|
|
19065
|
+
);
|
|
19066
|
+
}
|
|
19067
|
+
}
|
|
19068
|
+
const items = [];
|
|
19069
|
+
for (const child of contentOf(n)) {
|
|
19070
|
+
if (isListItem(child)) {
|
|
19071
|
+
items.push(...this.listItem(child));
|
|
19072
|
+
} else {
|
|
19073
|
+
items.push(...this.listItem({ type: TextNodeType.listItem, content: [child] }));
|
|
19074
|
+
}
|
|
19075
|
+
}
|
|
19076
|
+
if (items.length === 0) return [];
|
|
19077
|
+
const newAttrs = { ...attrs };
|
|
19078
|
+
if (ordered && start !== void 0) newAttrs.start = start;
|
|
19079
|
+
return [asNode({ ...n, attrs: newAttrs, content: items })];
|
|
19080
|
+
}
|
|
19081
|
+
/**
|
|
19082
|
+
* A list item holds a paragraph, then at most one sublist. Everything else is merged into the
|
|
19083
|
+
* paragraph; further sublists become new items (with an empty paragraph, which keeps them
|
|
19084
|
+
* attached). Returns the resulting item(s).
|
|
19085
|
+
*/
|
|
19086
|
+
listItem(item) {
|
|
19087
|
+
const inlineOpts = { stripLeadingTabs: true };
|
|
19088
|
+
const acc = {};
|
|
19089
|
+
let sublist;
|
|
19090
|
+
const extraItems = [];
|
|
19091
|
+
const merge = (inline) => {
|
|
19092
|
+
if (!acc.para) acc.para = inline;
|
|
19093
|
+
else if (inline.length > 0) acc.para.push(hardBreak(), ...inline);
|
|
19094
|
+
};
|
|
19095
|
+
for (const child of contentOf(item)) {
|
|
19096
|
+
if (isList(child)) {
|
|
19097
|
+
for (const list of this.list(child)) {
|
|
19098
|
+
if (list.type === TextNodeType.paragraph) {
|
|
19099
|
+
merge(list.content ?? []);
|
|
19100
|
+
} else if (!sublist) {
|
|
19101
|
+
sublist = list;
|
|
19102
|
+
} else {
|
|
19103
|
+
extraItems.push({ ...item, content: [paragraph([]), list] });
|
|
19104
|
+
}
|
|
19105
|
+
}
|
|
19106
|
+
} else if (child.type === TextNodeType.image) {
|
|
19107
|
+
} else {
|
|
19108
|
+
merge(this.inline([child], inlineOpts));
|
|
19109
|
+
}
|
|
19110
|
+
}
|
|
19111
|
+
const paraContent = acc.para ?? [];
|
|
19112
|
+
if (!hasText(paraContent) && !sublist) return extraItems;
|
|
19113
|
+
const content = [paragraph(paraContent)];
|
|
19114
|
+
if (sublist) content.push(sublist);
|
|
19115
|
+
return [{ ...item, content }, ...extraItems];
|
|
19116
|
+
}
|
|
19117
|
+
//
|
|
19118
|
+
// Inline context
|
|
19119
|
+
//
|
|
19120
|
+
/** A root node at tag location: paragraphs of inline content only */
|
|
19121
|
+
inlineRootNode(n, opts) {
|
|
19122
|
+
switch (n.type) {
|
|
19123
|
+
case TextNodeType.text:
|
|
19124
|
+
case TextNodeType.hardBreak:
|
|
19125
|
+
case TextNodeType.imageInline:
|
|
19126
|
+
case TextNodeType.latex:
|
|
19127
|
+
return this.inline([n], opts);
|
|
19128
|
+
case TextNodeType.image:
|
|
19129
|
+
return [];
|
|
19130
|
+
default:
|
|
19131
|
+
if (isBodyBit(n)) return [n];
|
|
19132
|
+
if (isList(n)) {
|
|
19133
|
+
return contentOf(n).map(
|
|
19134
|
+
(item) => paragraph(this.inline([item], { ...opts, stripLeadingTabs: true }))
|
|
19135
|
+
);
|
|
19136
|
+
}
|
|
19137
|
+
return [paragraph(this.inline(contentOf(n), opts))];
|
|
19138
|
+
}
|
|
19139
|
+
}
|
|
19140
|
+
inline(nodes, opts = {}) {
|
|
19141
|
+
const result = [];
|
|
19142
|
+
const separator = () => opts.singleLine ? this.spaceText() : hardBreak();
|
|
19143
|
+
const separate = () => {
|
|
19144
|
+
if (result.length > 0 && !isHardBreak(result[result.length - 1])) result.push(separator());
|
|
19145
|
+
};
|
|
19146
|
+
for (const n of nodes) {
|
|
19147
|
+
switch (n.type) {
|
|
19148
|
+
case TextNodeType.text: {
|
|
19149
|
+
const text = this.text(n, opts);
|
|
19150
|
+
if (text) result.push(text);
|
|
19151
|
+
break;
|
|
19152
|
+
}
|
|
19153
|
+
case TextNodeType.hardBreak:
|
|
19154
|
+
result.push(separator());
|
|
19155
|
+
break;
|
|
19156
|
+
case TextNodeType.imageInline: {
|
|
19157
|
+
if (opts.plain) break;
|
|
19158
|
+
const image = this.imageInline(n);
|
|
19159
|
+
if (image) result.push(image);
|
|
19160
|
+
break;
|
|
19161
|
+
}
|
|
19162
|
+
case TextNodeType.latex:
|
|
19163
|
+
if (opts.plain) break;
|
|
19164
|
+
if (typeof attrsOf2(n).formula === "string") result.push(n);
|
|
19165
|
+
break;
|
|
19166
|
+
case TextNodeType.image:
|
|
19167
|
+
break;
|
|
19168
|
+
default:
|
|
19169
|
+
if (isBodyBit(n)) {
|
|
19170
|
+
result.push(n);
|
|
19171
|
+
} else if (isList(n)) {
|
|
19172
|
+
for (const item of contentOf(n)) {
|
|
19173
|
+
separate();
|
|
19174
|
+
result.push(...this.inline([item], opts));
|
|
19175
|
+
}
|
|
19176
|
+
} else if (FLATTENED_BLOCK_TYPES.indexOf(n.type) !== -1) {
|
|
19177
|
+
separate();
|
|
19178
|
+
result.push(...this.inline(contentOf(n), opts));
|
|
19179
|
+
} else if (Array.isArray(n.content)) {
|
|
19180
|
+
result.push({ ...n, content: this.inline(contentOf(n), opts) });
|
|
19181
|
+
} else {
|
|
19182
|
+
result.push(n);
|
|
19183
|
+
}
|
|
19184
|
+
}
|
|
19185
|
+
}
|
|
19186
|
+
return this.dropSymbolsBeforePipes(result);
|
|
19187
|
+
}
|
|
19188
|
+
/**
|
|
19189
|
+
* A symbol's media chain swallows every following `...|` segment on its line (even when sealed
|
|
19190
|
+
* with `^`), so a symbol mark has no representable form when the rest of the line contains `|`.
|
|
19191
|
+
*/
|
|
19192
|
+
dropSymbolsBeforePipes(nodes) {
|
|
19193
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
19194
|
+
const n = nodes[i];
|
|
19195
|
+
if (!n.marks?.some((m) => m.type === TextMarkType.symbol)) continue;
|
|
19196
|
+
let pipeFollows = false;
|
|
19197
|
+
for (let j = i + 1; j < nodes.length && !isHardBreak(nodes[j]); j++) {
|
|
19198
|
+
const text = nodes[j].text;
|
|
19199
|
+
if (typeof text !== "string") continue;
|
|
19200
|
+
const firstLine = text.split(/[\n\r\u2028\u2029]/, 1)[0];
|
|
19201
|
+
if (firstLine.indexOf("|") !== -1) pipeFollows = true;
|
|
19202
|
+
if (hasLineTerminator(text)) break;
|
|
19203
|
+
}
|
|
19204
|
+
if (pipeFollows) {
|
|
19205
|
+
const marks = n.marks.filter((m) => m.type !== TextMarkType.symbol);
|
|
19206
|
+
const { marks: _m, ...rest } = n;
|
|
19207
|
+
nodes[i] = marks.length > 0 ? { ...rest, marks } : rest;
|
|
19208
|
+
}
|
|
19209
|
+
}
|
|
19210
|
+
return nodes;
|
|
19211
|
+
}
|
|
19212
|
+
text(n, opts) {
|
|
19213
|
+
if (typeof n.text !== "string") return void 0;
|
|
19214
|
+
let text = n.text;
|
|
19215
|
+
if (opts.stripLeadingTabs) text = text.replace(LEADING_TAB_REGEX, "$1");
|
|
19216
|
+
if (opts.singleLine) text = text.replace(/[\n\r\u2028\u2029]+/g, " ");
|
|
19217
|
+
if (!text) return void 0;
|
|
19218
|
+
const marks = sanitizeMarks(n.marks, {
|
|
19219
|
+
chainValue: opts.chainValue,
|
|
19220
|
+
normalizeChainValue: (content) => this.chainValue(content)
|
|
19221
|
+
});
|
|
19222
|
+
const { marks: _m, ...rest } = n;
|
|
19223
|
+
return marks.length > 0 ? { ...rest, text, marks } : { ...rest, text };
|
|
19224
|
+
}
|
|
19225
|
+
spaceText() {
|
|
19226
|
+
return { type: TextNodeType.text, text: " " };
|
|
19227
|
+
}
|
|
19228
|
+
imageInline(n) {
|
|
19229
|
+
const attrs = attrsOf2(n);
|
|
19230
|
+
if (!isUrl(attrs.src)) return void 0;
|
|
19231
|
+
const alt = attrs.alt;
|
|
19232
|
+
if (!isInlineAlt(alt)) return void 0;
|
|
19233
|
+
return asNode({
|
|
19234
|
+
...n,
|
|
19235
|
+
attrs: { src: attrs.src, alt, ...sanitizeMediaAttrs("imageInline", attrs) }
|
|
19236
|
+
});
|
|
19237
|
+
}
|
|
19238
|
+
/**
|
|
19239
|
+
* Footnote content: a `|`-free single line of plain text with short-form standard marks.
|
|
19240
|
+
* Returns undefined when the content cannot be represented.
|
|
19241
|
+
*/
|
|
19242
|
+
chainValue(content) {
|
|
19243
|
+
if (!Array.isArray(content)) return [];
|
|
19244
|
+
const nodes = this.inline(content.filter(isNode), {
|
|
19245
|
+
plain: true,
|
|
19246
|
+
chainValue: true,
|
|
19247
|
+
singleLine: true
|
|
19248
|
+
});
|
|
19249
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
19250
|
+
const n = nodes[i];
|
|
19251
|
+
const text = n.text;
|
|
19252
|
+
if (typeof text === "string" && (text.indexOf("|") !== -1 || hasLineTerminator(text))) {
|
|
19253
|
+
return void 0;
|
|
19254
|
+
}
|
|
19255
|
+
if (n.marks?.some((m) => m.type === TextMarkType.link) && !isSimpleLinkNode(n, nodes[i + 1])) {
|
|
19256
|
+
const { marks: _m, ...rest } = n;
|
|
19257
|
+
nodes[i] = rest;
|
|
19258
|
+
}
|
|
19259
|
+
}
|
|
19260
|
+
return nodes;
|
|
19261
|
+
}
|
|
19262
|
+
};
|
|
19263
|
+
function normalizeTextAst(ast, options) {
|
|
19264
|
+
return new TextAstNormalizer(options).normalize(ast);
|
|
19265
|
+
}
|
|
19266
|
+
|
|
18417
19267
|
// src/generator/text/TextGenerator.ts
|
|
18418
19268
|
var DEFAULT_OPTIONS = {
|
|
18419
19269
|
bodyBitCallback: void 0,
|
|
@@ -18506,21 +19356,9 @@ var INLINE_MARK_TYPES = [
|
|
|
18506
19356
|
TextMarkType.colorPicker,
|
|
18507
19357
|
TextMarkType.comment
|
|
18508
19358
|
];
|
|
18509
|
-
var HIGHLIGHT_COLORS = [
|
|
18510
|
-
"orange",
|
|
18511
|
-
"yellow",
|
|
18512
|
-
"green",
|
|
18513
|
-
"blue",
|
|
18514
|
-
"purple",
|
|
18515
|
-
"pink",
|
|
18516
|
-
"brown",
|
|
18517
|
-
"white",
|
|
18518
|
-
"black",
|
|
18519
|
-
"gray"
|
|
18520
|
-
];
|
|
18521
19359
|
var INDENTATION_REGEX = new RegExp(/(\n|\r\n)/, "g");
|
|
18522
|
-
var LINK_REGEX = new RegExp(/https?:\/\/|mailto:(.*)/, "g");
|
|
18523
19360
|
var LINK_BREAKSCAPE_REGEX = new RegExp(/\]/, "g");
|
|
19361
|
+
var CHAIN_CONTINUATION_REGEX = /^[^\n\r\u2028\u2029]*\|/;
|
|
18524
19362
|
var Stage = {
|
|
18525
19363
|
enter: "enter",
|
|
18526
19364
|
between: "between",
|
|
@@ -18557,6 +19395,8 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18557
19395
|
__publicField(this, "textDepth", 0);
|
|
18558
19396
|
__publicField(this, "placeholderIndex", 0);
|
|
18559
19397
|
__publicField(this, "placeholders", {});
|
|
19398
|
+
__publicField(this, "chainJustClosed", false);
|
|
19399
|
+
__publicField(this, "simpleLinkAllowed", true);
|
|
18560
19400
|
// For pre-text
|
|
18561
19401
|
__publicField(this, "rootParagraphNodeContentIndex", 0);
|
|
18562
19402
|
__publicField(this, "previousRootParagraphContextType", TextNodeType.text);
|
|
@@ -18602,6 +19442,11 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18602
19442
|
generateSync(ast, textFormat, textLocation, options) {
|
|
18603
19443
|
if (!ast || !Array.isArray(ast)) return "";
|
|
18604
19444
|
this.generateOptions = Object.assign({}, options);
|
|
19445
|
+
ast = normalizeTextAst(ast, {
|
|
19446
|
+
format: textFormat ?? TextFormat2.bitmarkText,
|
|
19447
|
+
location: textLocation,
|
|
19448
|
+
chainValue: this.generateOptions.chainValueContext
|
|
19449
|
+
});
|
|
18605
19450
|
this.validateGenerateOptions(ast);
|
|
18606
19451
|
if (!this.generateOptions.plainTextDividerAllowed) {
|
|
18607
19452
|
this.resetState(textFormat, textLocation);
|
|
@@ -18645,6 +19490,8 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18645
19490
|
this.textDepth = 0;
|
|
18646
19491
|
this.placeholderIndex = 0;
|
|
18647
19492
|
this.placeholders = {};
|
|
19493
|
+
this.chainJustClosed = false;
|
|
19494
|
+
this.simpleLinkAllowed = true;
|
|
18648
19495
|
this.rootParagraphNodeContentIndex = 0;
|
|
18649
19496
|
this.previousRootParagraphContextType = TextNodeType.hardBreak;
|
|
18650
19497
|
this.inPreText = false;
|
|
@@ -18710,6 +19557,7 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18710
19557
|
this.writeHardBreak(node);
|
|
18711
19558
|
break;
|
|
18712
19559
|
case TextNodeType.text: {
|
|
19560
|
+
this.simpleLinkAllowed = this.isSimpleLinkAllowedAfter(route);
|
|
18713
19561
|
this.writeMarks(node, Stage.enter);
|
|
18714
19562
|
this.writeText(node);
|
|
18715
19563
|
this.writeMarks(node, Stage.between);
|
|
@@ -18723,9 +19571,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18723
19571
|
this.writeHeading(node);
|
|
18724
19572
|
this.inHeading = true;
|
|
18725
19573
|
break;
|
|
18726
|
-
case TextNodeType.section:
|
|
18727
|
-
this.writeSection(node);
|
|
18728
|
-
break;
|
|
18729
19574
|
case TextNodeType.listItem:
|
|
18730
19575
|
case TextNodeType.taskItem:
|
|
18731
19576
|
this.writeBullet(node, route);
|
|
@@ -18783,7 +19628,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18783
19628
|
break;
|
|
18784
19629
|
case TextNodeType.heading:
|
|
18785
19630
|
this.inHeading = false;
|
|
18786
|
-
case TextNodeType.section:
|
|
18787
19631
|
case TextNodeType.image:
|
|
18788
19632
|
if (!this.inParagraph) {
|
|
18789
19633
|
this.writeNL();
|
|
@@ -18895,9 +19739,9 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18895
19739
|
*/
|
|
18896
19740
|
getLinkHref(node) {
|
|
18897
19741
|
if (node.type === TextNodeType.text && node.marks) {
|
|
18898
|
-
const href = node.marks.reduce((acc,
|
|
18899
|
-
if (
|
|
18900
|
-
const linkMark =
|
|
19742
|
+
const href = node.marks.reduce((acc, mark2) => {
|
|
19743
|
+
if (mark2.type === TextMarkType.link) {
|
|
19744
|
+
const linkMark = mark2;
|
|
18901
19745
|
const href2 = linkMark.attrs?.href;
|
|
18902
19746
|
if (href2) return href2;
|
|
18903
19747
|
}
|
|
@@ -18962,6 +19806,9 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18962
19806
|
const indentationString = this.getIndentationString();
|
|
18963
19807
|
s = s.replace(INDENTATION_REGEX, `$1${indentationString}`);
|
|
18964
19808
|
}
|
|
19809
|
+
if (this.chainJustClosed && CHAIN_CONTINUATION_REGEX.test(s)) {
|
|
19810
|
+
s = `^${s}`;
|
|
19811
|
+
}
|
|
18965
19812
|
if (this.havePreText && this.rootParagraphNodeContentIndex === this.preTextIndex) {
|
|
18966
19813
|
this.writePlainTextDivider();
|
|
18967
19814
|
this.writeNL();
|
|
@@ -18991,14 +19838,14 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
18991
19838
|
* @returns true if a simple link, otherwise false
|
|
18992
19839
|
*/
|
|
18993
19840
|
isSimpleLink(node) {
|
|
18994
|
-
|
|
18995
|
-
|
|
18996
|
-
|
|
18997
|
-
|
|
18998
|
-
|
|
18999
|
-
|
|
19000
|
-
|
|
19001
|
-
return
|
|
19841
|
+
return this.simpleLinkAllowed && isSimpleLinkNode(node, void 0);
|
|
19842
|
+
}
|
|
19843
|
+
/**
|
|
19844
|
+
* The bare-URL link short form is only safe when whatever is written next cannot be read as
|
|
19845
|
+
* part of the URL (the parser's Url rule consumes every following UrlChar).
|
|
19846
|
+
*/
|
|
19847
|
+
isSimpleLinkAllowedAfter(route) {
|
|
19848
|
+
return canFollowBareUrl(this.getSiblingNodes(route).right);
|
|
19002
19849
|
}
|
|
19003
19850
|
/**
|
|
19004
19851
|
* Get the link text if the node is a link, otherwise return false
|
|
@@ -19010,15 +19857,8 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19010
19857
|
if (node.text == null) return false;
|
|
19011
19858
|
const href = this.getLinkHref(node);
|
|
19012
19859
|
if (href) {
|
|
19013
|
-
|
|
19014
|
-
|
|
19015
|
-
if (hrefText === node.text) {
|
|
19016
|
-
res = href;
|
|
19017
|
-
} else {
|
|
19018
|
-
res = node.text;
|
|
19019
|
-
}
|
|
19020
|
-
res = (res ?? "").replace(LINK_BREAKSCAPE_REGEX, "^]");
|
|
19021
|
-
return res;
|
|
19860
|
+
const res = this.isSimpleLink(node) ? href : node.text;
|
|
19861
|
+
return res.replace(LINK_BREAKSCAPE_REGEX, "^]");
|
|
19022
19862
|
}
|
|
19023
19863
|
return false;
|
|
19024
19864
|
}
|
|
@@ -19075,22 +19915,17 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19075
19915
|
writeMarks(node, stage) {
|
|
19076
19916
|
if (node.marks) {
|
|
19077
19917
|
const forceSingleMark = this.generateOptions.forceInline || !!(this.inInline || this.inHeading);
|
|
19078
|
-
|
|
19079
|
-
const emptyMarks = node.marks.length === 0;
|
|
19080
|
-
if (emptyMarks) {
|
|
19081
|
-
this.writeMarkTextWrapper(INLINE_MARK);
|
|
19082
|
-
return;
|
|
19083
|
-
}
|
|
19084
|
-
const marks = this.getWritableMarks(node.marks);
|
|
19918
|
+
const marks = node.marks;
|
|
19085
19919
|
if (marks.length === 0) return;
|
|
19920
|
+
this.thisNodeIsPreText = false;
|
|
19086
19921
|
const singleMark = marks.length === 1 && forceSingleMark;
|
|
19087
19922
|
const markStartEnd = marks.reduce(
|
|
19088
|
-
(acc,
|
|
19923
|
+
(acc, mark2) => {
|
|
19089
19924
|
if (acc) return acc;
|
|
19090
|
-
if (this.isStandardMark(
|
|
19091
|
-
if (singleMark) return STANDARD_MARKS[
|
|
19925
|
+
if (this.isStandardMark(mark2)) {
|
|
19926
|
+
if (singleMark) return STANDARD_MARKS[mark2.type];
|
|
19092
19927
|
return INLINE_MARK;
|
|
19093
|
-
} else if (this.isInlineMark(
|
|
19928
|
+
} else if (this.isInlineMark(mark2)) {
|
|
19094
19929
|
return INLINE_MARK;
|
|
19095
19930
|
} else {
|
|
19096
19931
|
}
|
|
@@ -19105,56 +19940,59 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19105
19940
|
this.writeMarkTextWrapper(markStartEnd);
|
|
19106
19941
|
}
|
|
19107
19942
|
if (stage == Stage.between) {
|
|
19108
|
-
for (const
|
|
19109
|
-
if (this.isStandardMark(
|
|
19943
|
+
for (const mark2 of marks) {
|
|
19944
|
+
if (this.isStandardMark(mark2)) {
|
|
19110
19945
|
if (!singleMark) {
|
|
19111
19946
|
this.writeInlineMarkStartEnd();
|
|
19112
|
-
this.writeInlineMark(
|
|
19947
|
+
this.writeInlineMark(mark2);
|
|
19113
19948
|
}
|
|
19114
|
-
} else if (TextMarkType.comment ===
|
|
19949
|
+
} else if (TextMarkType.comment === mark2.type) {
|
|
19115
19950
|
this.writeInlineMarkStartEnd();
|
|
19116
|
-
this.writeCommentMark(
|
|
19117
|
-
} else if (TextMarkType.link ===
|
|
19951
|
+
this.writeCommentMark(mark2);
|
|
19952
|
+
} else if (TextMarkType.link === mark2.type) {
|
|
19118
19953
|
this.writeInlineMarkStartEnd();
|
|
19119
|
-
this.writeLinkMark(
|
|
19120
|
-
} else if (TextMarkType.ref ===
|
|
19954
|
+
this.writeLinkMark(mark2);
|
|
19955
|
+
} else if (TextMarkType.ref === mark2.type) {
|
|
19121
19956
|
this.writeInlineMarkStartEnd();
|
|
19122
|
-
this.writeRefMark(
|
|
19123
|
-
} else if (TextMarkType.xref ===
|
|
19957
|
+
this.writeRefMark(mark2);
|
|
19958
|
+
} else if (TextMarkType.xref === mark2.type) {
|
|
19124
19959
|
this.writeInlineMarkStartEnd();
|
|
19125
|
-
this.writeXRefMark(
|
|
19126
|
-
} else if (TextMarkType.extref ===
|
|
19960
|
+
this.writeXRefMark(mark2);
|
|
19961
|
+
} else if (TextMarkType.extref === mark2.type) {
|
|
19127
19962
|
this.writeInlineMarkStartEnd();
|
|
19128
|
-
this.writeExtRefMark(
|
|
19129
|
-
} else if (TextMarkType.footnote ===
|
|
19963
|
+
this.writeExtRefMark(mark2);
|
|
19964
|
+
} else if (TextMarkType.footnote === mark2.type) {
|
|
19130
19965
|
this.writeInlineMarkStartEnd();
|
|
19131
|
-
this.writeFootnoteMark(
|
|
19132
|
-
} else if (TextMarkType.footnoteStar ===
|
|
19966
|
+
this.writeFootnoteMark(mark2);
|
|
19967
|
+
} else if (TextMarkType.footnoteStar === mark2.type) {
|
|
19133
19968
|
this.writeInlineMarkStartEnd();
|
|
19134
|
-
this.writeFootnoteStarMark(
|
|
19135
|
-
} else if (TextMarkType.symbol ===
|
|
19969
|
+
this.writeFootnoteStarMark(mark2);
|
|
19970
|
+
} else if (TextMarkType.symbol === mark2.type) {
|
|
19136
19971
|
this.writeInlineMarkStartEnd();
|
|
19137
|
-
this.writeSymbolMark(
|
|
19138
|
-
} else if (this.isInlineMark(
|
|
19972
|
+
this.writeSymbolMark(mark2);
|
|
19973
|
+
} else if (this.isInlineMark(mark2)) {
|
|
19139
19974
|
this.writeInlineMarkStartEnd();
|
|
19140
|
-
this.writeInlineMark(
|
|
19975
|
+
this.writeInlineMark(mark2);
|
|
19141
19976
|
} else {
|
|
19142
19977
|
}
|
|
19143
19978
|
}
|
|
19144
19979
|
}
|
|
19145
19980
|
if (stage == Stage.exit) {
|
|
19146
19981
|
let inlineMarkWritten = false;
|
|
19147
|
-
for (const
|
|
19148
|
-
if (this.isStandardMark(
|
|
19982
|
+
for (const mark2 of marks) {
|
|
19983
|
+
if (this.isStandardMark(mark2)) {
|
|
19149
19984
|
if (!singleMark) {
|
|
19150
19985
|
inlineMarkWritten = true;
|
|
19151
19986
|
}
|
|
19152
|
-
} else if (TextMarkType.comment ===
|
|
19987
|
+
} 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)) {
|
|
19153
19988
|
inlineMarkWritten = true;
|
|
19154
19989
|
} else {
|
|
19155
19990
|
}
|
|
19156
19991
|
}
|
|
19157
|
-
if (inlineMarkWritten)
|
|
19992
|
+
if (inlineMarkWritten) {
|
|
19993
|
+
this.writeInlineMarkStartEnd();
|
|
19994
|
+
this.chainJustClosed = true;
|
|
19995
|
+
}
|
|
19158
19996
|
}
|
|
19159
19997
|
}
|
|
19160
19998
|
}
|
|
@@ -19190,15 +20028,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19190
20028
|
s += " ";
|
|
19191
20029
|
this.write(s);
|
|
19192
20030
|
}
|
|
19193
|
-
writeSection(node) {
|
|
19194
|
-
let s = "";
|
|
19195
|
-
if (node.section) {
|
|
19196
|
-
s = `|${node.section}: `;
|
|
19197
|
-
} else {
|
|
19198
|
-
s = "|";
|
|
19199
|
-
}
|
|
19200
|
-
this.write(s);
|
|
19201
|
-
}
|
|
19202
20031
|
writeBullet(node, route) {
|
|
19203
20032
|
let bullet = this.getIndentationString();
|
|
19204
20033
|
const listParent = this.getParentNode(route, 2);
|
|
@@ -19221,7 +20050,7 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19221
20050
|
bullet += "\u2022a ";
|
|
19222
20051
|
} else if (listType === TextNodeType.taskList) {
|
|
19223
20052
|
const taskList = node;
|
|
19224
|
-
const checked = taskList.attrs?.checked
|
|
20053
|
+
const checked = taskList.attrs?.checked === true;
|
|
19225
20054
|
bullet += checked ? "\u2022+ " : "\u2022- ";
|
|
19226
20055
|
}
|
|
19227
20056
|
if (bullet) this.write(bullet);
|
|
@@ -19230,28 +20059,20 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19230
20059
|
if (node.attrs == null || !node.attrs.src) return;
|
|
19231
20060
|
const attrs = node.attrs;
|
|
19232
20061
|
const inlineImage = node.type === TextNodeType.imageInline;
|
|
19233
|
-
|
|
19234
|
-
|
|
19235
|
-
ignoreAttributes = /* @__PURE__ */ new Set(["alt", "zoomDisabled", "title"]);
|
|
19236
|
-
const a = attrs;
|
|
19237
|
-
if (a.alignmentVertical === "top") ignoreAttributes.add("alignmentVertical");
|
|
19238
|
-
if (a.size === "line-height") ignoreAttributes.add("size");
|
|
19239
|
-
}
|
|
19240
|
-
const mediaAttrs = this.getMediaAttrs(inlineImage ? "imageInline" : "image", attrs, {
|
|
19241
|
-
ignoreAttributes
|
|
19242
|
-
});
|
|
20062
|
+
const kind = inlineImage ? "imageInline" : "image";
|
|
20063
|
+
const chain = serializeMediaChain(kind, attrs);
|
|
19243
20064
|
let s = "";
|
|
19244
20065
|
if (inlineImage) {
|
|
19245
20066
|
s = `==${attrs.alt ?? ""}==`;
|
|
19246
20067
|
}
|
|
19247
|
-
s +=
|
|
20068
|
+
s += `|${kind}:${attrs.src}${chain}|`;
|
|
19248
20069
|
this.write(s);
|
|
19249
20070
|
}
|
|
19250
20071
|
writeCodeBlock(node) {
|
|
19251
|
-
|
|
19252
|
-
const
|
|
19253
|
-
const s = `|code:${
|
|
19254
|
-
|
|
20072
|
+
const raw = node.attrs?.language ?? node.language;
|
|
20073
|
+
const language = normalizeBlockCodeLanguage(raw) ?? "";
|
|
20074
|
+
const s = language ? `|code:${language}
|
|
20075
|
+
` : "|code\n";
|
|
19255
20076
|
this.write(s);
|
|
19256
20077
|
}
|
|
19257
20078
|
writeLatex(node) {
|
|
@@ -19267,10 +20088,10 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19267
20088
|
writeMarkTextWrapper(s) {
|
|
19268
20089
|
if (s) this.write(s);
|
|
19269
20090
|
}
|
|
19270
|
-
writeInlineMark(
|
|
19271
|
-
const attrs =
|
|
20091
|
+
writeInlineMark(mark2) {
|
|
20092
|
+
const attrs = mark2.attrs ?? {};
|
|
19272
20093
|
let s;
|
|
19273
|
-
switch (
|
|
20094
|
+
switch (mark2.type) {
|
|
19274
20095
|
case TextMarkType.textStyle:
|
|
19275
20096
|
case TextMarkType.color:
|
|
19276
20097
|
s = `color:${attrs.color ?? ""}`;
|
|
@@ -19281,10 +20102,10 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19281
20102
|
break;
|
|
19282
20103
|
case TextMarkType.highlight:
|
|
19283
20104
|
case TextMarkType.userHighlight:
|
|
19284
|
-
s = attrs.color ? `${
|
|
20105
|
+
s = attrs.color ? `${mark2.type}|color:${attrs.color}` : `${mark2.type}`;
|
|
19285
20106
|
break;
|
|
19286
20107
|
default: {
|
|
19287
|
-
s = `${
|
|
20108
|
+
s = `${mark2.type}`;
|
|
19288
20109
|
for (const [k, v] of Object.entries(attrs)) {
|
|
19289
20110
|
if (k === "language" && v !== "plain text" || k === "propertyRef" || k === "name") {
|
|
19290
20111
|
s = `${s}:${v}`;
|
|
@@ -19294,88 +20115,49 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19294
20115
|
}
|
|
19295
20116
|
this.write(s);
|
|
19296
20117
|
}
|
|
19297
|
-
/**
|
|
19298
|
-
* Resolve the marks of a text node into the marks that will actually be written.
|
|
19299
|
-
*
|
|
19300
|
-
* - Merges a legacy standalone 'duration' mark into its sibling 'timer' mark.
|
|
19301
|
-
* - Drops marks the current grammar cannot express (standalone 'duration', 'timer'
|
|
19302
|
-
* without a duration).
|
|
19303
|
-
* - Moves a 'textStyle'/'color' mark before a preceding bare 'highlight'/'userHighlight'
|
|
19304
|
-
* mark when its color is a valid highlight color; written in the original order the
|
|
19305
|
-
* output would re-parse as a highlight-with-color compound mark and change meaning.
|
|
19306
|
-
*/
|
|
19307
|
-
getWritableMarks(nodeMarks) {
|
|
19308
|
-
const attrsOf = (m) => m.attrs ?? {};
|
|
19309
|
-
let marks = [...nodeMarks];
|
|
19310
|
-
const timer = marks.find((m) => m.type === TextMarkType.timer);
|
|
19311
|
-
const duration = marks.find((m) => m.type === TextMarkType.duration);
|
|
19312
|
-
if (timer && duration && !attrsOf(timer).duration) {
|
|
19313
|
-
marks = marks.map(
|
|
19314
|
-
(m) => m === timer ? {
|
|
19315
|
-
...timer,
|
|
19316
|
-
attrs: { ...attrsOf(timer), duration: attrsOf(duration).duration }
|
|
19317
|
-
} : m
|
|
19318
|
-
);
|
|
19319
|
-
}
|
|
19320
|
-
marks = marks.filter((m) => {
|
|
19321
|
-
if (m.type === TextMarkType.duration) return false;
|
|
19322
|
-
if (m.type === TextMarkType.timer) return !!attrsOf(m).duration;
|
|
19323
|
-
return true;
|
|
19324
|
-
});
|
|
19325
|
-
const isBareHighlight = (m) => (m.type === TextMarkType.highlight || m.type === TextMarkType.userHighlight) && !attrsOf(m).color;
|
|
19326
|
-
const isHighlightColorStyle = (m) => (m.type === TextMarkType.textStyle || m.type === TextMarkType.color) && HIGHLIGHT_COLORS.indexOf(attrsOf(m).color) !== -1;
|
|
19327
|
-
for (let i = 0; i < marks.length - 1; i++) {
|
|
19328
|
-
if (isBareHighlight(marks[i]) && isHighlightColorStyle(marks[i + 1])) {
|
|
19329
|
-
const tmp = marks[i];
|
|
19330
|
-
marks[i] = marks[i + 1];
|
|
19331
|
-
marks[i + 1] = tmp;
|
|
19332
|
-
}
|
|
19333
|
-
}
|
|
19334
|
-
return marks;
|
|
19335
|
-
}
|
|
19336
20118
|
/**
|
|
19337
20119
|
* True if the mark is written using its standard form (e.g. **bold**, !!highlight!!)
|
|
19338
20120
|
* when it is the only mark. A highlight mark with a color attribute is excluded - it
|
|
19339
20121
|
* can only be expressed using the inline chain form (==text==|highlight|color:x|).
|
|
19340
20122
|
*/
|
|
19341
|
-
isStandardMark(
|
|
19342
|
-
if (STANDARD_MARK_TYPES.indexOf(
|
|
19343
|
-
return !(
|
|
20123
|
+
isStandardMark(mark2) {
|
|
20124
|
+
if (STANDARD_MARK_TYPES.indexOf(mark2.type) === -1) return false;
|
|
20125
|
+
return !(mark2.attrs && mark2.attrs.color);
|
|
19344
20126
|
}
|
|
19345
20127
|
/**
|
|
19346
20128
|
* True if the mark is written using the inline chain form (==text==|mark|).
|
|
19347
20129
|
*/
|
|
19348
|
-
isInlineMark(
|
|
19349
|
-
if (INLINE_MARK_TYPES.indexOf(
|
|
19350
|
-
return
|
|
20130
|
+
isInlineMark(mark2) {
|
|
20131
|
+
if (INLINE_MARK_TYPES.indexOf(mark2.type) !== -1) return true;
|
|
20132
|
+
return mark2.type === TextMarkType.highlight && !!(mark2.attrs && mark2.attrs.color);
|
|
19351
20133
|
}
|
|
19352
|
-
writeCommentMark(
|
|
19353
|
-
const comment =
|
|
20134
|
+
writeCommentMark(mark2) {
|
|
20135
|
+
const comment = mark2.comment || "";
|
|
19354
20136
|
const s = `#${comment}`;
|
|
19355
20137
|
this.write(s);
|
|
19356
20138
|
}
|
|
19357
|
-
writeLinkMark(
|
|
19358
|
-
const href =
|
|
20139
|
+
writeLinkMark(mark2) {
|
|
20140
|
+
const href = mark2.attrs?.href || "";
|
|
19359
20141
|
const linkText = (href ?? "").replace(LINK_BREAKSCAPE_REGEX, "^]");
|
|
19360
20142
|
const s = `link:${linkText}`;
|
|
19361
20143
|
this.write(s);
|
|
19362
20144
|
}
|
|
19363
|
-
writeRefMark(
|
|
19364
|
-
const ref =
|
|
20145
|
+
writeRefMark(mark2) {
|
|
20146
|
+
const ref = mark2.attrs?.reference ?? "";
|
|
19365
20147
|
const s = `\u25BA${ref}`;
|
|
19366
20148
|
this.write(s);
|
|
19367
20149
|
}
|
|
19368
|
-
writeXRefMark(
|
|
19369
|
-
const xref =
|
|
19370
|
-
const ref =
|
|
20150
|
+
writeXRefMark(mark2) {
|
|
20151
|
+
const xref = mark2.attrs?.xref ?? "";
|
|
20152
|
+
const ref = mark2.attrs?.reference ?? "";
|
|
19371
20153
|
let s = `xref:${xref}`;
|
|
19372
20154
|
if (ref) s += `|\u25BA${ref}`;
|
|
19373
20155
|
this.write(s);
|
|
19374
20156
|
}
|
|
19375
|
-
writeExtRefMark(
|
|
19376
|
-
const extref =
|
|
19377
|
-
const refs =
|
|
19378
|
-
const provider =
|
|
20157
|
+
writeExtRefMark(mark2) {
|
|
20158
|
+
const extref = mark2.attrs?.extref ?? "";
|
|
20159
|
+
const refs = mark2.attrs?.references ?? [];
|
|
20160
|
+
const provider = mark2.attrs?.provider ?? "";
|
|
19379
20161
|
let s = `extref:${extref}`;
|
|
19380
20162
|
for (const ref of refs) {
|
|
19381
20163
|
s += `|\u25BA${ref ?? ""}`;
|
|
@@ -19383,39 +20165,39 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19383
20165
|
s += `|provider:${provider}`;
|
|
19384
20166
|
this.write(s);
|
|
19385
20167
|
}
|
|
19386
|
-
writeFootnoteMark(
|
|
20168
|
+
writeFootnoteMark(mark2) {
|
|
19387
20169
|
const s = `footnote:`;
|
|
19388
20170
|
this.write(s);
|
|
19389
20171
|
const text = this.internalTextGenerator?.generateSync(
|
|
19390
|
-
|
|
20172
|
+
mark2.attrs?.content,
|
|
19391
20173
|
this.textFormat,
|
|
19392
20174
|
this.textLocation,
|
|
19393
20175
|
{
|
|
19394
20176
|
...this.generateOptions,
|
|
19395
|
-
forceInline: true
|
|
20177
|
+
forceInline: true,
|
|
20178
|
+
chainValueContext: true
|
|
19396
20179
|
}
|
|
19397
20180
|
) ?? "";
|
|
19398
20181
|
this.write(text);
|
|
19399
20182
|
}
|
|
19400
|
-
writeFootnoteStarMark(
|
|
20183
|
+
writeFootnoteStarMark(mark2) {
|
|
19401
20184
|
const s = `footnote*:`;
|
|
19402
20185
|
this.write(s);
|
|
19403
20186
|
const text = this.internalTextGenerator?.generateSync(
|
|
19404
|
-
|
|
20187
|
+
mark2.attrs?.content,
|
|
19405
20188
|
this.textFormat,
|
|
19406
20189
|
this.textLocation,
|
|
19407
20190
|
{
|
|
19408
20191
|
...this.generateOptions,
|
|
19409
|
-
forceInline: true
|
|
20192
|
+
forceInline: true,
|
|
20193
|
+
chainValueContext: true
|
|
19410
20194
|
}
|
|
19411
20195
|
) ?? "";
|
|
19412
20196
|
this.write(text);
|
|
19413
20197
|
}
|
|
19414
|
-
writeSymbolMark(
|
|
19415
|
-
|
|
19416
|
-
const
|
|
19417
|
-
const mediaAttrs = this.getMediaAttrs("symbol", attrs);
|
|
19418
|
-
const s = mediaAttrs ?? "";
|
|
20198
|
+
writeSymbolMark(mark2) {
|
|
20199
|
+
const attrs = mark2.attrs ?? {};
|
|
20200
|
+
const s = `symbol:${attrs.src ?? ""}${serializeMediaChain("symbol", attrs)}`;
|
|
19419
20201
|
this.write(s);
|
|
19420
20202
|
}
|
|
19421
20203
|
writeInlineMarkStartEnd() {
|
|
@@ -19445,52 +20227,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19445
20227
|
}
|
|
19446
20228
|
this.writeString(tag);
|
|
19447
20229
|
}
|
|
19448
|
-
getMediaAttrs(mediaType, attrs, options) {
|
|
19449
|
-
if (!mediaType) return void 0;
|
|
19450
|
-
const opts = Object.assign({}, options);
|
|
19451
|
-
const ignoreAttributes = opts.ignoreAttributes ?? /* @__PURE__ */ new Set();
|
|
19452
|
-
let s = `${mediaType}:${attrs?.src ?? ""}`;
|
|
19453
|
-
const entries = Object.entries(attrs).filter(([k, _v]) => k !== "src");
|
|
19454
|
-
for (let i = 0; i < entries.length; i++) {
|
|
19455
|
-
const [k, v] = entries[i];
|
|
19456
|
-
if (ignoreAttributes.has(k)) continue;
|
|
19457
|
-
switch (k) {
|
|
19458
|
-
case "textAlign":
|
|
19459
|
-
if (v !== "left") s += `|captionAlign:${v}`;
|
|
19460
|
-
break;
|
|
19461
|
-
case "alignment":
|
|
19462
|
-
if (v !== "center") {
|
|
19463
|
-
if (v) s += `|alignment:${v}`;
|
|
19464
|
-
}
|
|
19465
|
-
break;
|
|
19466
|
-
case "title":
|
|
19467
|
-
if (v) s += `|caption:${v}`;
|
|
19468
|
-
break;
|
|
19469
|
-
case "class":
|
|
19470
|
-
if (v !== "center") {
|
|
19471
|
-
if (v) s += `|align:${v}`;
|
|
19472
|
-
}
|
|
19473
|
-
break;
|
|
19474
|
-
case "comment":
|
|
19475
|
-
if (v) s += `|#${v}`;
|
|
19476
|
-
break;
|
|
19477
|
-
case "":
|
|
19478
|
-
if (stringUtils.isString(v)) s += `|:${v}`;
|
|
19479
|
-
else s += `|`;
|
|
19480
|
-
break;
|
|
19481
|
-
case "zoomDisabled":
|
|
19482
|
-
if (!v) s += "|zoomDisabled:false";
|
|
19483
|
-
break;
|
|
19484
|
-
case "alt":
|
|
19485
|
-
case "width":
|
|
19486
|
-
case "height":
|
|
19487
|
-
default:
|
|
19488
|
-
if (k && v) s += `|${k}:${v}`;
|
|
19489
|
-
break;
|
|
19490
|
-
}
|
|
19491
|
-
}
|
|
19492
|
-
return s;
|
|
19493
|
-
}
|
|
19494
20230
|
//
|
|
19495
20231
|
// Helper functions
|
|
19496
20232
|
//
|
|
@@ -19516,6 +20252,7 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
|
|
|
19516
20252
|
*/
|
|
19517
20253
|
write(value) {
|
|
19518
20254
|
value = this.getInterTextBreakscape(value) + value;
|
|
20255
|
+
this.chainJustClosed = false;
|
|
19519
20256
|
if (this.options.writeCallback) {
|
|
19520
20257
|
this.options.writeCallback(value);
|
|
19521
20258
|
}
|
|
@@ -33701,8 +34438,8 @@ var Builder = class extends BaseBuilder {
|
|
|
33701
34438
|
break;
|
|
33702
34439
|
}
|
|
33703
34440
|
case BodyBitType.mark: {
|
|
33704
|
-
const
|
|
33705
|
-
instance7.fillBooleanExample([
|
|
34441
|
+
const mark2 = part;
|
|
34442
|
+
instance7.fillBooleanExample([mark2], __isDefaultExample, example, false);
|
|
33706
34443
|
break;
|
|
33707
34444
|
}
|
|
33708
34445
|
case BodyBitType.select: {
|
|
@@ -34483,10 +35220,10 @@ var BitmarkGenerator = class extends AstWalkerGenerator {
|
|
|
34483
35220
|
const markConfig = node.value;
|
|
34484
35221
|
const parent = this.getParentNode(route);
|
|
34485
35222
|
if (parent?.key !== NodeType.markConfig) return true;
|
|
34486
|
-
const { mark, color, emphasis } = markConfig;
|
|
34487
|
-
if (
|
|
35223
|
+
const { mark: mark2, color, emphasis } = markConfig;
|
|
35224
|
+
if (mark2) {
|
|
34488
35225
|
this.writeNL();
|
|
34489
|
-
this.writeProperty("mark",
|
|
35226
|
+
this.writeProperty("mark", mark2, route, {
|
|
34490
35227
|
format: TagFormat.plainText
|
|
34491
35228
|
});
|
|
34492
35229
|
if (color) {
|
|
@@ -34703,9 +35440,9 @@ var BitmarkGenerator = class extends AstWalkerGenerator {
|
|
|
34703
35440
|
}
|
|
34704
35441
|
// bodyBit -> mark
|
|
34705
35442
|
enter_mark(node, _route) {
|
|
34706
|
-
const
|
|
35443
|
+
const mark2 = node.value;
|
|
34707
35444
|
this.writeOPE();
|
|
34708
|
-
this.writeTextOrValue(
|
|
35445
|
+
this.writeTextOrValue(mark2.solution, TextFormat2.plainText, TextLocation2.tag);
|
|
34709
35446
|
this.writeCL();
|
|
34710
35447
|
return true;
|
|
34711
35448
|
}
|
|
@@ -34765,9 +35502,9 @@ var BitmarkGenerator = class extends AstWalkerGenerator {
|
|
|
34765
35502
|
leaf_mark(node, route) {
|
|
34766
35503
|
const root = route[0];
|
|
34767
35504
|
if (root?.key !== NodeType.mark) return;
|
|
34768
|
-
const
|
|
34769
|
-
if (
|
|
34770
|
-
this.writeProperty("mark",
|
|
35505
|
+
const mark2 = node.value;
|
|
35506
|
+
if (mark2) {
|
|
35507
|
+
this.writeProperty("mark", mark2, route, {
|
|
34771
35508
|
format: TagFormat.plainText
|
|
34772
35509
|
});
|
|
34773
35510
|
}
|
|
@@ -35481,7 +36218,7 @@ var BitmarkGenerator = class extends AstWalkerGenerator {
|
|
|
35481
36218
|
leaf_level(node, route) {
|
|
35482
36219
|
const parent = this.getParentNode(route);
|
|
35483
36220
|
if (parent?.key !== NodeType.bitsValue) return true;
|
|
35484
|
-
if (!instance2.isOfBitType(this.bitType, [BitType2.chapter])) return true;
|
|
36221
|
+
if (!instance2.isOfBitType(this.bitType, [BitType2.chapter, BitType2.h])) return true;
|
|
35485
36222
|
const level = node.value;
|
|
35486
36223
|
const bit = parent?.value;
|
|
35487
36224
|
if (level > 0 && bit.title == null) {
|
|
@@ -36524,8 +37261,6 @@ var MARK_TO_TAG = {
|
|
|
36524
37261
|
highlight: "mark",
|
|
36525
37262
|
code: "code"
|
|
36526
37263
|
};
|
|
36527
|
-
var INLINE_IMAGE_RE = /==([^=]*(?:=(?!=)[^=]*)*)==\|imageInline:([^|\s]+)((?:\|(?:@?[A-Za-z][A-Za-z0-9_-]*:[^|\s]+|#[^|\s]*))*)\|?/g;
|
|
36528
|
-
var MAX_IMAGE_DIMENSION = 9999;
|
|
36529
37264
|
var HtmlTableGenerator = class {
|
|
36530
37265
|
constructor() {
|
|
36531
37266
|
__publicField(this, "indentUnit", " ");
|
|
@@ -36667,13 +37402,13 @@ var HtmlTableGenerator = class {
|
|
|
36667
37402
|
if (!marks || marks.length === 0) return text;
|
|
36668
37403
|
let open = "";
|
|
36669
37404
|
let close = "";
|
|
36670
|
-
for (const
|
|
36671
|
-
if (
|
|
36672
|
-
const href =
|
|
37405
|
+
for (const mark2 of marks) {
|
|
37406
|
+
if (mark2.type === "link") {
|
|
37407
|
+
const href = mark2.attrs?.href ?? "";
|
|
36673
37408
|
open += `<a href="${this.escapeAttr(href)}">`;
|
|
36674
37409
|
close = `</a>${close}`;
|
|
36675
37410
|
} else {
|
|
36676
|
-
const tag = MARK_TO_TAG[
|
|
37411
|
+
const tag = MARK_TO_TAG[mark2.type];
|
|
36677
37412
|
if (tag) {
|
|
36678
37413
|
open += `<${tag}>`;
|
|
36679
37414
|
close = `</${tag}>${close}`;
|
|
@@ -36737,37 +37472,7 @@ var HtmlTableGenerator = class {
|
|
|
36737
37472
|
return `<img ${parts.join(" ")}>`;
|
|
36738
37473
|
}
|
|
36739
37474
|
textToHtml(text) {
|
|
36740
|
-
|
|
36741
|
-
let lastIndex = 0;
|
|
36742
|
-
for (const match of text.matchAll(INLINE_IMAGE_RE)) {
|
|
36743
|
-
const index = match.index ?? 0;
|
|
36744
|
-
html += this.escapeText(text.slice(lastIndex, index));
|
|
36745
|
-
html += this.inlineImageTokenToHtml(match);
|
|
36746
|
-
lastIndex = index + match[0].length;
|
|
36747
|
-
}
|
|
36748
|
-
html += this.escapeText(text.slice(lastIndex));
|
|
36749
|
-
return html;
|
|
36750
|
-
}
|
|
36751
|
-
inlineImageTokenToHtml(match) {
|
|
36752
|
-
const attrs = {
|
|
36753
|
-
alt: match[1],
|
|
36754
|
-
src: match[2]
|
|
36755
|
-
};
|
|
36756
|
-
const rawAttrs = match[3] ?? "";
|
|
36757
|
-
for (const attr of rawAttrs.split("|")) {
|
|
36758
|
-
if (!attr || attr.startsWith("#")) continue;
|
|
36759
|
-
const colon = attr.indexOf(":");
|
|
36760
|
-
if (colon < 1) continue;
|
|
36761
|
-
const key = attr.slice(0, colon).replace(/^@/, "");
|
|
36762
|
-
const value = attr.slice(colon + 1);
|
|
36763
|
-
if (key === "width" || key === "height") {
|
|
36764
|
-
const n = Number.parseInt(value, 10);
|
|
36765
|
-
if (!Number.isNaN(n) && n > 0 && n <= MAX_IMAGE_DIMENSION) attrs[key] = n;
|
|
36766
|
-
} else if (key === "class" || key === "title") {
|
|
36767
|
-
attrs[key] = value;
|
|
36768
|
-
}
|
|
36769
|
-
}
|
|
36770
|
-
return this.imageToHtml({ type: "imageInline", attrs });
|
|
37475
|
+
return this.escapeText(text);
|
|
36771
37476
|
}
|
|
36772
37477
|
// --- formulas -------------------------------------------------------------
|
|
36773
37478
|
latexToHtml(node) {
|
|
@@ -41251,13 +41956,13 @@ function markChainContentProcessor(context, contentDepth, tagsConfig, content, t
|
|
|
41251
41956
|
if (contentDepth === ContentDepth.Chain) {
|
|
41252
41957
|
markTagContentProcessor(context, ContentDepth.Chain, content, target);
|
|
41253
41958
|
} else {
|
|
41254
|
-
const
|
|
41959
|
+
const mark2 = buildMark(
|
|
41255
41960
|
context,
|
|
41256
41961
|
contentDepth,
|
|
41257
41962
|
tagsConfig,
|
|
41258
41963
|
content
|
|
41259
41964
|
);
|
|
41260
|
-
if (
|
|
41965
|
+
if (mark2) bodyParts.push(mark2);
|
|
41261
41966
|
}
|
|
41262
41967
|
}
|
|
41263
41968
|
function buildMark(context, _contentDepth, tagsConfig, content) {
|
|
@@ -41272,13 +41977,13 @@ function buildMark(context, _contentDepth, tagsConfig, content) {
|
|
|
41272
41977
|
if (context.DEBUG_CHAIN_TAGS) context.debugPrint("mark TAGS", chainTags);
|
|
41273
41978
|
const { solution } = tags2;
|
|
41274
41979
|
const { mark: markType, ...rest } = chainTags;
|
|
41275
|
-
const
|
|
41980
|
+
const mark2 = {
|
|
41276
41981
|
type: BodyBitType.mark,
|
|
41277
41982
|
solution: solution ?? "",
|
|
41278
41983
|
mark: instance4.asSingle(markType) ?? "",
|
|
41279
41984
|
...rest
|
|
41280
41985
|
};
|
|
41281
|
-
return
|
|
41986
|
+
return mark2;
|
|
41282
41987
|
}
|
|
41283
41988
|
|
|
41284
41989
|
// src/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.ts
|
|
@@ -41530,7 +42235,7 @@ function markConfigChainContentProcessor(context, _contentDepth, tagsConfig, con
|
|
|
41530
42235
|
content.chain
|
|
41531
42236
|
);
|
|
41532
42237
|
if (context.DEBUG_CHAIN_TAGS) context.debugPrint("mark TAGS", tags2);
|
|
41533
|
-
const
|
|
42238
|
+
const mark2 = instance3.unbreakscape(
|
|
41534
42239
|
stringUtils.trimmedString(content.value) ?? "unknown",
|
|
41535
42240
|
{
|
|
41536
42241
|
format: TextFormat2.bitmarkText,
|
|
@@ -41538,7 +42243,7 @@ function markConfigChainContentProcessor(context, _contentDepth, tagsConfig, con
|
|
|
41538
42243
|
}
|
|
41539
42244
|
);
|
|
41540
42245
|
const config = {
|
|
41541
|
-
mark,
|
|
42246
|
+
mark: mark2,
|
|
41542
42247
|
emphasis: "underline",
|
|
41543
42248
|
...tags2
|
|
41544
42249
|
};
|
|
@@ -42006,15 +42711,23 @@ function titleTagContentProcessor(context, _contentDepth, _tagsConfig, content,
|
|
|
42006
42711
|
titleString: titleText ?? ""
|
|
42007
42712
|
};
|
|
42008
42713
|
}
|
|
42009
|
-
|
|
42714
|
+
var H_TITLE_LEVEL_MAX = 7;
|
|
42715
|
+
function buildTitles(context, bitType, title) {
|
|
42010
42716
|
title = title ?? [];
|
|
42011
|
-
if (instance2.isOfBitType(bitType, BitType2.chapter)) {
|
|
42717
|
+
if (instance2.isOfBitType(bitType, [BitType2.chapter, BitType2.h])) {
|
|
42012
42718
|
let t;
|
|
42013
42719
|
if (title.length > 0) t = title[title.length - 1];
|
|
42720
|
+
let level = title.length > 0 ? title.length - 1 : void 0;
|
|
42721
|
+
if (level != null && level > H_TITLE_LEVEL_MAX && instance2.isOfBitType(bitType, BitType2.h)) {
|
|
42722
|
+
context.addWarning(
|
|
42723
|
+
`Title level of ${level} too high, setting to max value of ${H_TITLE_LEVEL_MAX}`
|
|
42724
|
+
);
|
|
42725
|
+
level = H_TITLE_LEVEL_MAX;
|
|
42726
|
+
}
|
|
42014
42727
|
return {
|
|
42015
42728
|
title: t?.titleAst ?? [],
|
|
42016
42729
|
titleString: t?.titleString ?? "",
|
|
42017
|
-
level
|
|
42730
|
+
level
|
|
42018
42731
|
};
|
|
42019
42732
|
} else {
|
|
42020
42733
|
if (Array.isArray(title)) {
|