textlint-plugin-typst 1.0.0 → 1.1.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.
Files changed (3) hide show
  1. package/README.md +17 -0
  2. package/lib/index.js +184 -94
  3. package/package.json +5 -4
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.12.0](https://github.com/typst/typst/releases/tag/v0.12.0).
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
@@ -1375,21 +1375,29 @@ ${indent}`) + "'";
1375
1375
  start = start.replace(/\n+/g, `$&${indent}`);
1376
1376
  }
1377
1377
  const indentSize = indent ? "2" : "1";
1378
- let header = (literal ? "|" : ">") + (startWithSpace ? indentSize : "") + chomp;
1378
+ let header = (startWithSpace ? indentSize : "") + chomp;
1379
1379
  if (comment) {
1380
1380
  header += " " + commentString(comment.replace(/ ?[\r\n]+/g, " "));
1381
1381
  if (onComment)
1382
1382
  onComment();
1383
1383
  }
1384
- if (literal) {
1385
- value = value.replace(/\n+/g, `$&${indent}`);
1386
- return `${header}
1387
- ${indent}${start}${value}${end}`;
1388
- }
1389
- value = value.replace(/\n+/g, "\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, "$1$2").replace(/\n+/g, `$&${indent}`);
1390
- const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx, true));
1391
- return `${header}
1384
+ if (!literal) {
1385
+ const foldedValue = value.replace(/\n+/g, "\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, "$1$2").replace(/\n+/g, `$&${indent}`);
1386
+ let literalFallback = false;
1387
+ const foldOptions = getFoldOptions(ctx, true);
1388
+ if (blockQuote !== "folded" && type !== Scalar.Scalar.BLOCK_FOLDED) {
1389
+ foldOptions.onOverflow = () => {
1390
+ literalFallback = true;
1391
+ };
1392
+ }
1393
+ const body = foldFlowLines.foldFlowLines(`${start}${foldedValue}${end}`, indent, foldFlowLines.FOLD_BLOCK, foldOptions);
1394
+ if (!literalFallback)
1395
+ return `>${header}
1392
1396
  ${indent}${body}`;
1397
+ }
1398
+ value = value.replace(/\n+/g, `$&${indent}`);
1399
+ return `|${header}
1400
+ ${indent}${start}${value}${end}`;
1393
1401
  }
1394
1402
  function plainString(item, ctx, onComment, onChompKeep) {
1395
1403
  const { type, value } = item;
@@ -1517,7 +1525,12 @@ var require_stringify = __commonJS({
1517
1525
  let obj;
1518
1526
  if (identity.isScalar(item)) {
1519
1527
  obj = item.value;
1520
- const match = tags.filter((t) => t.identify?.(obj));
1528
+ let match = tags.filter((t) => t.identify?.(obj));
1529
+ if (match.length > 1) {
1530
+ const testMatch = match.filter((t) => t.test);
1531
+ if (testMatch.length > 0)
1532
+ match = testMatch;
1533
+ }
1521
1534
  tagObj = match.find((t) => t.format === item.format) ?? match.find((t) => !t.format);
1522
1535
  } else {
1523
1536
  obj = item;
@@ -1731,28 +1744,78 @@ var require_log = __commonJS({
1731
1744
  }
1732
1745
  });
1733
1746
 
1747
+ // node_modules/yaml/dist/schema/yaml-1.1/merge.js
1748
+ var require_merge = __commonJS({
1749
+ "node_modules/yaml/dist/schema/yaml-1.1/merge.js"(exports2) {
1750
+ "use strict";
1751
+ var identity = require_identity();
1752
+ var Scalar = require_Scalar();
1753
+ var MERGE_KEY = "<<";
1754
+ var merge = {
1755
+ identify: (value) => value === MERGE_KEY || typeof value === "symbol" && value.description === MERGE_KEY,
1756
+ default: "key",
1757
+ tag: "tag:yaml.org,2002:merge",
1758
+ test: /^<<$/,
1759
+ resolve: () => Object.assign(new Scalar.Scalar(Symbol(MERGE_KEY)), {
1760
+ addToJSMap: addMergeToJSMap
1761
+ }),
1762
+ stringify: () => MERGE_KEY
1763
+ };
1764
+ 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);
1765
+ function addMergeToJSMap(ctx, map, value) {
1766
+ value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1767
+ if (identity.isSeq(value))
1768
+ for (const it of value.items)
1769
+ mergeValue(ctx, map, it);
1770
+ else if (Array.isArray(value))
1771
+ for (const it of value)
1772
+ mergeValue(ctx, map, it);
1773
+ else
1774
+ mergeValue(ctx, map, value);
1775
+ }
1776
+ function mergeValue(ctx, map, value) {
1777
+ const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1778
+ if (!identity.isMap(source))
1779
+ throw new Error("Merge sources must be maps or map aliases");
1780
+ const srcMap = source.toJSON(null, ctx, Map);
1781
+ for (const [key, value2] of srcMap) {
1782
+ if (map instanceof Map) {
1783
+ if (!map.has(key))
1784
+ map.set(key, value2);
1785
+ } else if (map instanceof Set) {
1786
+ map.add(key);
1787
+ } else if (!Object.prototype.hasOwnProperty.call(map, key)) {
1788
+ Object.defineProperty(map, key, {
1789
+ value: value2,
1790
+ writable: true,
1791
+ enumerable: true,
1792
+ configurable: true
1793
+ });
1794
+ }
1795
+ }
1796
+ return map;
1797
+ }
1798
+ exports2.addMergeToJSMap = addMergeToJSMap;
1799
+ exports2.isMergeKey = isMergeKey;
1800
+ exports2.merge = merge;
1801
+ }
1802
+ });
1803
+
1734
1804
  // node_modules/yaml/dist/nodes/addPairToJSMap.js
1735
1805
  var require_addPairToJSMap = __commonJS({
1736
1806
  "node_modules/yaml/dist/nodes/addPairToJSMap.js"(exports2) {
1737
1807
  "use strict";
1738
1808
  var log = require_log();
1809
+ var merge = require_merge();
1739
1810
  var stringify = require_stringify();
1740
1811
  var identity = require_identity();
1741
- var Scalar = require_Scalar();
1742
1812
  var toJS = require_toJS();
1743
- var MERGE_KEY = "<<";
1744
1813
  function addPairToJSMap(ctx, map, { key, value }) {
1745
- if (ctx?.doc.schema.merge && isMergeKey(key)) {
1746
- value = identity.isAlias(value) ? value.resolve(ctx.doc) : value;
1747
- if (identity.isSeq(value))
1748
- for (const it of value.items)
1749
- mergeToJSMap(ctx, map, it);
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 {
1814
+ if (identity.isNode(key) && key.addToJSMap)
1815
+ key.addToJSMap(ctx, map, value);
1816
+ else if (merge.isMergeKey(ctx, key))
1817
+ merge.addMergeToJSMap(ctx, map, value);
1818
+ else {
1756
1819
  const jsKey = toJS.toJS(key, "", ctx);
1757
1820
  if (map instanceof Map) {
1758
1821
  map.set(jsKey, toJS.toJS(value, jsKey, ctx));
@@ -1774,29 +1837,6 @@ var require_addPairToJSMap = __commonJS({
1774
1837
  }
1775
1838
  return map;
1776
1839
  }
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
1840
  function stringifyKey(key, jsKey, ctx) {
1801
1841
  if (jsKey === null)
1802
1842
  return "";
@@ -2552,7 +2592,7 @@ var require_schema2 = __commonJS({
2552
2592
  identify: (value) => typeof value === "boolean",
2553
2593
  default: true,
2554
2594
  tag: "tag:yaml.org,2002:bool",
2555
- test: /^true|false$/,
2595
+ test: /^true$|^false$/,
2556
2596
  resolve: (str) => str === "true",
2557
2597
  stringify: stringifyJSON
2558
2598
  },
@@ -3136,7 +3176,7 @@ var require_timestamp = __commonJS({
3136
3176
  }
3137
3177
  return new Date(date);
3138
3178
  },
3139
- stringify: ({ value }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, "")
3179
+ stringify: ({ value }) => value.toISOString().replace(/(T00:00:00)?\.000Z$/, "")
3140
3180
  };
3141
3181
  exports2.floatTime = floatTime;
3142
3182
  exports2.intTime = intTime;
@@ -3156,6 +3196,7 @@ var require_schema3 = __commonJS({
3156
3196
  var bool = require_bool2();
3157
3197
  var float = require_float2();
3158
3198
  var int = require_int2();
3199
+ var merge = require_merge();
3159
3200
  var omap = require_omap();
3160
3201
  var pairs = require_pairs();
3161
3202
  var set = require_set();
@@ -3175,6 +3216,7 @@ var require_schema3 = __commonJS({
3175
3216
  float.floatExp,
3176
3217
  float.float,
3177
3218
  binary.binary,
3219
+ merge.merge,
3178
3220
  omap.omap,
3179
3221
  pairs.pairs,
3180
3222
  set.set,
@@ -3200,6 +3242,7 @@ var require_tags = __commonJS({
3200
3242
  var schema = require_schema();
3201
3243
  var schema$1 = require_schema2();
3202
3244
  var binary = require_binary();
3245
+ var merge = require_merge();
3203
3246
  var omap = require_omap();
3204
3247
  var pairs = require_pairs();
3205
3248
  var schema$2 = require_schema3();
@@ -3224,6 +3267,7 @@ var require_tags = __commonJS({
3224
3267
  intOct: int.intOct,
3225
3268
  intTime: timestamp.intTime,
3226
3269
  map: map.map,
3270
+ merge: merge.merge,
3227
3271
  null: _null.nullTag,
3228
3272
  omap: omap.omap,
3229
3273
  pairs: pairs.pairs,
@@ -3233,13 +3277,18 @@ var require_tags = __commonJS({
3233
3277
  };
3234
3278
  var coreKnownTags = {
3235
3279
  "tag:yaml.org,2002:binary": binary.binary,
3280
+ "tag:yaml.org,2002:merge": merge.merge,
3236
3281
  "tag:yaml.org,2002:omap": omap.omap,
3237
3282
  "tag:yaml.org,2002:pairs": pairs.pairs,
3238
3283
  "tag:yaml.org,2002:set": set.set,
3239
3284
  "tag:yaml.org,2002:timestamp": timestamp.timestamp
3240
3285
  };
3241
- function getTags(customTags, schemaName) {
3242
- let tags = schemas.get(schemaName);
3286
+ function getTags(customTags, schemaName, addMergeTag) {
3287
+ const schemaTags = schemas.get(schemaName);
3288
+ if (schemaTags && !customTags) {
3289
+ return addMergeTag && !schemaTags.includes(merge.merge) ? schemaTags.concat(merge.merge) : schemaTags.slice();
3290
+ }
3291
+ let tags = schemaTags;
3243
3292
  if (!tags) {
3244
3293
  if (Array.isArray(customTags))
3245
3294
  tags = [];
@@ -3254,15 +3303,19 @@ var require_tags = __commonJS({
3254
3303
  } else if (typeof customTags === "function") {
3255
3304
  tags = customTags(tags.slice());
3256
3305
  }
3257
- return tags.map((tag) => {
3258
- if (typeof tag !== "string")
3259
- return tag;
3260
- const tagObj = tagsByName[tag];
3261
- if (tagObj)
3262
- return tagObj;
3263
- const keys = Object.keys(tagsByName).map((key) => JSON.stringify(key)).join(", ");
3264
- throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
3265
- });
3306
+ if (addMergeTag)
3307
+ tags = tags.concat(merge.merge);
3308
+ return tags.reduce((tags2, tag) => {
3309
+ const tagObj = typeof tag === "string" ? tagsByName[tag] : tag;
3310
+ if (!tagObj) {
3311
+ const tagName = JSON.stringify(tag);
3312
+ const keys = Object.keys(tagsByName).map((key) => JSON.stringify(key)).join(", ");
3313
+ throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);
3314
+ }
3315
+ if (!tags2.includes(tagObj))
3316
+ tags2.push(tagObj);
3317
+ return tags2;
3318
+ }, []);
3266
3319
  }
3267
3320
  exports2.coreKnownTags = coreKnownTags;
3268
3321
  exports2.getTags = getTags;
@@ -3282,10 +3335,9 @@ var require_Schema = __commonJS({
3282
3335
  var Schema = class _Schema {
3283
3336
  constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }) {
3284
3337
  this.compat = Array.isArray(compat) ? tags.getTags(compat, "compat") : compat ? tags.getTags(null, compat) : null;
3285
- this.merge = !!merge;
3286
3338
  this.name = typeof schema === "string" && schema || "core";
3287
3339
  this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
3288
- this.tags = tags.getTags(customTags, this.name);
3340
+ this.tags = tags.getTags(customTags, this.name, merge);
3289
3341
  this.toStringOptions = toStringDefaults ?? null;
3290
3342
  Object.defineProperty(this, identity.MAP, { value: map.map });
3291
3343
  Object.defineProperty(this, identity.SCALAR, { value: string.string });
@@ -3417,6 +3469,7 @@ var require_Document = __commonJS({
3417
3469
  logLevel: "warn",
3418
3470
  prettyErrors: true,
3419
3471
  strict: true,
3472
+ stringKeys: false,
3420
3473
  uniqueKeys: true,
3421
3474
  version: "1.2"
3422
3475
  }, options);
@@ -3618,7 +3671,7 @@ var require_Document = __commonJS({
3618
3671
  this.directives.yaml.version = "1.1";
3619
3672
  else
3620
3673
  this.directives = new directives.Directives({ version: "1.1" });
3621
- opt = { merge: true, resolveKnownTags: false, schema: "yaml-1.1" };
3674
+ opt = { resolveKnownTags: false, schema: "yaml-1.1" };
3622
3675
  break;
3623
3676
  case "1.2":
3624
3677
  case "next":
@@ -3626,7 +3679,7 @@ var require_Document = __commonJS({
3626
3679
  this.directives.yaml.version = version;
3627
3680
  else
3628
3681
  this.directives = new directives.Directives({ version });
3629
- opt = { merge: false, resolveKnownTags: true, schema: "core" };
3682
+ opt = { resolveKnownTags: true, schema: "core" };
3630
3683
  break;
3631
3684
  case null:
3632
3685
  if (this.directives)
@@ -3959,7 +4012,7 @@ var require_util_map_includes = __commonJS({
3959
4012
  const { uniqueKeys } = ctx.options;
3960
4013
  if (uniqueKeys === false)
3961
4014
  return false;
3962
- const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || identity.isScalar(a) && identity.isScalar(b) && a.value === b.value && !(a.value === "<<" && ctx.schema.merge);
4015
+ const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || identity.isScalar(a) && identity.isScalar(b) && a.value === b.value;
3963
4016
  return items.some((pair) => isEqual(pair.key, search));
3964
4017
  }
3965
4018
  exports2.mapIncludes = mapIncludes;
@@ -4018,10 +4071,12 @@ var require_resolve_block_map = __commonJS({
4018
4071
  } else if (keyProps.found?.indent !== bm.indent) {
4019
4072
  onError(offset, "BAD_INDENT", startColMsg);
4020
4073
  }
4074
+ ctx.atKey = true;
4021
4075
  const keyStart = keyProps.end;
4022
4076
  const keyNode = key ? composeNode(ctx, key, keyProps, onError) : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
4023
4077
  if (ctx.schema.compat)
4024
4078
  utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
4079
+ ctx.atKey = false;
4025
4080
  if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
4026
4081
  onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
4027
4082
  const valueProps = resolveProps.resolveProps(sep ?? [], {
@@ -4084,6 +4139,8 @@ var require_resolve_block_seq = __commonJS({
4084
4139
  const seq = new NodeClass(ctx.schema);
4085
4140
  if (ctx.atRoot)
4086
4141
  ctx.atRoot = false;
4142
+ if (ctx.atKey)
4143
+ ctx.atKey = false;
4087
4144
  let offset = bs.offset;
4088
4145
  let commentEnd = null;
4089
4146
  for (const { start, value } of bs.items) {
@@ -4187,6 +4244,8 @@ var require_resolve_flow_collection = __commonJS({
4187
4244
  const atRoot = ctx.atRoot;
4188
4245
  if (atRoot)
4189
4246
  ctx.atRoot = false;
4247
+ if (ctx.atKey)
4248
+ ctx.atKey = false;
4190
4249
  let offset = fc.offset + fc.start.source.length;
4191
4250
  for (let i = 0; i < fc.items.length; ++i) {
4192
4251
  const collItem = fc.items[i];
@@ -4263,10 +4322,12 @@ var require_resolve_flow_collection = __commonJS({
4263
4322
  if (isBlock(value))
4264
4323
  onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
4265
4324
  } else {
4325
+ ctx.atKey = true;
4266
4326
  const keyStart = props.end;
4267
4327
  const keyNode = key ? composeNode(ctx, key, props, onError) : composeEmptyNode(ctx, keyStart, start, null, props, onError);
4268
4328
  if (isBlock(key))
4269
4329
  onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
4330
+ ctx.atKey = false;
4270
4331
  const valueProps = resolveProps.resolveProps(sep ?? [], {
4271
4332
  flow: fcName,
4272
4333
  indicator: "map-value-ind",
@@ -4829,7 +4890,15 @@ var require_compose_scalar = __commonJS({
4829
4890
  function composeScalar(ctx, token, tagToken, onError) {
4830
4891
  const { value, type, comment, range } = token.type === "block-scalar" ? resolveBlockScalar.resolveBlockScalar(ctx, token, onError) : resolveFlowScalar.resolveFlowScalar(token, ctx.options.strict, onError);
4831
4892
  const tagName = tagToken ? ctx.directives.tagName(tagToken.source, (msg) => onError(tagToken, "TAG_RESOLVE_FAILED", msg)) : null;
4832
- const tag = tagToken && tagName ? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError) : token.type === "scalar" ? findScalarTagByTest(ctx, value, token, onError) : ctx.schema[identity.SCALAR];
4893
+ let tag;
4894
+ if (ctx.options.stringKeys && ctx.atKey) {
4895
+ tag = ctx.schema[identity.SCALAR];
4896
+ } else if (tagName)
4897
+ tag = findScalarTagByName(ctx.schema, value, tagName, tagToken, onError);
4898
+ else if (token.type === "scalar")
4899
+ tag = findScalarTagByTest(ctx, value, token, onError);
4900
+ else
4901
+ tag = ctx.schema[identity.SCALAR];
4833
4902
  let scalar;
4834
4903
  try {
4835
4904
  const res = tag.resolve(value, (msg) => onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg), ctx.options);
@@ -4874,8 +4943,8 @@ var require_compose_scalar = __commonJS({
4874
4943
  onError(tagToken, "TAG_RESOLVE_FAILED", `Unresolved tag: ${tagName}`, tagName !== "tag:yaml.org,2002:str");
4875
4944
  return schema[identity.SCALAR];
4876
4945
  }
4877
- function findScalarTagByTest({ directives, schema }, value, token, onError) {
4878
- const tag = schema.tags.find((tag2) => tag2.default && tag2.test?.test(value)) || schema[identity.SCALAR];
4946
+ function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
4947
+ const tag = schema.tags.find((tag2) => (tag2.default === true || atKey && tag2.default === "key") && tag2.test?.test(value)) || schema[identity.SCALAR];
4879
4948
  if (schema.compat) {
4880
4949
  const compat = schema.compat.find((tag2) => tag2.default && tag2.test?.test(value)) ?? schema[identity.SCALAR];
4881
4950
  if (tag.tag !== compat.tag) {
@@ -4927,12 +4996,14 @@ var require_compose_node = __commonJS({
4927
4996
  "node_modules/yaml/dist/compose/compose-node.js"(exports2) {
4928
4997
  "use strict";
4929
4998
  var Alias = require_Alias();
4999
+ var identity = require_identity();
4930
5000
  var composeCollection = require_compose_collection();
4931
5001
  var composeScalar = require_compose_scalar();
4932
5002
  var resolveEnd = require_resolve_end();
4933
5003
  var utilEmptyScalarPosition = require_util_empty_scalar_position();
4934
5004
  var CN = { composeNode, composeEmptyNode };
4935
5005
  function composeNode(ctx, token, props, onError) {
5006
+ const atKey = ctx.atKey;
4936
5007
  const { spaceBefore, comment, anchor, tag } = props;
4937
5008
  let node;
4938
5009
  let isSrcToken = true;
@@ -4966,6 +5037,10 @@ var require_compose_node = __commonJS({
4966
5037
  }
4967
5038
  if (anchor && node.anchor === "")
4968
5039
  onError(anchor, "BAD_ALIAS", "Anchor cannot be an empty string");
5040
+ if (atKey && ctx.options.stringKeys && (!identity.isScalar(node) || typeof node.value !== "string" || node.tag && node.tag !== "tag:yaml.org,2002:str")) {
5041
+ const msg = "With stringKeys, all keys must be strings";
5042
+ onError(tag ?? token, "NON_STRING_KEY", msg);
5043
+ }
4969
5044
  if (spaceBefore)
4970
5045
  node.spaceBefore = true;
4971
5046
  if (comment) {
@@ -5029,6 +5104,7 @@ var require_compose_doc = __commonJS({
5029
5104
  const opts = Object.assign({ _directives: directives }, options);
5030
5105
  const doc = new Document.Document(void 0, opts);
5031
5106
  const ctx = {
5107
+ atKey: false,
5032
5108
  atRoot: true,
5033
5109
  directives: doc.directives,
5034
5110
  options: doc.options,
@@ -7141,6 +7217,7 @@ var require_public_api = __commonJS({
7141
7217
  var Document = require_Document();
7142
7218
  var errors = require_errors();
7143
7219
  var log = require_log();
7220
+ var identity = require_identity();
7144
7221
  var lineCounter = require_line_counter();
7145
7222
  var parser = require_parser();
7146
7223
  function parseOptions(options) {
@@ -7218,6 +7295,8 @@ var require_public_api = __commonJS({
7218
7295
  if (!keepUndefined)
7219
7296
  return void 0;
7220
7297
  }
7298
+ if (identity.isDocument(value) && !_replacer)
7299
+ return value.toString(options);
7221
7300
  return new Document.Document(value, _replacer, options).toString(options);
7222
7301
  }
7223
7302
  exports2.parse = parse2;
@@ -7469,16 +7548,14 @@ replaceTraps((oldTraps) => ({
7469
7548
 
7470
7549
  // node_modules/@myriaddreamin/typst.ts/dist/esm/init.mjs
7471
7550
  var ComponentBuilder = class {
7472
- constructor() {
7473
- this.loadedFonts = /* @__PURE__ */ new Set();
7474
- this.fetcher = fetch;
7475
- }
7551
+ loadedFonts = /* @__PURE__ */ new Set();
7552
+ fetcher = fetch;
7476
7553
  setFetcher(fetcher) {
7477
7554
  this.fetcher = fetcher;
7478
7555
  }
7479
7556
  async loadFonts(builder, fonts) {
7480
7557
  const escapeImport = new Function("m", "return import(m)");
7481
- const fetcher = this.fetcher || (this.fetcher = await async function() {
7558
+ const fetcher = this.fetcher ||= await async function() {
7482
7559
  const { fetchBuilder, FileSystemCache } = await escapeImport("node-fetch-cache");
7483
7560
  const cache = new FileSystemCache({
7484
7561
  /// By default, we don't have a complicated cache policy.
@@ -7493,7 +7570,7 @@ var ComponentBuilder = class {
7493
7570
  clearTimeout(timeout);
7494
7571
  });
7495
7572
  };
7496
- }());
7573
+ }();
7497
7574
  const fontsToLoad = fonts.filter((font) => {
7498
7575
  if (font instanceof Uint8Array) {
7499
7576
  return true;
@@ -7614,6 +7691,8 @@ var once = (fn) => {
7614
7691
  };
7615
7692
  };
7616
7693
  var LazyWasmModule = class {
7694
+ wasmBin;
7695
+ initOnce;
7617
7696
  constructor(initFn) {
7618
7697
  if (typeof initFn !== "function") {
7619
7698
  throw new Error("initFn is not a function");
@@ -7630,6 +7709,10 @@ var LazyWasmModule = class {
7630
7709
 
7631
7710
  // node_modules/@myriaddreamin/typst.ts/dist/esm/compiler.mjs
7632
7711
  var IncrementalServer = class {
7712
+ /**
7713
+ * @internal
7714
+ */
7715
+ [kObject];
7633
7716
  /**
7634
7717
  * @internal
7635
7718
  */
@@ -7663,6 +7746,8 @@ function createTypstCompiler() {
7663
7746
  return new TypstCompilerDriver();
7664
7747
  }
7665
7748
  var TypstCompilerDriver = class {
7749
+ compiler;
7750
+ compilerJs;
7666
7751
  constructor() {
7667
7752
  }
7668
7753
  async init(options) {
@@ -7682,15 +7767,15 @@ var TypstCompilerDriver = class {
7682
7767
  compile(options) {
7683
7768
  return new Promise((resolve) => {
7684
7769
  if ("incrementalServer" in options) {
7685
- resolve(this.compiler.incr_compile(options.mainFilePath, options.incrementalServer[kObject], getDiagnosticsArg(options.diagnostics)));
7770
+ resolve(this.compiler.incr_compile(options.mainFilePath, convertInputs(options.inputs), options.incrementalServer[kObject], getDiagnosticsArg(options.diagnostics)));
7686
7771
  return;
7687
7772
  }
7688
- resolve(this.compiler.compile(options.mainFilePath, options.format || "vector", getDiagnosticsArg(options.diagnostics)));
7773
+ resolve(this.compiler.compile(options.mainFilePath, convertInputs(options.inputs), options.format || "vector", getDiagnosticsArg(options.diagnostics)));
7689
7774
  });
7690
7775
  }
7691
7776
  query(options) {
7692
7777
  return new Promise((resolve) => {
7693
- resolve(JSON.parse(this.compiler.query(options.mainFilePath, options.selector, options.field)));
7778
+ resolve(JSON.parse(this.compiler.query(options.mainFilePath, convertInputs(options.inputs), options.selector, options.field)));
7694
7779
  });
7695
7780
  }
7696
7781
  getSemanticTokenLegend() {
@@ -7740,6 +7825,9 @@ var TypstCompilerDriver = class {
7740
7825
  throw new Error("Please use the api TypstRenderer.renderToCanvas in v0.4.0");
7741
7826
  }
7742
7827
  };
7828
+ function convertInputs(inputs) {
7829
+ return inputs ? Object.entries(inputs) : void 0;
7830
+ }
7743
7831
  function getDiagnosticsArg(diagnostics) {
7744
7832
  switch (diagnostics) {
7745
7833
  case "none":
@@ -7793,20 +7881,6 @@ var convertRawTypstAstStringToObject = (rawTypstAstString) => {
7793
7881
  const parsed = (0, import_yaml.parse)(escapedRawTypstAstYamlString);
7794
7882
  return parsed.ast;
7795
7883
  };
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
7884
  var extractRawSourceByLocation = (typstSource, location) => {
7811
7885
  const { start, end } = location;
7812
7886
  const lines = typstSource.split("\n");
@@ -7927,16 +8001,32 @@ var convertRawTypstAstObjectToTextlintAstObject = (rawTypstAstObject, typstSourc
7927
8001
  node.value = extractRawSourceByLocation(typstSource, location);
7928
8002
  }
7929
8003
  const endOffset = currentOffset + nodeLength;
7930
- node.type = convertTypstAstNodeTypeToTextlintNodeType(
7931
- extractNodeType(node.s)
7932
- );
7933
8004
  node.raw = extractRawSourceByLocation(typstSource, location);
7934
8005
  node.range = [startOffset, endOffset];
7935
8006
  node.loc = location;
8007
+ node.type = extractNodeType(node.s);
8008
+ if (/^Marked::Heading$/.test(node.type)) {
8009
+ node.type = import_ast_node_types.ASTNodeTypes.Header;
8010
+ }
8011
+ if (/^Marked::Text/.test(node.type)) {
8012
+ node.type = import_ast_node_types.ASTNodeTypes.Str;
8013
+ }
8014
+ if (/^Marked::Parbreak/.test(node.type)) {
8015
+ node.type = import_ast_node_types.ASTNodeTypes.Break;
8016
+ }
8017
+ if (/^Escape::Linebreak/.test(node.type)) {
8018
+ node.type = import_ast_node_types.ASTNodeTypes.Break;
8019
+ }
7936
8020
  if (node.type === "Marked::Raw") {
7937
8021
  if (node.loc.start.line === node.loc.end.line) {
7938
8022
  node.type = import_ast_node_types.ASTNodeTypes.Code;
7939
- node.value = node.raw.replace(/`([\s\S]*?)`/, "$1");
8023
+ if (/^```([\s\S]*?)```$/.test(node.raw)) {
8024
+ const codeBlockPattern = /^```(\w+)?\s([\s\S]*?)\s*```$/;
8025
+ const match = node.raw.match(codeBlockPattern);
8026
+ node.value = match ? match[2].trim() : "";
8027
+ } else {
8028
+ node.value = node.raw.replace(/`([\s\S]*?)`/, "$1");
8029
+ }
7940
8030
  } else {
7941
8031
  node.type = import_ast_node_types.ASTNodeTypes.CodeBlock;
7942
8032
  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.0",
3
+ "version": "1.1.0",
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,11 +21,12 @@
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
- "@myriaddreamin/typst-ts-web-compiler": "^0.5.0-rc7",
28
- "@myriaddreamin/typst.ts": "^0.5.0-rc7",
28
+ "@myriaddreamin/typst-ts-web-compiler": "^0.5.1",
29
+ "@myriaddreamin/typst.ts": "^0.5.1",
29
30
  "yaml": "^2.5.1"
30
31
  },
31
32
  "devDependencies": {