textlint-plugin-typst 1.0.0 → 1.0.1
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/README.md +17 -0
- package/lib/index.js +147 -74
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -40,6 +40,8 @@ bun add textlint-plugin-typst
|
|
|
40
40
|
|
|
41
41
|
## Syntax support
|
|
42
42
|
|
|
43
|
+
This plugin supports the syntax of Typst [v0.11.1](https://github.com/typst/typst/releases/tag/v0.11.1).
|
|
44
|
+
|
|
43
45
|
Legend for syntax support:
|
|
44
46
|
|
|
45
47
|
- ✅: Supported
|
|
@@ -87,6 +89,21 @@ Disables all rules between comments
|
|
|
87
89
|
This is error text.
|
|
88
90
|
```
|
|
89
91
|
|
|
92
|
+
Also, you can use single-line comments.
|
|
93
|
+
|
|
94
|
+
```typst
|
|
95
|
+
This is error text.
|
|
96
|
+
|
|
97
|
+
// textlint-disable
|
|
98
|
+
|
|
99
|
+
This is ignored text by rule.
|
|
100
|
+
Disables all rules between comments
|
|
101
|
+
|
|
102
|
+
// textlint-enable
|
|
103
|
+
|
|
104
|
+
This is error text.
|
|
105
|
+
```
|
|
106
|
+
|
|
90
107
|
## Contributing
|
|
91
108
|
|
|
92
109
|
This project is still under development, so please feel free to contribute!
|
package/lib/index.js
CHANGED
|
@@ -1517,7 +1517,12 @@ var require_stringify = __commonJS({
|
|
|
1517
1517
|
let obj;
|
|
1518
1518
|
if (identity.isScalar(item)) {
|
|
1519
1519
|
obj = item.value;
|
|
1520
|
-
|
|
1520
|
+
let match = tags.filter((t) => t.identify?.(obj));
|
|
1521
|
+
if (match.length > 1) {
|
|
1522
|
+
const testMatch = match.filter((t) => t.test);
|
|
1523
|
+
if (testMatch.length > 0)
|
|
1524
|
+
match = testMatch;
|
|
1525
|
+
}
|
|
1521
1526
|
tagObj = match.find((t) => t.format === item.format) ?? match.find((t) => !t.format);
|
|
1522
1527
|
} else {
|
|
1523
1528
|
obj = item;
|
|
@@ -1731,28 +1736,78 @@ var require_log = __commonJS({
|
|
|
1731
1736
|
}
|
|
1732
1737
|
});
|
|
1733
1738
|
|
|
1739
|
+
// node_modules/yaml/dist/schema/yaml-1.1/merge.js
|
|
1740
|
+
var require_merge = __commonJS({
|
|
1741
|
+
"node_modules/yaml/dist/schema/yaml-1.1/merge.js"(exports2) {
|
|
1742
|
+
"use strict";
|
|
1743
|
+
var identity = require_identity();
|
|
1744
|
+
var Scalar = require_Scalar();
|
|
1745
|
+
var MERGE_KEY = "<<";
|
|
1746
|
+
var merge = {
|
|
1747
|
+
identify: (value) => value === MERGE_KEY || typeof value === "symbol" && value.description === MERGE_KEY,
|
|
1748
|
+
default: "key",
|
|
1749
|
+
tag: "tag:yaml.org,2002:merge",
|
|
1750
|
+
test: /^<<$/,
|
|
1751
|
+
resolve: () => Object.assign(new Scalar.Scalar(Symbol(MERGE_KEY)), {
|
|
1752
|
+
addToJSMap: addMergeToJSMap
|
|
1753
|
+
}),
|
|
1754
|
+
stringify: () => MERGE_KEY
|
|
1755
|
+
};
|
|
1756
|
+
var isMergeKey = (ctx, key) => (merge.identify(key) || identity.isScalar(key) && (!key.type || key.type === Scalar.Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
|
|
1757
|
+
function addMergeToJSMap(ctx, map, value) {
|
|
1758
|
+
value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
1759
|
+
if (identity.isSeq(value))
|
|
1760
|
+
for (const it of value.items)
|
|
1761
|
+
mergeValue(ctx, map, it);
|
|
1762
|
+
else if (Array.isArray(value))
|
|
1763
|
+
for (const it of value)
|
|
1764
|
+
mergeValue(ctx, map, it);
|
|
1765
|
+
else
|
|
1766
|
+
mergeValue(ctx, map, value);
|
|
1767
|
+
}
|
|
1768
|
+
function mergeValue(ctx, map, value) {
|
|
1769
|
+
const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
1770
|
+
if (!identity.isMap(source))
|
|
1771
|
+
throw new Error("Merge sources must be maps or map aliases");
|
|
1772
|
+
const srcMap = source.toJSON(null, ctx, Map);
|
|
1773
|
+
for (const [key, value2] of srcMap) {
|
|
1774
|
+
if (map instanceof Map) {
|
|
1775
|
+
if (!map.has(key))
|
|
1776
|
+
map.set(key, value2);
|
|
1777
|
+
} else if (map instanceof Set) {
|
|
1778
|
+
map.add(key);
|
|
1779
|
+
} else if (!Object.prototype.hasOwnProperty.call(map, key)) {
|
|
1780
|
+
Object.defineProperty(map, key, {
|
|
1781
|
+
value: value2,
|
|
1782
|
+
writable: true,
|
|
1783
|
+
enumerable: true,
|
|
1784
|
+
configurable: true
|
|
1785
|
+
});
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return map;
|
|
1789
|
+
}
|
|
1790
|
+
exports2.addMergeToJSMap = addMergeToJSMap;
|
|
1791
|
+
exports2.isMergeKey = isMergeKey;
|
|
1792
|
+
exports2.merge = merge;
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
1795
|
+
|
|
1734
1796
|
// node_modules/yaml/dist/nodes/addPairToJSMap.js
|
|
1735
1797
|
var require_addPairToJSMap = __commonJS({
|
|
1736
1798
|
"node_modules/yaml/dist/nodes/addPairToJSMap.js"(exports2) {
|
|
1737
1799
|
"use strict";
|
|
1738
1800
|
var log = require_log();
|
|
1801
|
+
var merge = require_merge();
|
|
1739
1802
|
var stringify = require_stringify();
|
|
1740
1803
|
var identity = require_identity();
|
|
1741
|
-
var Scalar = require_Scalar();
|
|
1742
1804
|
var toJS = require_toJS();
|
|
1743
|
-
var MERGE_KEY = "<<";
|
|
1744
1805
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
1745
|
-
if (
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
else if (Array.isArray(value))
|
|
1751
|
-
for (const it of value)
|
|
1752
|
-
mergeToJSMap(ctx, map, it);
|
|
1753
|
-
else
|
|
1754
|
-
mergeToJSMap(ctx, map, value);
|
|
1755
|
-
} else {
|
|
1806
|
+
if (identity.isNode(key) && key.addToJSMap)
|
|
1807
|
+
key.addToJSMap(ctx, map, value);
|
|
1808
|
+
else if (merge.isMergeKey(ctx, key))
|
|
1809
|
+
merge.addMergeToJSMap(ctx, map, value);
|
|
1810
|
+
else {
|
|
1756
1811
|
const jsKey = toJS.toJS(key, "", ctx);
|
|
1757
1812
|
if (map instanceof Map) {
|
|
1758
1813
|
map.set(jsKey, toJS.toJS(value, jsKey, ctx));
|
|
@@ -1774,29 +1829,6 @@ var require_addPairToJSMap = __commonJS({
|
|
|
1774
1829
|
}
|
|
1775
1830
|
return map;
|
|
1776
1831
|
}
|
|
1777
|
-
var isMergeKey = (key) => key === MERGE_KEY || identity.isScalar(key) && key.value === MERGE_KEY && (!key.type || key.type === Scalar.Scalar.PLAIN);
|
|
1778
|
-
function mergeToJSMap(ctx, map, value) {
|
|
1779
|
-
const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
1780
|
-
if (!identity.isMap(source))
|
|
1781
|
-
throw new Error("Merge sources must be maps or map aliases");
|
|
1782
|
-
const srcMap = source.toJSON(null, ctx, Map);
|
|
1783
|
-
for (const [key, value2] of srcMap) {
|
|
1784
|
-
if (map instanceof Map) {
|
|
1785
|
-
if (!map.has(key))
|
|
1786
|
-
map.set(key, value2);
|
|
1787
|
-
} else if (map instanceof Set) {
|
|
1788
|
-
map.add(key);
|
|
1789
|
-
} else if (!Object.prototype.hasOwnProperty.call(map, key)) {
|
|
1790
|
-
Object.defineProperty(map, key, {
|
|
1791
|
-
value: value2,
|
|
1792
|
-
writable: true,
|
|
1793
|
-
enumerable: true,
|
|
1794
|
-
configurable: true
|
|
1795
|
-
});
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
return map;
|
|
1799
|
-
}
|
|
1800
1832
|
function stringifyKey(key, jsKey, ctx) {
|
|
1801
1833
|
if (jsKey === null)
|
|
1802
1834
|
return "";
|
|
@@ -3156,6 +3188,7 @@ var require_schema3 = __commonJS({
|
|
|
3156
3188
|
var bool = require_bool2();
|
|
3157
3189
|
var float = require_float2();
|
|
3158
3190
|
var int = require_int2();
|
|
3191
|
+
var merge = require_merge();
|
|
3159
3192
|
var omap = require_omap();
|
|
3160
3193
|
var pairs = require_pairs();
|
|
3161
3194
|
var set = require_set();
|
|
@@ -3175,6 +3208,7 @@ var require_schema3 = __commonJS({
|
|
|
3175
3208
|
float.floatExp,
|
|
3176
3209
|
float.float,
|
|
3177
3210
|
binary.binary,
|
|
3211
|
+
merge.merge,
|
|
3178
3212
|
omap.omap,
|
|
3179
3213
|
pairs.pairs,
|
|
3180
3214
|
set.set,
|
|
@@ -3200,6 +3234,7 @@ var require_tags = __commonJS({
|
|
|
3200
3234
|
var schema = require_schema();
|
|
3201
3235
|
var schema$1 = require_schema2();
|
|
3202
3236
|
var binary = require_binary();
|
|
3237
|
+
var merge = require_merge();
|
|
3203
3238
|
var omap = require_omap();
|
|
3204
3239
|
var pairs = require_pairs();
|
|
3205
3240
|
var schema$2 = require_schema3();
|
|
@@ -3224,6 +3259,7 @@ var require_tags = __commonJS({
|
|
|
3224
3259
|
intOct: int.intOct,
|
|
3225
3260
|
intTime: timestamp.intTime,
|
|
3226
3261
|
map: map.map,
|
|
3262
|
+
merge: merge.merge,
|
|
3227
3263
|
null: _null.nullTag,
|
|
3228
3264
|
omap: omap.omap,
|
|
3229
3265
|
pairs: pairs.pairs,
|
|
@@ -3233,13 +3269,18 @@ var require_tags = __commonJS({
|
|
|
3233
3269
|
};
|
|
3234
3270
|
var coreKnownTags = {
|
|
3235
3271
|
"tag:yaml.org,2002:binary": binary.binary,
|
|
3272
|
+
"tag:yaml.org,2002:merge": merge.merge,
|
|
3236
3273
|
"tag:yaml.org,2002:omap": omap.omap,
|
|
3237
3274
|
"tag:yaml.org,2002:pairs": pairs.pairs,
|
|
3238
3275
|
"tag:yaml.org,2002:set": set.set,
|
|
3239
3276
|
"tag:yaml.org,2002:timestamp": timestamp.timestamp
|
|
3240
3277
|
};
|
|
3241
|
-
function getTags(customTags, schemaName) {
|
|
3242
|
-
|
|
3278
|
+
function getTags(customTags, schemaName, addMergeTag) {
|
|
3279
|
+
const schemaTags = schemas.get(schemaName);
|
|
3280
|
+
if (schemaTags && !customTags) {
|
|
3281
|
+
return addMergeTag && !schemaTags.includes(merge.merge) ? schemaTags.concat(merge.merge) : schemaTags.slice();
|
|
3282
|
+
}
|
|
3283
|
+
let tags = schemaTags;
|
|
3243
3284
|
if (!tags) {
|
|
3244
3285
|
if (Array.isArray(customTags))
|
|
3245
3286
|
tags = [];
|
|
@@ -3254,15 +3295,19 @@ var require_tags = __commonJS({
|
|
|
3254
3295
|
} else if (typeof customTags === "function") {
|
|
3255
3296
|
tags = customTags(tags.slice());
|
|
3256
3297
|
}
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
const tagObj = tagsByName[tag];
|
|
3261
|
-
if (tagObj)
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3298
|
+
if (addMergeTag)
|
|
3299
|
+
tags = tags.concat(merge.merge);
|
|
3300
|
+
return tags.reduce((tags2, tag) => {
|
|
3301
|
+
const tagObj = typeof tag === "string" ? tagsByName[tag] : tag;
|
|
3302
|
+
if (!tagObj) {
|
|
3303
|
+
const tagName = JSON.stringify(tag);
|
|
3304
|
+
const keys = Object.keys(tagsByName).map((key) => JSON.stringify(key)).join(", ");
|
|
3305
|
+
throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);
|
|
3306
|
+
}
|
|
3307
|
+
if (!tags2.includes(tagObj))
|
|
3308
|
+
tags2.push(tagObj);
|
|
3309
|
+
return tags2;
|
|
3310
|
+
}, []);
|
|
3266
3311
|
}
|
|
3267
3312
|
exports2.coreKnownTags = coreKnownTags;
|
|
3268
3313
|
exports2.getTags = getTags;
|
|
@@ -3282,10 +3327,9 @@ var require_Schema = __commonJS({
|
|
|
3282
3327
|
var Schema = class _Schema {
|
|
3283
3328
|
constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }) {
|
|
3284
3329
|
this.compat = Array.isArray(compat) ? tags.getTags(compat, "compat") : compat ? tags.getTags(null, compat) : null;
|
|
3285
|
-
this.merge = !!merge;
|
|
3286
3330
|
this.name = typeof schema === "string" && schema || "core";
|
|
3287
3331
|
this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
|
|
3288
|
-
this.tags = tags.getTags(customTags, this.name);
|
|
3332
|
+
this.tags = tags.getTags(customTags, this.name, merge);
|
|
3289
3333
|
this.toStringOptions = toStringDefaults ?? null;
|
|
3290
3334
|
Object.defineProperty(this, identity.MAP, { value: map.map });
|
|
3291
3335
|
Object.defineProperty(this, identity.SCALAR, { value: string.string });
|
|
@@ -3417,6 +3461,7 @@ var require_Document = __commonJS({
|
|
|
3417
3461
|
logLevel: "warn",
|
|
3418
3462
|
prettyErrors: true,
|
|
3419
3463
|
strict: true,
|
|
3464
|
+
stringKeys: false,
|
|
3420
3465
|
uniqueKeys: true,
|
|
3421
3466
|
version: "1.2"
|
|
3422
3467
|
}, options);
|
|
@@ -3618,7 +3663,7 @@ var require_Document = __commonJS({
|
|
|
3618
3663
|
this.directives.yaml.version = "1.1";
|
|
3619
3664
|
else
|
|
3620
3665
|
this.directives = new directives.Directives({ version: "1.1" });
|
|
3621
|
-
opt = {
|
|
3666
|
+
opt = { resolveKnownTags: false, schema: "yaml-1.1" };
|
|
3622
3667
|
break;
|
|
3623
3668
|
case "1.2":
|
|
3624
3669
|
case "next":
|
|
@@ -3626,7 +3671,7 @@ var require_Document = __commonJS({
|
|
|
3626
3671
|
this.directives.yaml.version = version;
|
|
3627
3672
|
else
|
|
3628
3673
|
this.directives = new directives.Directives({ version });
|
|
3629
|
-
opt = {
|
|
3674
|
+
opt = { resolveKnownTags: true, schema: "core" };
|
|
3630
3675
|
break;
|
|
3631
3676
|
case null:
|
|
3632
3677
|
if (this.directives)
|
|
@@ -3959,7 +4004,7 @@ var require_util_map_includes = __commonJS({
|
|
|
3959
4004
|
const { uniqueKeys } = ctx.options;
|
|
3960
4005
|
if (uniqueKeys === false)
|
|
3961
4006
|
return false;
|
|
3962
|
-
const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || identity.isScalar(a) && identity.isScalar(b) && a.value === b.value
|
|
4007
|
+
const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || identity.isScalar(a) && identity.isScalar(b) && a.value === b.value;
|
|
3963
4008
|
return items.some((pair) => isEqual(pair.key, search));
|
|
3964
4009
|
}
|
|
3965
4010
|
exports2.mapIncludes = mapIncludes;
|
|
@@ -4018,10 +4063,12 @@ var require_resolve_block_map = __commonJS({
|
|
|
4018
4063
|
} else if (keyProps.found?.indent !== bm.indent) {
|
|
4019
4064
|
onError(offset, "BAD_INDENT", startColMsg);
|
|
4020
4065
|
}
|
|
4066
|
+
ctx.atKey = true;
|
|
4021
4067
|
const keyStart = keyProps.end;
|
|
4022
4068
|
const keyNode = key ? composeNode(ctx, key, keyProps, onError) : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
|
|
4023
4069
|
if (ctx.schema.compat)
|
|
4024
4070
|
utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
|
|
4071
|
+
ctx.atKey = false;
|
|
4025
4072
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
4026
4073
|
onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
|
|
4027
4074
|
const valueProps = resolveProps.resolveProps(sep ?? [], {
|
|
@@ -4084,6 +4131,8 @@ var require_resolve_block_seq = __commonJS({
|
|
|
4084
4131
|
const seq = new NodeClass(ctx.schema);
|
|
4085
4132
|
if (ctx.atRoot)
|
|
4086
4133
|
ctx.atRoot = false;
|
|
4134
|
+
if (ctx.atKey)
|
|
4135
|
+
ctx.atKey = false;
|
|
4087
4136
|
let offset = bs.offset;
|
|
4088
4137
|
let commentEnd = null;
|
|
4089
4138
|
for (const { start, value } of bs.items) {
|
|
@@ -4187,6 +4236,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4187
4236
|
const atRoot = ctx.atRoot;
|
|
4188
4237
|
if (atRoot)
|
|
4189
4238
|
ctx.atRoot = false;
|
|
4239
|
+
if (ctx.atKey)
|
|
4240
|
+
ctx.atKey = false;
|
|
4190
4241
|
let offset = fc.offset + fc.start.source.length;
|
|
4191
4242
|
for (let i = 0; i < fc.items.length; ++i) {
|
|
4192
4243
|
const collItem = fc.items[i];
|
|
@@ -4263,10 +4314,12 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4263
4314
|
if (isBlock(value))
|
|
4264
4315
|
onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
4265
4316
|
} else {
|
|
4317
|
+
ctx.atKey = true;
|
|
4266
4318
|
const keyStart = props.end;
|
|
4267
4319
|
const keyNode = key ? composeNode(ctx, key, props, onError) : composeEmptyNode(ctx, keyStart, start, null, props, onError);
|
|
4268
4320
|
if (isBlock(key))
|
|
4269
4321
|
onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
4322
|
+
ctx.atKey = false;
|
|
4270
4323
|
const valueProps = resolveProps.resolveProps(sep ?? [], {
|
|
4271
4324
|
flow: fcName,
|
|
4272
4325
|
indicator: "map-value-ind",
|
|
@@ -4829,7 +4882,15 @@ var require_compose_scalar = __commonJS({
|
|
|
4829
4882
|
function composeScalar(ctx, token, tagToken, onError) {
|
|
4830
4883
|
const { value, type, comment, range } = token.type === "block-scalar" ? resolveBlockScalar.resolveBlockScalar(ctx, token, onError) : resolveFlowScalar.resolveFlowScalar(token, ctx.options.strict, onError);
|
|
4831
4884
|
const tagName = tagToken ? ctx.directives.tagName(tagToken.source, (msg) => onError(tagToken, "TAG_RESOLVE_FAILED", msg)) : null;
|
|
4832
|
-
|
|
4885
|
+
let tag;
|
|
4886
|
+
if (ctx.options.stringKeys && ctx.atKey) {
|
|
4887
|
+
tag = ctx.schema[identity.SCALAR];
|
|
4888
|
+
} else if (tagName)
|
|
4889
|
+
tag = findScalarTagByName(ctx.schema, value, tagName, tagToken, onError);
|
|
4890
|
+
else if (token.type === "scalar")
|
|
4891
|
+
tag = findScalarTagByTest(ctx, value, token, onError);
|
|
4892
|
+
else
|
|
4893
|
+
tag = ctx.schema[identity.SCALAR];
|
|
4833
4894
|
let scalar;
|
|
4834
4895
|
try {
|
|
4835
4896
|
const res = tag.resolve(value, (msg) => onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg), ctx.options);
|
|
@@ -4874,8 +4935,8 @@ var require_compose_scalar = __commonJS({
|
|
|
4874
4935
|
onError(tagToken, "TAG_RESOLVE_FAILED", `Unresolved tag: ${tagName}`, tagName !== "tag:yaml.org,2002:str");
|
|
4875
4936
|
return schema[identity.SCALAR];
|
|
4876
4937
|
}
|
|
4877
|
-
function findScalarTagByTest({ directives, schema }, value, token, onError) {
|
|
4878
|
-
const tag = schema.tags.find((tag2) => tag2.default && tag2.test?.test(value)) || schema[identity.SCALAR];
|
|
4938
|
+
function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
|
|
4939
|
+
const tag = schema.tags.find((tag2) => (tag2.default === true || atKey && tag2.default === "key") && tag2.test?.test(value)) || schema[identity.SCALAR];
|
|
4879
4940
|
if (schema.compat) {
|
|
4880
4941
|
const compat = schema.compat.find((tag2) => tag2.default && tag2.test?.test(value)) ?? schema[identity.SCALAR];
|
|
4881
4942
|
if (tag.tag !== compat.tag) {
|
|
@@ -4927,12 +4988,14 @@ var require_compose_node = __commonJS({
|
|
|
4927
4988
|
"node_modules/yaml/dist/compose/compose-node.js"(exports2) {
|
|
4928
4989
|
"use strict";
|
|
4929
4990
|
var Alias = require_Alias();
|
|
4991
|
+
var identity = require_identity();
|
|
4930
4992
|
var composeCollection = require_compose_collection();
|
|
4931
4993
|
var composeScalar = require_compose_scalar();
|
|
4932
4994
|
var resolveEnd = require_resolve_end();
|
|
4933
4995
|
var utilEmptyScalarPosition = require_util_empty_scalar_position();
|
|
4934
4996
|
var CN = { composeNode, composeEmptyNode };
|
|
4935
4997
|
function composeNode(ctx, token, props, onError) {
|
|
4998
|
+
const atKey = ctx.atKey;
|
|
4936
4999
|
const { spaceBefore, comment, anchor, tag } = props;
|
|
4937
5000
|
let node;
|
|
4938
5001
|
let isSrcToken = true;
|
|
@@ -4966,6 +5029,10 @@ var require_compose_node = __commonJS({
|
|
|
4966
5029
|
}
|
|
4967
5030
|
if (anchor && node.anchor === "")
|
|
4968
5031
|
onError(anchor, "BAD_ALIAS", "Anchor cannot be an empty string");
|
|
5032
|
+
if (atKey && ctx.options.stringKeys && (!identity.isScalar(node) || typeof node.value !== "string" || node.tag && node.tag !== "tag:yaml.org,2002:str")) {
|
|
5033
|
+
const msg = "With stringKeys, all keys must be strings";
|
|
5034
|
+
onError(tag ?? token, "NON_STRING_KEY", msg);
|
|
5035
|
+
}
|
|
4969
5036
|
if (spaceBefore)
|
|
4970
5037
|
node.spaceBefore = true;
|
|
4971
5038
|
if (comment) {
|
|
@@ -5029,6 +5096,7 @@ var require_compose_doc = __commonJS({
|
|
|
5029
5096
|
const opts = Object.assign({ _directives: directives }, options);
|
|
5030
5097
|
const doc = new Document.Document(void 0, opts);
|
|
5031
5098
|
const ctx = {
|
|
5099
|
+
atKey: false,
|
|
5032
5100
|
atRoot: true,
|
|
5033
5101
|
directives: doc.directives,
|
|
5034
5102
|
options: doc.options,
|
|
@@ -7141,6 +7209,7 @@ var require_public_api = __commonJS({
|
|
|
7141
7209
|
var Document = require_Document();
|
|
7142
7210
|
var errors = require_errors();
|
|
7143
7211
|
var log = require_log();
|
|
7212
|
+
var identity = require_identity();
|
|
7144
7213
|
var lineCounter = require_line_counter();
|
|
7145
7214
|
var parser = require_parser();
|
|
7146
7215
|
function parseOptions(options) {
|
|
@@ -7218,6 +7287,8 @@ var require_public_api = __commonJS({
|
|
|
7218
7287
|
if (!keepUndefined)
|
|
7219
7288
|
return void 0;
|
|
7220
7289
|
}
|
|
7290
|
+
if (identity.isDocument(value) && !_replacer)
|
|
7291
|
+
return value.toString(options);
|
|
7221
7292
|
return new Document.Document(value, _replacer, options).toString(options);
|
|
7222
7293
|
}
|
|
7223
7294
|
exports2.parse = parse2;
|
|
@@ -7793,20 +7864,6 @@ var convertRawTypstAstStringToObject = (rawTypstAstString) => {
|
|
|
7793
7864
|
const parsed = (0, import_yaml.parse)(escapedRawTypstAstYamlString);
|
|
7794
7865
|
return parsed.ast;
|
|
7795
7866
|
};
|
|
7796
|
-
var convertTypstAstNodeTypeToTextlintNodeType = (typstAstNodeType) => {
|
|
7797
|
-
const nodeTypeMap = /* @__PURE__ */ new Map([
|
|
7798
|
-
[/^Marked::Heading$/, import_ast_node_types.ASTNodeTypes.Header],
|
|
7799
|
-
[/^Marked::Text/, import_ast_node_types.ASTNodeTypes.Str],
|
|
7800
|
-
[/^Marked::Parbreak/, import_ast_node_types.ASTNodeTypes.Break],
|
|
7801
|
-
[/^Escape::Linebreak/, import_ast_node_types.ASTNodeTypes.Break]
|
|
7802
|
-
]);
|
|
7803
|
-
for (const [pattern, nodeType] of nodeTypeMap) {
|
|
7804
|
-
if (pattern.test(typstAstNodeType)) {
|
|
7805
|
-
return nodeType;
|
|
7806
|
-
}
|
|
7807
|
-
}
|
|
7808
|
-
return typstAstNodeType;
|
|
7809
|
-
};
|
|
7810
7867
|
var extractRawSourceByLocation = (typstSource, location) => {
|
|
7811
7868
|
const { start, end } = location;
|
|
7812
7869
|
const lines = typstSource.split("\n");
|
|
@@ -7927,16 +7984,32 @@ var convertRawTypstAstObjectToTextlintAstObject = (rawTypstAstObject, typstSourc
|
|
|
7927
7984
|
node.value = extractRawSourceByLocation(typstSource, location);
|
|
7928
7985
|
}
|
|
7929
7986
|
const endOffset = currentOffset + nodeLength;
|
|
7930
|
-
node.type = convertTypstAstNodeTypeToTextlintNodeType(
|
|
7931
|
-
extractNodeType(node.s)
|
|
7932
|
-
);
|
|
7933
7987
|
node.raw = extractRawSourceByLocation(typstSource, location);
|
|
7934
7988
|
node.range = [startOffset, endOffset];
|
|
7935
7989
|
node.loc = location;
|
|
7990
|
+
node.type = extractNodeType(node.s);
|
|
7991
|
+
if (/^Marked::Heading$/.test(node.type)) {
|
|
7992
|
+
node.type = import_ast_node_types.ASTNodeTypes.Header;
|
|
7993
|
+
}
|
|
7994
|
+
if (/^Marked::Text/.test(node.type)) {
|
|
7995
|
+
node.type = import_ast_node_types.ASTNodeTypes.Str;
|
|
7996
|
+
}
|
|
7997
|
+
if (/^Marked::Parbreak/.test(node.type)) {
|
|
7998
|
+
node.type = import_ast_node_types.ASTNodeTypes.Break;
|
|
7999
|
+
}
|
|
8000
|
+
if (/^Escape::Linebreak/.test(node.type)) {
|
|
8001
|
+
node.type = import_ast_node_types.ASTNodeTypes.Break;
|
|
8002
|
+
}
|
|
7936
8003
|
if (node.type === "Marked::Raw") {
|
|
7937
8004
|
if (node.loc.start.line === node.loc.end.line) {
|
|
7938
8005
|
node.type = import_ast_node_types.ASTNodeTypes.Code;
|
|
7939
|
-
|
|
8006
|
+
if (/^```([\s\S]*?)```$/.test(node.raw)) {
|
|
8007
|
+
const codeBlockPattern = /^```(\w+)?\s([\s\S]*?)\s*```$/;
|
|
8008
|
+
const match = node.raw.match(codeBlockPattern);
|
|
8009
|
+
node.value = match ? match[2].trim() : "";
|
|
8010
|
+
} else {
|
|
8011
|
+
node.value = node.raw.replace(/`([\s\S]*?)`/, "$1");
|
|
8012
|
+
}
|
|
7940
8013
|
} else {
|
|
7941
8014
|
node.type = import_ast_node_types.ASTNodeTypes.CodeBlock;
|
|
7942
8015
|
node.value = node.raw.replace(/```(?:\w*)\n([\s\S]*?)\n```/, "$1");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textlint-plugin-typst",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "textlint plugin to lint Typst",
|
|
5
5
|
"keywords": ["textlint", "textlintplugin", "plugin", "lint", "typst"],
|
|
6
6
|
"repository": "https://github.com/3w36zj6/textlint-plugin-typst",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"lint:apply": "biome lint --apply .",
|
|
22
22
|
"check": "biome check .",
|
|
23
23
|
"check:write": "biome check --write .",
|
|
24
|
-
"test": "vitest"
|
|
24
|
+
"test": "vitest",
|
|
25
|
+
"update-fixtures": "bun ./test/update-fixtures.ts && biome check --write ./test/fixtures"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@myriaddreamin/typst-ts-web-compiler": "^0.5.0-rc7",
|