@wdprlib/parser 5.1.4 → 5.1.6

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.
@@ -0,0 +1,23 @@
1
+ # Third-Party Licenses
2
+
3
+ Portions of this package's code, data structures, and algorithms were adapted from or based on the projects listed below and modified for wdpr's TypeScript implementation. Test fixtures derived from ftml are distributed in the wdpr source repository.
4
+
5
+ ## ftml
6
+
7
+ - Source: <https://github.com/scpwiki/ftml>
8
+ - Author: Emmie Smith
9
+ - Copyright notice: Copyright (C) 2019-2026 Wikijump Team
10
+ - License: GNU Affero General Public License, version 3 or later
11
+
12
+ The GNU Affero General Public License version 3 is reproduced in [LICENSE](LICENSE). The upstream project permits use under version 3 or any later version.
13
+
14
+ ## Wikidot Text_Wiki
15
+
16
+ - Source: <https://github.com/gabrys/wikidot/tree/master/lib/Text_Wiki/Text>
17
+ - Authors and contributors named in the source: Paul M. Jones, Michal Frackowiak, Manuel Holtgrewe, and Bertrand Gugger
18
+ - Copyright notice in some files: 2005 bertrand Gugger
19
+ - License: GNU Lesser General Public License, version 2.1
20
+
21
+ The GNU Lesser General Public License version 2.1 is reproduced in [licenses/LGPL-2.1.txt](licenses/LGPL-2.1.txt).
22
+
23
+ The surrounding Wikidot project is Copyright (c) 2008 by Wikidot Inc. and is distributed under the GNU Affero General Public License, version 3 or later. See the upstream [LICENSE.txt](https://github.com/gabrys/wikidot/blob/master/LICENSE.txt).
package/dist/index.cjs CHANGED
@@ -1,4 +1,3 @@
1
- var import_node_module = require("node:module");
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1298,17 +1297,22 @@ function parseInlineUntil(ctx, endType) {
1298
1297
  }
1299
1298
  // packages/parser/src/parser/rules/block/parsing/attributes/names.ts
1300
1299
  function consumeAttributeName(ctx, startPos, startConsumed, startName, options) {
1300
+ if (startName === "_" && isAttributeWordToken(ctx.tokens[startPos])) {
1301
+ startName += ctx.tokens[startPos]?.value ?? "";
1302
+ startPos++;
1303
+ startConsumed++;
1304
+ }
1301
1305
  return options.strikeHyphens ? consumeRawNameSuffix(ctx, startPos, startConsumed, startName, options.hyphenatedNames) : consumeSafeNameSuffix(ctx, startPos, startConsumed, startName);
1302
1306
  }
1303
1307
  function isAttributeNameToken(token5) {
1304
- return token5?.type === "TEXT" || token5?.type === "IDENTIFIER";
1308
+ return isAttributeWordToken(token5) || token5?.type === "UNDERSCORE";
1305
1309
  }
1306
1310
  function consumeSafeNameSuffix(ctx, startPos, startConsumed, startName) {
1307
1311
  let name = startName;
1308
1312
  let pos = startPos;
1309
1313
  let consumed = startConsumed;
1310
- while (ctx.tokens[pos]?.type === "TEXT" && ctx.tokens[pos]?.value === "-" && isAttributeNameToken(ctx.tokens[pos + 1])) {
1311
- name += "-";
1314
+ while (isAttributeNameSeparator(ctx.tokens[pos]) && isAttributeWordToken(ctx.tokens[pos + 1])) {
1315
+ name += ctx.tokens[pos]?.value ?? "";
1312
1316
  pos++;
1313
1317
  consumed++;
1314
1318
  name += ctx.tokens[pos]?.value ?? "";
@@ -1321,18 +1325,18 @@ function consumeRawNameSuffix(ctx, startPos, startConsumed, startName, hyphenate
1321
1325
  let name = startName;
1322
1326
  let pos = startPos;
1323
1327
  let consumed = startConsumed;
1324
- while (isHyphenToken(ctx.tokens[pos])) {
1325
- while (isHyphenToken(ctx.tokens[pos])) {
1326
- if (hyphenatedNames) {
1328
+ while (isAttributeNameSeparator(ctx.tokens[pos])) {
1329
+ while (isAttributeNameSeparator(ctx.tokens[pos])) {
1330
+ if (hyphenatedNames || ctx.tokens[pos]?.type === "UNDERSCORE") {
1327
1331
  name += ctx.tokens[pos]?.value ?? "-";
1328
1332
  }
1329
1333
  pos++;
1330
1334
  consumed++;
1331
1335
  }
1332
- if (!isAttributeNameToken(ctx.tokens[pos])) {
1336
+ if (!isAttributeWordToken(ctx.tokens[pos])) {
1333
1337
  break;
1334
1338
  }
1335
- if (hyphenatedNames) {
1339
+ if (hyphenatedNames || name.endsWith("_")) {
1336
1340
  name += ctx.tokens[pos]?.value ?? "";
1337
1341
  }
1338
1342
  pos++;
@@ -1340,8 +1344,11 @@ function consumeRawNameSuffix(ctx, startPos, startConsumed, startName, hyphenate
1340
1344
  }
1341
1345
  return { name, pos, consumed };
1342
1346
  }
1343
- function isHyphenToken(token5) {
1344
- return token5?.type === "TEXT" && token5.value === "-" || token5?.type === "STRIKE_MARKER";
1347
+ function isAttributeWordToken(token5) {
1348
+ return token5?.type === "TEXT" || token5?.type === "IDENTIFIER";
1349
+ }
1350
+ function isAttributeNameSeparator(token5) {
1351
+ return token5?.type === "TEXT" && token5.value === "-" || token5?.type === "STRIKE_MARKER" || token5?.type === "UNDERSCORE";
1345
1352
  }
1346
1353
 
1347
1354
  // packages/parser/src/parser/rules/block/parsing/attributes/values.ts
@@ -4456,18 +4463,18 @@ var listPagesModuleRule = {
4456
4463
  wrapper,
4457
4464
  rss
4458
4465
  } = args;
4459
- const linkTo = args["link-to"] ?? args.linkto;
4460
- const createdBy = args["created-by"] ?? args.createdby;
4461
- const createdAt = args["created-at"] ?? args.createdat;
4462
- const updatedAt = args["updated-at"] ?? args.updatedat;
4463
- const perPage = args["per-page"] ?? args.perpage;
4464
- const prependLine = args["prepend-line"] ?? args.prependline;
4465
- const appendLine = args["append-line"] ?? args.appendline;
4466
- const rssDescription = args["rss-description"] ?? args.rssdescription;
4467
- const rssHome = args["rss-home"] ?? args.rsshome;
4468
- const rssLimit = args["rss-limit"] ?? args.rsslimit;
4469
- const rssOnly = args["rss-only"] ?? args.rssonly;
4470
- const urlAttrPrefix = args["url-attr-prefix"] ?? args.urlattrprefix;
4466
+ const linkTo = args["link-to"] ?? args.linkto ?? args.link_to;
4467
+ const createdBy = args["created-by"] ?? args.createdby ?? args.created_by;
4468
+ const createdAt = args["created-at"] ?? args.createdat ?? args.created_at;
4469
+ const updatedAt = args["updated-at"] ?? args.updatedat ?? args.updated_at;
4470
+ const perPage = args["per-page"] ?? args.perpage ?? args.per_page;
4471
+ const prependLine = args["prepend-line"] ?? args.prependline ?? args.prepend_line;
4472
+ const appendLine = args["append-line"] ?? args.appendline ?? args.append_line;
4473
+ const rssDescription = args["rss-description"] ?? args.rssdescription ?? args.rss_description;
4474
+ const rssHome = args["rss-home"] ?? args.rsshome ?? args.rss_home;
4475
+ const rssLimit = args["rss-limit"] ?? args.rsslimit ?? args.rss_limit;
4476
+ const rssOnly = args["rss-only"] ?? args.rssonly ?? args.rss_only;
4477
+ const urlAttrPrefix = args["url-attr-prefix"] ?? args.urlattrprefix ?? args.url_attr_prefix;
4471
4478
  const rawArgs = { ...args };
4472
4479
  return {
4473
4480
  module: "list-pages",
@@ -5979,7 +5986,12 @@ function setsEqual(left, right) {
5979
5986
  var URL_RESOLVABLE_FIELDS = [
5980
5987
  { attr: "offset", queryKey: "offset", type: "number" },
5981
5988
  { attr: "limit", queryKey: "limit", type: "number" },
5982
- { attr: "per-page", queryKey: "perPage", type: "number" },
5989
+ {
5990
+ attr: "per-page",
5991
+ queryKey: "perPage",
5992
+ type: "number",
5993
+ aliases: ["perpage", "per_page"]
5994
+ },
5983
5995
  { attr: "order", queryKey: "order", type: "string" },
5984
5996
  { attr: "tags", queryKey: "tags", type: "string", urlAttrs: ["tag"] },
5985
5997
  { attr: "category", queryKey: "category", type: "string" },
@@ -5987,9 +5999,24 @@ var URL_RESOLVABLE_FIELDS = [
5987
5999
  { attr: "range", queryKey: "range", type: "string" },
5988
6000
  { attr: "name", queryKey: "name", type: "string" },
5989
6001
  { attr: "fullname", queryKey: "fullname", type: "string" },
5990
- { attr: "created-at", queryKey: "createdAt", type: "string" },
5991
- { attr: "updated-at", queryKey: "updatedAt", type: "string" },
5992
- { attr: "created-by", queryKey: "createdBy", type: "string" },
6002
+ {
6003
+ attr: "created-at",
6004
+ queryKey: "createdAt",
6005
+ type: "string",
6006
+ aliases: ["createdat", "created_at"]
6007
+ },
6008
+ {
6009
+ attr: "updated-at",
6010
+ queryKey: "updatedAt",
6011
+ type: "string",
6012
+ aliases: ["updatedat", "updated_at"]
6013
+ },
6014
+ {
6015
+ attr: "created-by",
6016
+ queryKey: "createdBy",
6017
+ type: "string",
6018
+ aliases: ["createdby", "created_by"]
6019
+ },
5993
6020
  { attr: "rating", queryKey: "rating", type: "string" },
5994
6021
  { attr: "votes", queryKey: "votes", type: "string" },
5995
6022
  { attr: "reverse", queryKey: "reverse", type: "boolean" }
@@ -6312,7 +6339,7 @@ function resolveQuery(requirement, urlParams) {
6312
6339
  const { query, rawAttributes, urlAttrPrefix } = requirement;
6313
6340
  const resolved = { ...query };
6314
6341
  for (const field of URL_RESOLVABLE_FIELDS) {
6315
- const rawValue = rawAttributes[field.attr];
6342
+ const rawValue = [field.attr, ...field.aliases ?? []].map((attr) => rawAttributes[attr]).find((value) => value !== undefined);
6316
6343
  if (!rawValue)
6317
6344
  continue;
6318
6345
  const resolvedValue = resolveUrlValue(rawValue, getUrlParamNames(field), urlParams, urlAttrPrefix);
package/dist/index.js CHANGED
@@ -1233,17 +1233,22 @@ function parseInlineUntil(ctx, endType) {
1233
1233
  }
1234
1234
  // packages/parser/src/parser/rules/block/parsing/attributes/names.ts
1235
1235
  function consumeAttributeName(ctx, startPos, startConsumed, startName, options) {
1236
+ if (startName === "_" && isAttributeWordToken(ctx.tokens[startPos])) {
1237
+ startName += ctx.tokens[startPos]?.value ?? "";
1238
+ startPos++;
1239
+ startConsumed++;
1240
+ }
1236
1241
  return options.strikeHyphens ? consumeRawNameSuffix(ctx, startPos, startConsumed, startName, options.hyphenatedNames) : consumeSafeNameSuffix(ctx, startPos, startConsumed, startName);
1237
1242
  }
1238
1243
  function isAttributeNameToken(token5) {
1239
- return token5?.type === "TEXT" || token5?.type === "IDENTIFIER";
1244
+ return isAttributeWordToken(token5) || token5?.type === "UNDERSCORE";
1240
1245
  }
1241
1246
  function consumeSafeNameSuffix(ctx, startPos, startConsumed, startName) {
1242
1247
  let name = startName;
1243
1248
  let pos = startPos;
1244
1249
  let consumed = startConsumed;
1245
- while (ctx.tokens[pos]?.type === "TEXT" && ctx.tokens[pos]?.value === "-" && isAttributeNameToken(ctx.tokens[pos + 1])) {
1246
- name += "-";
1250
+ while (isAttributeNameSeparator(ctx.tokens[pos]) && isAttributeWordToken(ctx.tokens[pos + 1])) {
1251
+ name += ctx.tokens[pos]?.value ?? "";
1247
1252
  pos++;
1248
1253
  consumed++;
1249
1254
  name += ctx.tokens[pos]?.value ?? "";
@@ -1256,18 +1261,18 @@ function consumeRawNameSuffix(ctx, startPos, startConsumed, startName, hyphenate
1256
1261
  let name = startName;
1257
1262
  let pos = startPos;
1258
1263
  let consumed = startConsumed;
1259
- while (isHyphenToken(ctx.tokens[pos])) {
1260
- while (isHyphenToken(ctx.tokens[pos])) {
1261
- if (hyphenatedNames) {
1264
+ while (isAttributeNameSeparator(ctx.tokens[pos])) {
1265
+ while (isAttributeNameSeparator(ctx.tokens[pos])) {
1266
+ if (hyphenatedNames || ctx.tokens[pos]?.type === "UNDERSCORE") {
1262
1267
  name += ctx.tokens[pos]?.value ?? "-";
1263
1268
  }
1264
1269
  pos++;
1265
1270
  consumed++;
1266
1271
  }
1267
- if (!isAttributeNameToken(ctx.tokens[pos])) {
1272
+ if (!isAttributeWordToken(ctx.tokens[pos])) {
1268
1273
  break;
1269
1274
  }
1270
- if (hyphenatedNames) {
1275
+ if (hyphenatedNames || name.endsWith("_")) {
1271
1276
  name += ctx.tokens[pos]?.value ?? "";
1272
1277
  }
1273
1278
  pos++;
@@ -1275,8 +1280,11 @@ function consumeRawNameSuffix(ctx, startPos, startConsumed, startName, hyphenate
1275
1280
  }
1276
1281
  return { name, pos, consumed };
1277
1282
  }
1278
- function isHyphenToken(token5) {
1279
- return token5?.type === "TEXT" && token5.value === "-" || token5?.type === "STRIKE_MARKER";
1283
+ function isAttributeWordToken(token5) {
1284
+ return token5?.type === "TEXT" || token5?.type === "IDENTIFIER";
1285
+ }
1286
+ function isAttributeNameSeparator(token5) {
1287
+ return token5?.type === "TEXT" && token5.value === "-" || token5?.type === "STRIKE_MARKER" || token5?.type === "UNDERSCORE";
1280
1288
  }
1281
1289
 
1282
1290
  // packages/parser/src/parser/rules/block/parsing/attributes/values.ts
@@ -4391,18 +4399,18 @@ var listPagesModuleRule = {
4391
4399
  wrapper,
4392
4400
  rss
4393
4401
  } = args;
4394
- const linkTo = args["link-to"] ?? args.linkto;
4395
- const createdBy = args["created-by"] ?? args.createdby;
4396
- const createdAt = args["created-at"] ?? args.createdat;
4397
- const updatedAt = args["updated-at"] ?? args.updatedat;
4398
- const perPage = args["per-page"] ?? args.perpage;
4399
- const prependLine = args["prepend-line"] ?? args.prependline;
4400
- const appendLine = args["append-line"] ?? args.appendline;
4401
- const rssDescription = args["rss-description"] ?? args.rssdescription;
4402
- const rssHome = args["rss-home"] ?? args.rsshome;
4403
- const rssLimit = args["rss-limit"] ?? args.rsslimit;
4404
- const rssOnly = args["rss-only"] ?? args.rssonly;
4405
- const urlAttrPrefix = args["url-attr-prefix"] ?? args.urlattrprefix;
4402
+ const linkTo = args["link-to"] ?? args.linkto ?? args.link_to;
4403
+ const createdBy = args["created-by"] ?? args.createdby ?? args.created_by;
4404
+ const createdAt = args["created-at"] ?? args.createdat ?? args.created_at;
4405
+ const updatedAt = args["updated-at"] ?? args.updatedat ?? args.updated_at;
4406
+ const perPage = args["per-page"] ?? args.perpage ?? args.per_page;
4407
+ const prependLine = args["prepend-line"] ?? args.prependline ?? args.prepend_line;
4408
+ const appendLine = args["append-line"] ?? args.appendline ?? args.append_line;
4409
+ const rssDescription = args["rss-description"] ?? args.rssdescription ?? args.rss_description;
4410
+ const rssHome = args["rss-home"] ?? args.rsshome ?? args.rss_home;
4411
+ const rssLimit = args["rss-limit"] ?? args.rsslimit ?? args.rss_limit;
4412
+ const rssOnly = args["rss-only"] ?? args.rssonly ?? args.rss_only;
4413
+ const urlAttrPrefix = args["url-attr-prefix"] ?? args.urlattrprefix ?? args.url_attr_prefix;
4406
4414
  const rawArgs = { ...args };
4407
4415
  return {
4408
4416
  module: "list-pages",
@@ -5914,7 +5922,12 @@ function setsEqual(left, right) {
5914
5922
  var URL_RESOLVABLE_FIELDS = [
5915
5923
  { attr: "offset", queryKey: "offset", type: "number" },
5916
5924
  { attr: "limit", queryKey: "limit", type: "number" },
5917
- { attr: "per-page", queryKey: "perPage", type: "number" },
5925
+ {
5926
+ attr: "per-page",
5927
+ queryKey: "perPage",
5928
+ type: "number",
5929
+ aliases: ["perpage", "per_page"]
5930
+ },
5918
5931
  { attr: "order", queryKey: "order", type: "string" },
5919
5932
  { attr: "tags", queryKey: "tags", type: "string", urlAttrs: ["tag"] },
5920
5933
  { attr: "category", queryKey: "category", type: "string" },
@@ -5922,9 +5935,24 @@ var URL_RESOLVABLE_FIELDS = [
5922
5935
  { attr: "range", queryKey: "range", type: "string" },
5923
5936
  { attr: "name", queryKey: "name", type: "string" },
5924
5937
  { attr: "fullname", queryKey: "fullname", type: "string" },
5925
- { attr: "created-at", queryKey: "createdAt", type: "string" },
5926
- { attr: "updated-at", queryKey: "updatedAt", type: "string" },
5927
- { attr: "created-by", queryKey: "createdBy", type: "string" },
5938
+ {
5939
+ attr: "created-at",
5940
+ queryKey: "createdAt",
5941
+ type: "string",
5942
+ aliases: ["createdat", "created_at"]
5943
+ },
5944
+ {
5945
+ attr: "updated-at",
5946
+ queryKey: "updatedAt",
5947
+ type: "string",
5948
+ aliases: ["updatedat", "updated_at"]
5949
+ },
5950
+ {
5951
+ attr: "created-by",
5952
+ queryKey: "createdBy",
5953
+ type: "string",
5954
+ aliases: ["createdby", "created_by"]
5955
+ },
5928
5956
  { attr: "rating", queryKey: "rating", type: "string" },
5929
5957
  { attr: "votes", queryKey: "votes", type: "string" },
5930
5958
  { attr: "reverse", queryKey: "reverse", type: "boolean" }
@@ -6247,7 +6275,7 @@ function resolveQuery(requirement, urlParams) {
6247
6275
  const { query, rawAttributes, urlAttrPrefix } = requirement;
6248
6276
  const resolved = { ...query };
6249
6277
  for (const field of URL_RESOLVABLE_FIELDS) {
6250
- const rawValue = rawAttributes[field.attr];
6278
+ const rawValue = [field.attr, ...field.aliases ?? []].map((attr) => rawAttributes[attr]).find((value) => value !== undefined);
6251
6279
  if (!rawValue)
6252
6280
  continue;
6253
6281
  const resolvedValue = resolveUrlValue(rawValue, getUrlParamNames(field), urlParams, urlAttrPrefix);