@diplodoc/yfmlint 1.4.0 → 1.6.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/build/config.d.ts +1 -0
- package/build/index.js +96 -15
- package/build/index.js.map +4 -4
- package/build/rules/index.d.ts +1 -0
- package/build/rules/yfm018.d.ts +2 -0
- package/package.json +2 -2
package/build/config.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -21337,6 +21337,9 @@ function log(errors, logger) {
|
|
|
21337
21337
|
case "warn" /* WARN */:
|
|
21338
21338
|
logger.warn(message);
|
|
21339
21339
|
break;
|
|
21340
|
+
case "info" /* INFO */:
|
|
21341
|
+
logger.info(message);
|
|
21342
|
+
break;
|
|
21340
21343
|
case "disabled" /* DISABLED */:
|
|
21341
21344
|
default:
|
|
21342
21345
|
break;
|
|
@@ -21367,12 +21370,14 @@ var config_default = {
|
|
|
21367
21370
|
// Term used without definition
|
|
21368
21371
|
YFM008: "warn" /* WARN */,
|
|
21369
21372
|
// Term inside definition not allowed
|
|
21370
|
-
YFM009: "
|
|
21373
|
+
YFM009: "error" /* ERROR */,
|
|
21371
21374
|
// Term definition used not at the end of file
|
|
21372
21375
|
YFM010: "warn" /* WARN */,
|
|
21373
21376
|
// Autotitle anchor is missed
|
|
21374
|
-
YFM011: "warn" /* WARN
|
|
21377
|
+
YFM011: "warn" /* WARN */,
|
|
21375
21378
|
// Max svg size
|
|
21379
|
+
YFM018: "info" /* INFO */
|
|
21380
|
+
// Term definition from include
|
|
21376
21381
|
};
|
|
21377
21382
|
|
|
21378
21383
|
// src/rules/index.ts
|
|
@@ -21388,7 +21393,8 @@ __export(rules_exports, {
|
|
|
21388
21393
|
yfm008: () => yfm008,
|
|
21389
21394
|
yfm009: () => yfm009,
|
|
21390
21395
|
yfm010: () => yfm010,
|
|
21391
|
-
yfm011: () => yfm011
|
|
21396
|
+
yfm011: () => yfm011,
|
|
21397
|
+
yfm018: () => yfm018
|
|
21392
21398
|
});
|
|
21393
21399
|
|
|
21394
21400
|
// src/rules/yfm001.ts
|
|
@@ -21766,6 +21772,56 @@ var yfm008 = {
|
|
|
21766
21772
|
};
|
|
21767
21773
|
|
|
21768
21774
|
// src/rules/yfm009.ts
|
|
21775
|
+
function isFromInclude(token) {
|
|
21776
|
+
return token.attrGet("from-include") === "true";
|
|
21777
|
+
}
|
|
21778
|
+
function isLintMarker(token) {
|
|
21779
|
+
return token.type === "__yfm_lint";
|
|
21780
|
+
}
|
|
21781
|
+
function findMatchingDfnOpen(tokens, closeIndex) {
|
|
21782
|
+
let depth = 0;
|
|
21783
|
+
for (let j = closeIndex; j >= 0; j--) {
|
|
21784
|
+
if (tokens[j].type === "dfn_close") depth++;
|
|
21785
|
+
if (tokens[j].type === "dfn_open") {
|
|
21786
|
+
depth--;
|
|
21787
|
+
if (depth === 0) return j;
|
|
21788
|
+
}
|
|
21789
|
+
}
|
|
21790
|
+
return -1;
|
|
21791
|
+
}
|
|
21792
|
+
function skipNonContent(tokens, from) {
|
|
21793
|
+
let pos = from;
|
|
21794
|
+
while (pos < tokens.length) {
|
|
21795
|
+
if (isLintMarker(tokens[pos])) {
|
|
21796
|
+
pos++;
|
|
21797
|
+
continue;
|
|
21798
|
+
}
|
|
21799
|
+
if (tokens[pos].type === "dfn_open" && isFromInclude(tokens[pos])) {
|
|
21800
|
+
pos = skipDfnPair(tokens, pos);
|
|
21801
|
+
continue;
|
|
21802
|
+
}
|
|
21803
|
+
break;
|
|
21804
|
+
}
|
|
21805
|
+
return pos;
|
|
21806
|
+
}
|
|
21807
|
+
function skipDfnPair(tokens, from) {
|
|
21808
|
+
let depth = 1;
|
|
21809
|
+
let pos = from + 1;
|
|
21810
|
+
while (pos < tokens.length && depth > 0) {
|
|
21811
|
+
if (tokens[pos].type === "dfn_open") depth++;
|
|
21812
|
+
if (tokens[pos].type === "dfn_close") depth--;
|
|
21813
|
+
pos++;
|
|
21814
|
+
}
|
|
21815
|
+
return pos;
|
|
21816
|
+
}
|
|
21817
|
+
function isLocalDfnClose(tokens, index) {
|
|
21818
|
+
if (tokens[index].type !== "dfn_close") return false;
|
|
21819
|
+
const openIndex = findMatchingDfnOpen(tokens, index);
|
|
21820
|
+
return openIndex < 0 || !isFromInclude(tokens[openIndex]);
|
|
21821
|
+
}
|
|
21822
|
+
function hasLocalDfnOpenAt(tokens, index) {
|
|
21823
|
+
return index < tokens.length && tokens[index].type === "dfn_open" && !isFromInclude(tokens[index]);
|
|
21824
|
+
}
|
|
21769
21825
|
var yfm009 = {
|
|
21770
21826
|
names: ["YFM009", "no-term-definition-in-content"],
|
|
21771
21827
|
description: "Term definition should be placed at the end of file",
|
|
@@ -21777,23 +21833,19 @@ var yfm009 = {
|
|
|
21777
21833
|
if (!config) {
|
|
21778
21834
|
return;
|
|
21779
21835
|
}
|
|
21780
|
-
let lastCloseIndex = -1;
|
|
21781
21836
|
const tokens = params2.parsers.markdownit.tokens;
|
|
21782
21837
|
const size = tokens.length;
|
|
21838
|
+
let lastLocalCloseIndex = -1;
|
|
21783
21839
|
for (let i = 0; i < size; i++) {
|
|
21784
|
-
if (tokens
|
|
21785
|
-
lastCloseIndex = i;
|
|
21786
|
-
}
|
|
21787
|
-
if (tokens[i].type !== "dfn_close") {
|
|
21840
|
+
if (!isLocalDfnClose(tokens, i)) {
|
|
21788
21841
|
continue;
|
|
21789
21842
|
}
|
|
21843
|
+
lastLocalCloseIndex = i;
|
|
21790
21844
|
if (i === size - 1) {
|
|
21791
21845
|
continue;
|
|
21792
21846
|
}
|
|
21793
|
-
|
|
21794
|
-
|
|
21795
|
-
}
|
|
21796
|
-
if (i < size - 2 && tokens[i + 2].type === "dfn_open") {
|
|
21847
|
+
const nextReal = skipNonContent(tokens, i + 1);
|
|
21848
|
+
if (nextReal >= size || hasLocalDfnOpenAt(tokens, nextReal)) {
|
|
21797
21849
|
continue;
|
|
21798
21850
|
}
|
|
21799
21851
|
onError({
|
|
@@ -21801,12 +21853,13 @@ var yfm009 = {
|
|
|
21801
21853
|
detail: "There is a content between term definition. All term defitions should be placed at the end of file."
|
|
21802
21854
|
});
|
|
21803
21855
|
}
|
|
21804
|
-
if (
|
|
21856
|
+
if (lastLocalCloseIndex === -1) {
|
|
21805
21857
|
return;
|
|
21806
21858
|
}
|
|
21807
|
-
|
|
21859
|
+
const tailPos = skipNonContent(tokens, lastLocalCloseIndex + 1);
|
|
21860
|
+
if (tailPos < size) {
|
|
21808
21861
|
onError({
|
|
21809
|
-
lineNumber: ((_b = tokens[
|
|
21862
|
+
lineNumber: ((_b = tokens[lastLocalCloseIndex + 1]) == null ? void 0 : _b.lineNumber) || tokens[lastLocalCloseIndex].lineNumber || 1,
|
|
21810
21863
|
detail: "The file must end with term only."
|
|
21811
21864
|
});
|
|
21812
21865
|
}
|
|
@@ -21866,6 +21919,34 @@ var yfm011 = {
|
|
|
21866
21919
|
}
|
|
21867
21920
|
};
|
|
21868
21921
|
|
|
21922
|
+
// src/rules/yfm018.ts
|
|
21923
|
+
var yfm018 = {
|
|
21924
|
+
names: ["YFM018", "term-definition-from-include"],
|
|
21925
|
+
description: "Term definition comes from an included file",
|
|
21926
|
+
tags: ["term"],
|
|
21927
|
+
parser: "markdownit",
|
|
21928
|
+
function: function YFM018(params2, onError) {
|
|
21929
|
+
const { config } = params2;
|
|
21930
|
+
if (!config) {
|
|
21931
|
+
return;
|
|
21932
|
+
}
|
|
21933
|
+
const tokens = params2.parsers.markdownit.tokens;
|
|
21934
|
+
const size = tokens.length;
|
|
21935
|
+
for (let i = 0; i < size; i++) {
|
|
21936
|
+
if (tokens[i].type !== "dfn_open") {
|
|
21937
|
+
continue;
|
|
21938
|
+
}
|
|
21939
|
+
if (tokens[i].attrGet("from-include") !== "true") {
|
|
21940
|
+
continue;
|
|
21941
|
+
}
|
|
21942
|
+
onError({
|
|
21943
|
+
lineNumber: tokens[i].lineNumber || 1,
|
|
21944
|
+
detail: "Term definition is provided via include. Consider moving it to the end of the page or defining the term locally."
|
|
21945
|
+
});
|
|
21946
|
+
}
|
|
21947
|
+
}
|
|
21948
|
+
};
|
|
21949
|
+
|
|
21869
21950
|
// src/index.ts
|
|
21870
21951
|
async function yfmlint(content3, path3, opts) {
|
|
21871
21952
|
const { lint } = await Promise.resolve().then(() => (init_exports_promise(), exports_promise_exports));
|