@ng-doc/utils 16.1.1 → 16.2.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.
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { NgDocHeading } from '@ng-doc/core';
|
|
2
|
-
import {
|
|
2
|
+
import { AddKeyword, GetKeyword } from './plugins/keywords.plugin';
|
|
3
3
|
export interface NgDocHtmlPostProcessorConfig {
|
|
4
4
|
headings?: NgDocHeading[];
|
|
5
5
|
route?: string;
|
|
6
|
-
addUsedKeyword?:
|
|
6
|
+
addUsedKeyword?: AddKeyword;
|
|
7
|
+
addPotentialKeyword?: AddKeyword;
|
|
7
8
|
getKeyword?: GetKeyword;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { NgDocKeyword } from '@ng-doc/core/interfaces';
|
|
2
2
|
import { Element } from 'hast';
|
|
3
|
-
export type
|
|
3
|
+
export type AddKeyword = (keyword: string) => void;
|
|
4
4
|
export type GetKeyword = (keyword: string) => NgDocKeyword | undefined;
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
7
7
|
* @param entityStore
|
|
8
8
|
* @param entity
|
|
9
9
|
* @param addUsedKeyword
|
|
10
|
+
* @param addPotentialKeyword
|
|
10
11
|
* @param getKeyword
|
|
11
12
|
*/
|
|
12
|
-
export default function keywordsPlugin(addUsedKeyword?:
|
|
13
|
+
export default function keywordsPlugin(addUsedKeyword?: AddKeyword, addPotentialKeyword?: AddKeyword, getKeyword?: GetKeyword): (tree: Element) => void;
|
package/index.js
CHANGED
|
@@ -15025,9 +15025,10 @@ const languages = ['typescript', 'ts'];
|
|
|
15025
15025
|
* @param entityStore
|
|
15026
15026
|
* @param entity
|
|
15027
15027
|
* @param addUsedKeyword
|
|
15028
|
+
* @param addPotentialKeyword
|
|
15028
15029
|
* @param getKeyword
|
|
15029
15030
|
*/
|
|
15030
|
-
function keywordsPlugin(addUsedKeyword, getKeyword) {
|
|
15031
|
+
function keywordsPlugin(addUsedKeyword, addPotentialKeyword, getKeyword) {
|
|
15031
15032
|
return tree => visitParents(tree, 'element', (node, ancestors) => {
|
|
15032
15033
|
if (!isCodeNode(node)) {
|
|
15033
15034
|
return;
|
|
@@ -15036,13 +15037,13 @@ function keywordsPlugin(addUsedKeyword, getKeyword) {
|
|
|
15036
15037
|
const lang = node.properties?.['lang']?.toString() || '';
|
|
15037
15038
|
if (isInlineCode || languages.includes(lang)) {
|
|
15038
15039
|
visitParents(node, 'text', (node, ancestors) => {
|
|
15039
|
-
if (hasLinkAncestor(ancestors) || !getKeyword || !addUsedKeyword) {
|
|
15040
|
+
if (hasLinkAncestor(ancestors) || !getKeyword || !addUsedKeyword || !addPotentialKeyword) {
|
|
15040
15041
|
return;
|
|
15041
15042
|
}
|
|
15042
15043
|
const parent = ancestors[ancestors.length - 1];
|
|
15043
15044
|
const index = parent.children.indexOf(node);
|
|
15044
15045
|
// Parse the text for words that we can convert to links
|
|
15045
|
-
const nodes = getNodes(node, parent, isInlineCode, addUsedKeyword, getKeyword);
|
|
15046
|
+
const nodes = getNodes(node, parent, isInlineCode, addUsedKeyword, addPotentialKeyword, getKeyword);
|
|
15046
15047
|
// Replace the text node with the links and leftover text nodes
|
|
15047
15048
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
15048
15049
|
// @ts-ignore
|
|
@@ -15061,15 +15062,16 @@ function keywordsPlugin(addUsedKeyword, getKeyword) {
|
|
|
15061
15062
|
* @param inlineLink
|
|
15062
15063
|
* @param e
|
|
15063
15064
|
* @param addUsedKeyword
|
|
15065
|
+
* @param addPotentialKeyword
|
|
15064
15066
|
* @param getKeyword
|
|
15065
15067
|
*/
|
|
15066
|
-
function getNodes(node, parent, inlineLink, addUsedKeyword, getKeyword) {
|
|
15068
|
+
function getNodes(node, parent, inlineLink, addUsedKeyword, addPotentialKeyword, getKeyword) {
|
|
15067
15069
|
const KeywordRegExp = /([A-Za-z0-9_.-/*]+)/;
|
|
15068
15070
|
return toString(node).split(KeywordRegExp).filter(word => word.length).map(word => {
|
|
15071
|
+
const keyword = getKeyword(word);
|
|
15069
15072
|
if (KeywordRegExp.test(word)) {
|
|
15070
|
-
addUsedKeyword(word);
|
|
15073
|
+
keyword ? addUsedKeyword(word) : addPotentialKeyword(word);
|
|
15071
15074
|
}
|
|
15072
|
-
const keyword = getKeyword(word);
|
|
15073
15075
|
if (inlineLink && /^\*\w+/gm.test(word) && !keyword) {
|
|
15074
15076
|
console.log(`\n${chalk.blue('NgDoc:')} ${chalk.yellow(`Keyword "${word}" is missing.`)}`);
|
|
15075
15077
|
}
|
|
@@ -15189,7 +15191,7 @@ async function htmlPostProcessor(html, config) {
|
|
|
15189
15191
|
languages: {
|
|
15190
15192
|
twig
|
|
15191
15193
|
}
|
|
15192
|
-
}).use(sluggerPlugin, config.headings).use(rehypeMinifyWhitespace).use(autolinkHeading, config.route).use(keywordsPlugin, config.addUsedKeyword, config.getKeyword).use(markElementsPlugin).use(markCodeBlocksPlugin).process(html).then(file => file.toString());
|
|
15194
|
+
}).use(sluggerPlugin, config.headings).use(rehypeMinifyWhitespace).use(autolinkHeading, config.route).use(keywordsPlugin, config.addUsedKeyword, config.addPotentialKeyword, config.getKeyword).use(markElementsPlugin).use(markCodeBlocksPlugin).process(html).then(file => file.toString());
|
|
15193
15195
|
}
|
|
15194
15196
|
|
|
15195
15197
|
/**
|