@gmb/bitmark-parser-generator 5.14.0 → 5.16.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 +1669 -1446
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +51 -2
- package/dist/browser/esm/index.d.ts +51 -2
- package/dist/browser/esm/index.js +1668 -1446
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/cli/main.js +523 -6
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +488 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -2
- package/dist/index.d.ts +51 -2
- package/dist/index.js +487 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
package/dist/index.js
CHANGED
|
@@ -1211,6 +1211,7 @@ var propertyKeys = {
|
|
|
1211
1211
|
property_availableClassifications: "@availableClassifications",
|
|
1212
1212
|
property_brandColor: "@brandColor",
|
|
1213
1213
|
property_brandColorName: "@brandColorName",
|
|
1214
|
+
property_backgroundImage: "@backgroundImage",
|
|
1214
1215
|
property_blockId: "@blockId",
|
|
1215
1216
|
property_book: "@book",
|
|
1216
1217
|
property_bookAlias: "@bookAlias",
|
|
@@ -1507,7 +1508,8 @@ var resourceKeys = {
|
|
|
1507
1508
|
resource_imagePlaceholder: "&imagePlaceholder",
|
|
1508
1509
|
resource_previewImage: "&previewImage",
|
|
1509
1510
|
resource_previewVideo: "&previewVideo",
|
|
1510
|
-
resource_coverImage: "&coverImage"
|
|
1511
|
+
resource_coverImage: "&coverImage",
|
|
1512
|
+
resource_backgroundImage: "&backgroundImage"
|
|
1511
1513
|
};
|
|
1512
1514
|
|
|
1513
1515
|
// src/model/enum/ResourceType.ts
|
|
@@ -1737,7 +1739,8 @@ var ResourceType = {
|
|
|
1737
1739
|
platformBackgroundImage: "platformBackgroundImage",
|
|
1738
1740
|
previewImage: "previewImage",
|
|
1739
1741
|
previewVideo: "previewVideo",
|
|
1740
|
-
coverImage: "coverImage"
|
|
1742
|
+
coverImage: "coverImage",
|
|
1743
|
+
backgroundImage: "backgroundImage"
|
|
1741
1744
|
};
|
|
1742
1745
|
function resourceTypeToConfigKey(type) {
|
|
1743
1746
|
return `&${stringUtils.kebabToCamel(type)}`;
|
|
@@ -3779,6 +3782,22 @@ var GROUPS = {
|
|
|
3779
3782
|
}
|
|
3780
3783
|
]
|
|
3781
3784
|
},
|
|
3785
|
+
{
|
|
3786
|
+
key: ConfigKey.property_backgroundImage,
|
|
3787
|
+
description: "The background image(s) of the book",
|
|
3788
|
+
format: TagFormat.plainText,
|
|
3789
|
+
maxCount: Count.infinity
|
|
3790
|
+
},
|
|
3791
|
+
{
|
|
3792
|
+
key: ConfigKey.resource_backgroundImage,
|
|
3793
|
+
description: "The background image of the book",
|
|
3794
|
+
chain: [
|
|
3795
|
+
{
|
|
3796
|
+
key: ConfigKey.group_resourceImageCommon,
|
|
3797
|
+
description: "Common image properties for the background image resource"
|
|
3798
|
+
}
|
|
3799
|
+
]
|
|
3800
|
+
},
|
|
3782
3801
|
{
|
|
3783
3802
|
key: ConfigKey.property_coverColor,
|
|
3784
3803
|
description: "The cover color of the book",
|
|
@@ -10901,7 +10920,7 @@ var instance2 = new Config();
|
|
|
10901
10920
|
// src/generated/package_info.ts
|
|
10902
10921
|
var PACKAGE_INFO = {
|
|
10903
10922
|
"name": "@gmb/bitmark-parser-generator",
|
|
10904
|
-
"version": "5.
|
|
10923
|
+
"version": "5.16.0",
|
|
10905
10924
|
"author": "Get More Brain Ltd",
|
|
10906
10925
|
"license": "ISC",
|
|
10907
10926
|
"description": "A bitmark parser and generator using Peggy.js"
|
|
@@ -11291,6 +11310,8 @@ var NodeType = {
|
|
|
11291
11310
|
avatarImage: "avatarImage",
|
|
11292
11311
|
backgroundWallpaper: "backgroundWallpaper",
|
|
11293
11312
|
backgroundWallpaperValue: "backgroundWallpaperValue",
|
|
11313
|
+
backgroundImage: "backgroundImage",
|
|
11314
|
+
backgroundImageValue: "backgroundImageValue",
|
|
11294
11315
|
bitLevel: "bitLevel",
|
|
11295
11316
|
// bit level
|
|
11296
11317
|
bitmarkAst: "bitmarkAst",
|
|
@@ -23595,6 +23616,7 @@ var ResourceBuilder = class extends BaseBuilder {
|
|
|
23595
23616
|
case ResourceType.platformBackgroundImage:
|
|
23596
23617
|
case ResourceType.previewImage:
|
|
23597
23618
|
case ResourceType.coverImage:
|
|
23619
|
+
case ResourceType.backgroundImage:
|
|
23598
23620
|
node = this.imageResource(context, finalData, type);
|
|
23599
23621
|
break;
|
|
23600
23622
|
// case ResourceType.imageResponsive: {
|
|
@@ -24874,6 +24896,12 @@ var Builder = class extends BaseBuilder {
|
|
|
24874
24896
|
data.coverColor,
|
|
24875
24897
|
options
|
|
24876
24898
|
),
|
|
24899
|
+
backgroundImage: typeof data.backgroundImage === "string" || Array.isArray(data.backgroundImage) ? this.toAstProperty(
|
|
24900
|
+
bitType,
|
|
24901
|
+
ConfigKey.property_backgroundImage,
|
|
24902
|
+
instance4.asArray(data.backgroundImage),
|
|
24903
|
+
options
|
|
24904
|
+
) : this.toImageResource(context, data.backgroundImage),
|
|
24877
24905
|
publications: this.toAstProperty(
|
|
24878
24906
|
bitType,
|
|
24879
24907
|
ConfigKey.property_publications,
|
|
@@ -28947,6 +28975,62 @@ var BitmarkGenerator = class extends AstWalkerGenerator {
|
|
|
28947
28975
|
ignoreTrue: propertyConfig.defaultValue === "true"
|
|
28948
28976
|
});
|
|
28949
28977
|
}
|
|
28978
|
+
// bitmarkAst -> bits -> bitsValue -> backgroundImage (when it's a resource object or property array)
|
|
28979
|
+
enter_backgroundImage(node, route) {
|
|
28980
|
+
const value = node.value;
|
|
28981
|
+
if (value && typeof value === "object" && !Array.isArray(value) && "type" in value) {
|
|
28982
|
+
const resource = value;
|
|
28983
|
+
this.writeNL();
|
|
28984
|
+
this.writePropertyStyleResource(node.key, resource);
|
|
28985
|
+
return true;
|
|
28986
|
+
}
|
|
28987
|
+
if (Array.isArray(value)) {
|
|
28988
|
+
if (value == null) return true;
|
|
28989
|
+
const parent = this.getParentNode(route);
|
|
28990
|
+
if (parent?.key !== NodeType.bitsValue) return true;
|
|
28991
|
+
const bitType = this.getBitType(route);
|
|
28992
|
+
if (!bitType) return true;
|
|
28993
|
+
const config = instance2.getBitConfig(bitType);
|
|
28994
|
+
const propertyConfig = instance2.getTagConfigForTag(
|
|
28995
|
+
config.tags,
|
|
28996
|
+
ConfigKey.property_backgroundImage
|
|
28997
|
+
);
|
|
28998
|
+
if (!propertyConfig) return true;
|
|
28999
|
+
this.writeNL_IfNotChain(route);
|
|
29000
|
+
this.writeProperty(propertyConfig.tag, value, route, {
|
|
29001
|
+
format: propertyConfig.format ?? TagFormat.plainText,
|
|
29002
|
+
array: propertyConfig.array ?? false,
|
|
29003
|
+
writeEmpty: true,
|
|
29004
|
+
ignoreFalse: propertyConfig.defaultValue === "false",
|
|
29005
|
+
ignoreTrue: propertyConfig.defaultValue === "true"
|
|
29006
|
+
});
|
|
29007
|
+
}
|
|
29008
|
+
return true;
|
|
29009
|
+
}
|
|
29010
|
+
// bitmarkAst -> bits -> bitsValue -> backgroundImage (when it's a property string)
|
|
29011
|
+
// This is called when backgroundImage is a simple string value
|
|
29012
|
+
leaf_backgroundImage(node, route) {
|
|
29013
|
+
const value = node.value;
|
|
29014
|
+
if (value == null) return;
|
|
29015
|
+
const parent = this.getParentNode(route);
|
|
29016
|
+
if (parent?.key !== NodeType.bitsValue) return;
|
|
29017
|
+
const bitType = this.getBitType(route);
|
|
29018
|
+
if (!bitType) return;
|
|
29019
|
+
const config = instance2.getBitConfig(bitType);
|
|
29020
|
+
const propertyConfig = instance2.getTagConfigForTag(
|
|
29021
|
+
config.tags,
|
|
29022
|
+
ConfigKey.property_backgroundImage
|
|
29023
|
+
);
|
|
29024
|
+
if (!propertyConfig) return;
|
|
29025
|
+
this.writeNL_IfNotChain(route);
|
|
29026
|
+
this.writeProperty(propertyConfig.tag, node.value, route, {
|
|
29027
|
+
format: propertyConfig.format ?? TagFormat.plainText,
|
|
29028
|
+
array: propertyConfig.array ?? false,
|
|
29029
|
+
writeEmpty: true,
|
|
29030
|
+
ignoreFalse: propertyConfig.defaultValue === "false",
|
|
29031
|
+
ignoreTrue: propertyConfig.defaultValue === "true"
|
|
29032
|
+
});
|
|
29033
|
+
}
|
|
28950
29034
|
exit_imagePlaceholder(_node, _route) {
|
|
28951
29035
|
}
|
|
28952
29036
|
// bitmarkAst -> bits -> bitsValue -> posterImage
|
|
@@ -30560,6 +30644,12 @@ var JsonGenerator = class extends AstWalkerGenerator {
|
|
|
30560
30644
|
array: Array.isArray(node.value)
|
|
30561
30645
|
});
|
|
30562
30646
|
}
|
|
30647
|
+
// bitmarkAst -> bits -> bitsValue -> backgroundImage
|
|
30648
|
+
enter_backgroundImage(node, route) {
|
|
30649
|
+
return this.standardHandler(node, route, NodeType.bitsValue, {
|
|
30650
|
+
array: Array.isArray(node.value)
|
|
30651
|
+
});
|
|
30652
|
+
}
|
|
30563
30653
|
// bitmarkAst -> bits -> bitsValue -> resources
|
|
30564
30654
|
enter_resources(node, route) {
|
|
30565
30655
|
const resources = node.value;
|
|
@@ -35028,7 +35118,7 @@ function resourceContentProcessor(context, _contentDepth, tagsConfig, content, t
|
|
|
35028
35118
|
...tags2
|
|
35029
35119
|
});
|
|
35030
35120
|
if (resource) {
|
|
35031
|
-
if (configKey === ConfigKey.resource_backgroundWallpaper || configKey === ConfigKey.resource_imagePlaceholder || configKey === ConfigKey.resource_platformIcon || configKey === ConfigKey.resource_platformLogo || configKey === ConfigKey.resource_platformBackgroundImage || configKey === ConfigKey.resource_previewImage || configKey === ConfigKey.resource_previewVideo || configKey === ConfigKey.resource_coverImage) {
|
|
35121
|
+
if (configKey === ConfigKey.resource_backgroundWallpaper || configKey === ConfigKey.resource_imagePlaceholder || configKey === ConfigKey.resource_platformIcon || configKey === ConfigKey.resource_platformLogo || configKey === ConfigKey.resource_platformBackgroundImage || configKey === ConfigKey.resource_previewImage || configKey === ConfigKey.resource_previewVideo || configKey === ConfigKey.resource_coverImage || configKey === ConfigKey.resource_backgroundImage) {
|
|
35032
35122
|
if (target.propertyStyleResources) {
|
|
35033
35123
|
if (target.propertyStyleResources[resourceType]) {
|
|
35034
35124
|
if (!Array.isArray(target.propertyStyleResources[resourceType])) {
|
|
@@ -39653,6 +39743,265 @@ var JsonFileGenerator = class {
|
|
|
39653
39743
|
}
|
|
39654
39744
|
};
|
|
39655
39745
|
|
|
39746
|
+
// src/generator/plainText/PlainTextGenerator.ts
|
|
39747
|
+
var TEXT_NODE_TYPES = new Set(Object.values(TextNodeType));
|
|
39748
|
+
var PlainTextGenerator = class {
|
|
39749
|
+
/**
|
|
39750
|
+
* Generate plain text from a string or JSON object.
|
|
39751
|
+
*
|
|
39752
|
+
* @param input - A string (plain or JSON-encoded) or a parsed JSON value.
|
|
39753
|
+
* @returns The extracted plain text.
|
|
39754
|
+
*/
|
|
39755
|
+
generate(input) {
|
|
39756
|
+
let data = input;
|
|
39757
|
+
if (typeof data === "string") {
|
|
39758
|
+
try {
|
|
39759
|
+
data = JSON.parse(data);
|
|
39760
|
+
} catch (_e) {
|
|
39761
|
+
return data;
|
|
39762
|
+
}
|
|
39763
|
+
}
|
|
39764
|
+
return this.walk(data).trim();
|
|
39765
|
+
}
|
|
39766
|
+
// ---------------------------------------------------------------------------
|
|
39767
|
+
// Private helpers
|
|
39768
|
+
// ---------------------------------------------------------------------------
|
|
39769
|
+
walk(value) {
|
|
39770
|
+
if (value == null) return "";
|
|
39771
|
+
if (typeof value === "string") return value;
|
|
39772
|
+
if (typeof value !== "object") return "";
|
|
39773
|
+
if (Array.isArray(value)) {
|
|
39774
|
+
if (value.length === 0) return "";
|
|
39775
|
+
if (this.isTextAst(value)) {
|
|
39776
|
+
return this.textAstToPlainText(value);
|
|
39777
|
+
}
|
|
39778
|
+
return value.map((v) => this.walk(v)).filter(Boolean).join("\n");
|
|
39779
|
+
}
|
|
39780
|
+
const obj = value;
|
|
39781
|
+
if (this.isTextNode(obj)) {
|
|
39782
|
+
return this.textNodeToPlainText(obj);
|
|
39783
|
+
}
|
|
39784
|
+
if (this.isBitWrapper(obj)) {
|
|
39785
|
+
return this.walk(obj["bit"]);
|
|
39786
|
+
}
|
|
39787
|
+
const parts = [];
|
|
39788
|
+
for (const val of Object.values(obj)) {
|
|
39789
|
+
if (val == null || typeof val !== "object") continue;
|
|
39790
|
+
const text = this.walk(val);
|
|
39791
|
+
if (text) parts.push(text);
|
|
39792
|
+
}
|
|
39793
|
+
return parts.join("\n");
|
|
39794
|
+
}
|
|
39795
|
+
// -- Type guards -----------------------------------------------------------
|
|
39796
|
+
isTextNode(obj) {
|
|
39797
|
+
return typeof obj["type"] === "string" && TEXT_NODE_TYPES.has(obj["type"]);
|
|
39798
|
+
}
|
|
39799
|
+
isTextAst(arr) {
|
|
39800
|
+
const first = arr[0];
|
|
39801
|
+
return typeof first === "object" && first !== null && !Array.isArray(first) && this.isTextNode(first);
|
|
39802
|
+
}
|
|
39803
|
+
isBitWrapper(obj) {
|
|
39804
|
+
return "bit" in obj && typeof obj["bit"] === "object" && obj["bit"] !== null && !Array.isArray(obj["bit"]);
|
|
39805
|
+
}
|
|
39806
|
+
// -- TextNode extraction ---------------------------------------------------
|
|
39807
|
+
textAstToPlainText(ast) {
|
|
39808
|
+
return ast.map((node) => this.textNodeToPlainText(node)).join("\n");
|
|
39809
|
+
}
|
|
39810
|
+
textNodeToPlainText(node) {
|
|
39811
|
+
const { type, text, content } = node;
|
|
39812
|
+
switch (type) {
|
|
39813
|
+
case TextNodeType.text:
|
|
39814
|
+
return this.textWithMarks(node);
|
|
39815
|
+
case TextNodeType.hardBreak:
|
|
39816
|
+
return "\n";
|
|
39817
|
+
// Block elements whose children are joined without extra separator
|
|
39818
|
+
case TextNodeType.paragraph:
|
|
39819
|
+
case TextNodeType.heading:
|
|
39820
|
+
case TextNodeType.section:
|
|
39821
|
+
case TextNodeType.gap:
|
|
39822
|
+
case TextNodeType.select:
|
|
39823
|
+
case TextNodeType.highlight:
|
|
39824
|
+
case TextNodeType.mark:
|
|
39825
|
+
case TextNodeType.codeBlock:
|
|
39826
|
+
return content ? content.map((c) => this.textNodeToPlainText(c)).join("") : text ?? "";
|
|
39827
|
+
// List items are handled by listToPlainText with indent context
|
|
39828
|
+
case TextNodeType.listItem:
|
|
39829
|
+
return content ? content.map((c) => this.textNodeToPlainText(c)).join("") : text ?? "";
|
|
39830
|
+
// Task item – handled by taskListToPlainText, but fallback if encountered standalone
|
|
39831
|
+
case TextNodeType.taskItem: {
|
|
39832
|
+
const checked = node.attrs?.checked ?? false;
|
|
39833
|
+
const prefix = checked ? "[x] " : "[ ] ";
|
|
39834
|
+
const itemText = content ? content.map((c) => this.textNodeToPlainText(c)).join("") : text ?? "";
|
|
39835
|
+
return `${prefix}${itemText}`;
|
|
39836
|
+
}
|
|
39837
|
+
// List containers – rendered with indent-aware helper
|
|
39838
|
+
case TextNodeType.noBulletList:
|
|
39839
|
+
case TextNodeType.bulletList:
|
|
39840
|
+
case TextNodeType.orderedList:
|
|
39841
|
+
case TextNodeType.orderedListRoman:
|
|
39842
|
+
case TextNodeType.orderedListRomanLower:
|
|
39843
|
+
case TextNodeType.letteredList:
|
|
39844
|
+
case TextNodeType.letteredListLower:
|
|
39845
|
+
return this.listToPlainText(node, 0);
|
|
39846
|
+
// Task list – rendered with indent-aware helper
|
|
39847
|
+
case TextNodeType.taskList:
|
|
39848
|
+
return this.taskListToPlainText(node, 0);
|
|
39849
|
+
// Images – return alt text when available
|
|
39850
|
+
case TextNodeType.image:
|
|
39851
|
+
case TextNodeType.imageInline: {
|
|
39852
|
+
const attrs = node.attrs;
|
|
39853
|
+
return attrs?.alt ?? "";
|
|
39854
|
+
}
|
|
39855
|
+
// LaTeX – return the formula source
|
|
39856
|
+
case TextNodeType.latex: {
|
|
39857
|
+
const latexAttrs = node.attrs;
|
|
39858
|
+
return latexAttrs?.formula ?? "";
|
|
39859
|
+
}
|
|
39860
|
+
default:
|
|
39861
|
+
return content ? content.map((c) => this.textNodeToPlainText(c)).join("") : text ?? "";
|
|
39862
|
+
}
|
|
39863
|
+
}
|
|
39864
|
+
listToPlainText(node, depth) {
|
|
39865
|
+
const { type, content } = node;
|
|
39866
|
+
if (!content || content.length === 0) return "";
|
|
39867
|
+
const indent = " ".repeat(depth);
|
|
39868
|
+
const start = node.attrs?.start ?? 1;
|
|
39869
|
+
const displayStart = start < 1 ? start + 1 : start;
|
|
39870
|
+
return content.map((child, i) => {
|
|
39871
|
+
const { inline, nested } = this.splitListItemContent(child, depth);
|
|
39872
|
+
const prefix = this.listItemPrefix(type, displayStart + i);
|
|
39873
|
+
const line = `${indent}${prefix}${inline}`;
|
|
39874
|
+
return nested ? `${line}
|
|
39875
|
+
${nested}` : line;
|
|
39876
|
+
}).join("\n");
|
|
39877
|
+
}
|
|
39878
|
+
taskListToPlainText(node, depth) {
|
|
39879
|
+
const { content } = node;
|
|
39880
|
+
if (!content || content.length === 0) return "";
|
|
39881
|
+
const indent = " ".repeat(depth);
|
|
39882
|
+
return content.map((child) => {
|
|
39883
|
+
const checked = child.attrs?.checked ?? false;
|
|
39884
|
+
const prefix = checked ? "[x] " : "[ ] ";
|
|
39885
|
+
const { inline, nested } = this.splitListItemContent(child, depth);
|
|
39886
|
+
const line = `${indent}${prefix}${inline}`;
|
|
39887
|
+
return nested ? `${line}
|
|
39888
|
+
${nested}` : line;
|
|
39889
|
+
}).join("\n");
|
|
39890
|
+
}
|
|
39891
|
+
splitListItemContent(item, depth) {
|
|
39892
|
+
const children = item.content ?? [];
|
|
39893
|
+
const inlineParts = [];
|
|
39894
|
+
const nestedParts = [];
|
|
39895
|
+
for (const child of children) {
|
|
39896
|
+
if (this.isListType(child.type)) {
|
|
39897
|
+
nestedParts.push(this.renderNestedList(child, depth + 1));
|
|
39898
|
+
} else {
|
|
39899
|
+
inlineParts.push(this.textNodeToPlainText(child));
|
|
39900
|
+
}
|
|
39901
|
+
}
|
|
39902
|
+
return {
|
|
39903
|
+
inline: inlineParts.join(""),
|
|
39904
|
+
nested: nestedParts.join("\n")
|
|
39905
|
+
};
|
|
39906
|
+
}
|
|
39907
|
+
isListType(type) {
|
|
39908
|
+
return type === TextNodeType.bulletList || type === TextNodeType.orderedList || type === TextNodeType.orderedListRoman || type === TextNodeType.orderedListRomanLower || type === TextNodeType.letteredList || type === TextNodeType.letteredListLower || type === TextNodeType.noBulletList || type === TextNodeType.taskList;
|
|
39909
|
+
}
|
|
39910
|
+
renderNestedList(node, depth) {
|
|
39911
|
+
if (node.type === TextNodeType.taskList) {
|
|
39912
|
+
return this.taskListToPlainText(node, depth);
|
|
39913
|
+
}
|
|
39914
|
+
return this.listToPlainText(node, depth);
|
|
39915
|
+
}
|
|
39916
|
+
listItemPrefix(listType, index) {
|
|
39917
|
+
switch (listType) {
|
|
39918
|
+
case TextNodeType.bulletList:
|
|
39919
|
+
return "\u2022 ";
|
|
39920
|
+
case TextNodeType.orderedList:
|
|
39921
|
+
return `${index}. `;
|
|
39922
|
+
case TextNodeType.orderedListRoman:
|
|
39923
|
+
return `${this.toRoman(index)}. `;
|
|
39924
|
+
case TextNodeType.orderedListRomanLower:
|
|
39925
|
+
return `${this.toRoman(index).toLowerCase()}. `;
|
|
39926
|
+
case TextNodeType.letteredList:
|
|
39927
|
+
return `${this.toLetter(index)}. `;
|
|
39928
|
+
case TextNodeType.letteredListLower:
|
|
39929
|
+
return `${this.toLetter(index).toLowerCase()}. `;
|
|
39930
|
+
case TextNodeType.noBulletList:
|
|
39931
|
+
default:
|
|
39932
|
+
return "";
|
|
39933
|
+
}
|
|
39934
|
+
}
|
|
39935
|
+
toRoman(num) {
|
|
39936
|
+
const romanNumerals = [
|
|
39937
|
+
[1e3, "M"],
|
|
39938
|
+
[900, "CM"],
|
|
39939
|
+
[500, "D"],
|
|
39940
|
+
[400, "CD"],
|
|
39941
|
+
[100, "C"],
|
|
39942
|
+
[90, "XC"],
|
|
39943
|
+
[50, "L"],
|
|
39944
|
+
[40, "XL"],
|
|
39945
|
+
[10, "X"],
|
|
39946
|
+
[9, "IX"],
|
|
39947
|
+
[5, "V"],
|
|
39948
|
+
[4, "IV"],
|
|
39949
|
+
[1, "I"]
|
|
39950
|
+
];
|
|
39951
|
+
let result = "";
|
|
39952
|
+
let remaining = num;
|
|
39953
|
+
for (const [value, numeral] of romanNumerals) {
|
|
39954
|
+
while (remaining >= value) {
|
|
39955
|
+
result += numeral;
|
|
39956
|
+
remaining -= value;
|
|
39957
|
+
}
|
|
39958
|
+
}
|
|
39959
|
+
return result;
|
|
39960
|
+
}
|
|
39961
|
+
toLetter(num) {
|
|
39962
|
+
let result = "";
|
|
39963
|
+
let remaining = num;
|
|
39964
|
+
while (remaining > 0) {
|
|
39965
|
+
remaining--;
|
|
39966
|
+
result = String.fromCharCode(65 + remaining % 26) + result;
|
|
39967
|
+
remaining = Math.floor(remaining / 26);
|
|
39968
|
+
}
|
|
39969
|
+
return result;
|
|
39970
|
+
}
|
|
39971
|
+
textWithMarks(node) {
|
|
39972
|
+
const { text, marks } = node;
|
|
39973
|
+
const parts = [];
|
|
39974
|
+
const linkMark = marks?.find((m) => m.type === "link");
|
|
39975
|
+
const href = linkMark?.attrs?.href;
|
|
39976
|
+
if (text && href && text !== href) {
|
|
39977
|
+
const hrefBare = href.replace(/^https?:\/\//, "");
|
|
39978
|
+
if (text.includes(hrefBare)) {
|
|
39979
|
+
parts.push(text.replace(hrefBare, href));
|
|
39980
|
+
} else if (text.includes(href)) {
|
|
39981
|
+
parts.push(text);
|
|
39982
|
+
} else {
|
|
39983
|
+
parts.push(`${text} ${href}`);
|
|
39984
|
+
}
|
|
39985
|
+
} else if (text) {
|
|
39986
|
+
parts.push(text);
|
|
39987
|
+
} else if (href) {
|
|
39988
|
+
parts.push(href);
|
|
39989
|
+
}
|
|
39990
|
+
if (marks) {
|
|
39991
|
+
for (const mark of marks) {
|
|
39992
|
+
if (mark.type === "footnote") {
|
|
39993
|
+
const footnote = mark;
|
|
39994
|
+
if (footnote.attrs?.content) {
|
|
39995
|
+
const footnoteText = footnote.attrs.content.map((c) => this.textNodeToPlainText(c)).join("");
|
|
39996
|
+
if (footnoteText) parts.push(footnoteText);
|
|
39997
|
+
}
|
|
39998
|
+
}
|
|
39999
|
+
}
|
|
40000
|
+
}
|
|
40001
|
+
return parts.join(" ");
|
|
40002
|
+
}
|
|
40003
|
+
};
|
|
40004
|
+
|
|
39656
40005
|
// src/info/ConfigBuilder.ts
|
|
39657
40006
|
import path3 from "path";
|
|
39658
40007
|
import { Enum as Enum22 } from "@ncoderz/superenum";
|
|
@@ -40362,7 +40711,25 @@ var Output = {
|
|
|
40362
40711
|
/**
|
|
40363
40712
|
* Output AST as a plain JS object, or a file
|
|
40364
40713
|
*/
|
|
40365
|
-
ast: "ast"
|
|
40714
|
+
ast: "ast",
|
|
40715
|
+
/**
|
|
40716
|
+
* Output plain text as a string, or a file
|
|
40717
|
+
*/
|
|
40718
|
+
text: "text"
|
|
40719
|
+
};
|
|
40720
|
+
var InputFormat = {
|
|
40721
|
+
/**
|
|
40722
|
+
* Input is bitmark
|
|
40723
|
+
*/
|
|
40724
|
+
bitmark: "bitmark",
|
|
40725
|
+
/**
|
|
40726
|
+
* Input is bitmarkText
|
|
40727
|
+
*/
|
|
40728
|
+
bitmarkText: "bitmarkText",
|
|
40729
|
+
/**
|
|
40730
|
+
* Input is plain text
|
|
40731
|
+
*/
|
|
40732
|
+
plainText: "plainText"
|
|
40366
40733
|
};
|
|
40367
40734
|
var BitmarkParserGenerator = class {
|
|
40368
40735
|
constructor() {
|
|
@@ -40464,6 +40831,12 @@ var BitmarkParserGenerator = class {
|
|
|
40464
40831
|
* - input(JSON/AST) ==> output(bitmark)
|
|
40465
40832
|
* - input(bitmark) ==> output(JSON)
|
|
40466
40833
|
*
|
|
40834
|
+
* Output type can be overridden to one of the following:
|
|
40835
|
+
* - bitmark: output bitmark string
|
|
40836
|
+
* - json: output JSON as a plain JS object, or a file
|
|
40837
|
+
* - ast: output AST as a plain JS object, or a file
|
|
40838
|
+
* - text: output plain text as a string, or a file
|
|
40839
|
+
*
|
|
40467
40840
|
* By default, the result is returned as a string for bitmark, or a plain JS object for JSON/AST.
|
|
40468
40841
|
*
|
|
40469
40842
|
* The options can be used to write the output to a file and to set conversion options or override defaults.
|
|
@@ -40486,6 +40859,7 @@ var BitmarkParserGenerator = class {
|
|
|
40486
40859
|
const outputBitmark = outputFormat === Output.bitmark;
|
|
40487
40860
|
const outputJson = outputFormat === Output.json;
|
|
40488
40861
|
const outputAst = outputFormat === Output.ast;
|
|
40862
|
+
const outputText = outputFormat === Output.text;
|
|
40489
40863
|
const bitmarkParserType = BitmarkParserType.peggy;
|
|
40490
40864
|
let inStr = input;
|
|
40491
40865
|
const inputIsString = typeof input === "string";
|
|
@@ -40532,6 +40906,22 @@ var BitmarkParserGenerator = class {
|
|
|
40532
40906
|
}
|
|
40533
40907
|
}
|
|
40534
40908
|
};
|
|
40909
|
+
const bitmarkToText = (bitmarkStr) => {
|
|
40910
|
+
ast = this.bitmarkParser.toAst(bitmarkStr, {
|
|
40911
|
+
parserType: bitmarkParserType
|
|
40912
|
+
});
|
|
40913
|
+
const jsonGenerator = new JsonObjectGenerator(opts);
|
|
40914
|
+
const json = jsonGenerator.generateSync(ast);
|
|
40915
|
+
const textGenerator = new PlainTextGenerator();
|
|
40916
|
+
const str = textGenerator.generate(json);
|
|
40917
|
+
if (opts.outputFile) {
|
|
40918
|
+
fs4.writeFileSync(opts.outputFile, str, {
|
|
40919
|
+
encoding: "utf8"
|
|
40920
|
+
});
|
|
40921
|
+
} else {
|
|
40922
|
+
res = str;
|
|
40923
|
+
}
|
|
40924
|
+
};
|
|
40535
40925
|
const astToBitmark = (astJson) => {
|
|
40536
40926
|
if (opts.outputFile) {
|
|
40537
40927
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
@@ -40554,6 +40944,19 @@ var BitmarkParserGenerator = class {
|
|
|
40554
40944
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
40555
40945
|
}
|
|
40556
40946
|
};
|
|
40947
|
+
const astToText = (astJson) => {
|
|
40948
|
+
const jsonGenerator = new JsonObjectGenerator(opts);
|
|
40949
|
+
const json = jsonGenerator.generateSync(astJson);
|
|
40950
|
+
const textGenerator = new PlainTextGenerator();
|
|
40951
|
+
const str = textGenerator.generate(json);
|
|
40952
|
+
if (opts.outputFile) {
|
|
40953
|
+
fs4.writeFileSync(opts.outputFile, str, {
|
|
40954
|
+
encoding: "utf8"
|
|
40955
|
+
});
|
|
40956
|
+
} else {
|
|
40957
|
+
res = str;
|
|
40958
|
+
}
|
|
40959
|
+
};
|
|
40557
40960
|
const jsonToBitmark = (astJson) => {
|
|
40558
40961
|
if (opts.outputFile) {
|
|
40559
40962
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
@@ -40566,6 +40969,19 @@ var BitmarkParserGenerator = class {
|
|
|
40566
40969
|
const jsonToAst = (astJson) => {
|
|
40567
40970
|
res = this.jsonStringifyPrettify(astJson, jsonOptions);
|
|
40568
40971
|
};
|
|
40972
|
+
const jsonToText = (astJson) => {
|
|
40973
|
+
const jsonGenerator = new JsonObjectGenerator(opts);
|
|
40974
|
+
const json = jsonGenerator.generateSync(astJson);
|
|
40975
|
+
const textGenerator = new PlainTextGenerator();
|
|
40976
|
+
const str = textGenerator.generate(json);
|
|
40977
|
+
if (opts.outputFile) {
|
|
40978
|
+
fs4.writeFileSync(opts.outputFile, str, {
|
|
40979
|
+
encoding: "utf8"
|
|
40980
|
+
});
|
|
40981
|
+
} else {
|
|
40982
|
+
res = str;
|
|
40983
|
+
}
|
|
40984
|
+
};
|
|
40569
40985
|
const jsonToJson = (astJson) => {
|
|
40570
40986
|
astToJson(astJson);
|
|
40571
40987
|
};
|
|
@@ -40574,6 +40990,8 @@ var BitmarkParserGenerator = class {
|
|
|
40574
40990
|
bitmarkToBitmark(inStr);
|
|
40575
40991
|
} else if (outputAst) {
|
|
40576
40992
|
bitmarkToAst(inStr);
|
|
40993
|
+
} else if (outputText) {
|
|
40994
|
+
bitmarkToText(inStr);
|
|
40577
40995
|
} else {
|
|
40578
40996
|
bitmarkToJson(inStr);
|
|
40579
40997
|
}
|
|
@@ -40583,6 +41001,8 @@ var BitmarkParserGenerator = class {
|
|
|
40583
41001
|
astToAst(ast);
|
|
40584
41002
|
} else if (outputJson) {
|
|
40585
41003
|
astToJson(ast);
|
|
41004
|
+
} else if (outputText) {
|
|
41005
|
+
astToText(ast);
|
|
40586
41006
|
} else {
|
|
40587
41007
|
astToBitmark(ast);
|
|
40588
41008
|
}
|
|
@@ -40592,6 +41012,8 @@ var BitmarkParserGenerator = class {
|
|
|
40592
41012
|
jsonToJson(ast);
|
|
40593
41013
|
} else if (outputAst) {
|
|
40594
41014
|
jsonToAst(ast);
|
|
41015
|
+
} else if (outputText) {
|
|
41016
|
+
jsonToText(ast);
|
|
40595
41017
|
} else {
|
|
40596
41018
|
jsonToBitmark(ast);
|
|
40597
41019
|
}
|
|
@@ -40720,7 +41142,7 @@ var BitmarkParserGenerator = class {
|
|
|
40720
41142
|
return res;
|
|
40721
41143
|
}
|
|
40722
41144
|
/**
|
|
40723
|
-
* Convert bitmark text
|
|
41145
|
+
* Convert bitmark text to JSON, or JSON to bitmark text.
|
|
40724
41146
|
*
|
|
40725
41147
|
* Input type is detected automatically and may be:
|
|
40726
41148
|
* - string: bitmark text or JSON
|
|
@@ -40794,6 +41216,54 @@ var BitmarkParserGenerator = class {
|
|
|
40794
41216
|
}
|
|
40795
41217
|
return res;
|
|
40796
41218
|
}
|
|
41219
|
+
extractPlainText(input, options) {
|
|
41220
|
+
const dataIn = input;
|
|
41221
|
+
const inputFormat = options?.inputFormat;
|
|
41222
|
+
const isString2 = typeof input === "string";
|
|
41223
|
+
let data;
|
|
41224
|
+
const parseAutomatically = () => {
|
|
41225
|
+
let dataOut = dataIn;
|
|
41226
|
+
if (typeof dataIn === "string") {
|
|
41227
|
+
try {
|
|
41228
|
+
dataOut = JSON.parse(dataIn);
|
|
41229
|
+
} catch (_e) {
|
|
41230
|
+
let isBitmark = false;
|
|
41231
|
+
const bitmarkData = this.convert(dataIn, {
|
|
41232
|
+
outputFormat: Output.json
|
|
41233
|
+
});
|
|
41234
|
+
if (bitmarkData.length > 0) {
|
|
41235
|
+
const isError = bitmarkData[0].bit.type === BitType._error;
|
|
41236
|
+
if (!isError) {
|
|
41237
|
+
isBitmark = true;
|
|
41238
|
+
dataOut = bitmarkData;
|
|
41239
|
+
}
|
|
41240
|
+
}
|
|
41241
|
+
if (!isBitmark) {
|
|
41242
|
+
dataOut = this.convertText(dataIn, {
|
|
41243
|
+
textFormat: TextFormat.bitmarkText
|
|
41244
|
+
});
|
|
41245
|
+
}
|
|
41246
|
+
}
|
|
41247
|
+
}
|
|
41248
|
+
return dataOut;
|
|
41249
|
+
};
|
|
41250
|
+
if (inputFormat === InputFormat.bitmark) {
|
|
41251
|
+
data = this.convert(dataIn, {
|
|
41252
|
+
outputFormat: Output.json
|
|
41253
|
+
});
|
|
41254
|
+
} else if (inputFormat === InputFormat.bitmarkText) {
|
|
41255
|
+
data = this.convertText(dataIn, {
|
|
41256
|
+
textFormat: TextFormat.bitmarkText
|
|
41257
|
+
});
|
|
41258
|
+
} else if (inputFormat === InputFormat.plainText) {
|
|
41259
|
+
if (isString2) data = String(input);
|
|
41260
|
+
} else {
|
|
41261
|
+
data = parseAutomatically();
|
|
41262
|
+
}
|
|
41263
|
+
const generator = new PlainTextGenerator();
|
|
41264
|
+
const res = generator.generate(data);
|
|
41265
|
+
return res;
|
|
41266
|
+
}
|
|
40797
41267
|
/**
|
|
40798
41268
|
* Breakscape bitmark text.
|
|
40799
41269
|
*
|
|
@@ -40901,6 +41371,16 @@ var BitmarkParserGenerator = class {
|
|
|
40901
41371
|
}
|
|
40902
41372
|
return;
|
|
40903
41373
|
}
|
|
41374
|
+
textAstToPlainText(textAst, _options) {
|
|
41375
|
+
const textGenerator = new TextGenerator(BitmarkVersion.v3, {
|
|
41376
|
+
//
|
|
41377
|
+
});
|
|
41378
|
+
const res = textGenerator.generateSync(textAst, TextFormat.bitmarkText, TextLocation.body, {
|
|
41379
|
+
noBreakscaping: true,
|
|
41380
|
+
noMarkup: true
|
|
41381
|
+
});
|
|
41382
|
+
return res;
|
|
41383
|
+
}
|
|
40904
41384
|
/**
|
|
40905
41385
|
* Get the supported bits as a formatted strings
|
|
40906
41386
|
*
|
|
@@ -40970,6 +41450,7 @@ export {
|
|
|
40970
41450
|
InfoFormat,
|
|
40971
41451
|
InfoType,
|
|
40972
41452
|
Input,
|
|
41453
|
+
InputFormat,
|
|
40973
41454
|
JsonFileGenerator,
|
|
40974
41455
|
JsonGenerator,
|
|
40975
41456
|
JsonParser,
|