@ng-doc/utils 16.4.3 → 16.5.0-beta.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/html/helpers/attr-value.d.ts +7 -0
- package/html/helpers/index.d.ts +1 -0
- package/index.js +27 -16
- package/package.json +1 -1
package/html/helpers/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -14701,6 +14701,16 @@ function toResult(value) {
|
|
|
14701
14701
|
return [value]
|
|
14702
14702
|
}
|
|
14703
14703
|
|
|
14704
|
+
/**
|
|
14705
|
+
*
|
|
14706
|
+
* @param node
|
|
14707
|
+
* @param attr
|
|
14708
|
+
*/
|
|
14709
|
+
function attrValue(node, attr) {
|
|
14710
|
+
const attrKey = attr.toLowerCase();
|
|
14711
|
+
return node.properties?.[attrKey] ? String(node.properties[attrKey]) : undefined;
|
|
14712
|
+
}
|
|
14713
|
+
|
|
14704
14714
|
/**
|
|
14705
14715
|
*
|
|
14706
14716
|
* @param node
|
|
@@ -14771,8 +14781,8 @@ function keywordsPlugin(config) {
|
|
|
14771
14781
|
* @param config
|
|
14772
14782
|
*/
|
|
14773
14783
|
function getNodes(node, parent, inlineLink, config) {
|
|
14774
|
-
const KeywordRegExp = /([A-Za-z0-9_
|
|
14775
|
-
const keywordAnchorRegexp = /^(?<keyword>[A-Za-z0-9_
|
|
14784
|
+
const KeywordRegExp = /([*A-Za-z0-9_$@]+[.#]?[A-Za-z0-9_-]+)/g;
|
|
14785
|
+
const keywordAnchorRegexp = /^(?<keyword>[*A-Za-z0-9_$@]+)((?<delimiter>[.#])(?<anchor>[A-Za-z0-9_-]+))?$/;
|
|
14776
14786
|
const {
|
|
14777
14787
|
addUsedKeyword,
|
|
14778
14788
|
addPotentialKeyword,
|
|
@@ -14784,8 +14794,7 @@ function getNodes(node, parent, inlineLink, config) {
|
|
|
14784
14794
|
}
|
|
14785
14795
|
return toString(node).split(KeywordRegExp).filter(word => word.length).map(word => {
|
|
14786
14796
|
const match = word.match(keywordAnchorRegexp);
|
|
14787
|
-
const
|
|
14788
|
-
const keyword = getKeyword(formattedWord);
|
|
14797
|
+
const keyword = getKeyword(word);
|
|
14789
14798
|
const rootKeyword = getKeyword(match?.groups?.['keyword'] || '');
|
|
14790
14799
|
if (keywordAnchorRegexp.test(word)) {
|
|
14791
14800
|
keyword ? addUsedKeyword(word) : addPotentialKeyword(word);
|
|
@@ -14809,7 +14818,7 @@ function getNodes(node, parent, inlineLink, config) {
|
|
|
14809
14818
|
parent.properties['class'] = [NG_DOC_ELEMENT, 'ng-doc-code-with-link'];
|
|
14810
14819
|
}
|
|
14811
14820
|
// Add link inside the code if it's a link to the API entity
|
|
14812
|
-
return keyword ? createLinkNode(inlineLink ? keyword.title : word, keyword.path, keyword.type) : {
|
|
14821
|
+
return keyword ? createLinkNode(inlineLink ? keyword.title : word, keyword.path, keyword.type, keyword.description) : {
|
|
14813
14822
|
type: 'text',
|
|
14814
14823
|
value: word
|
|
14815
14824
|
};
|
|
@@ -14820,16 +14829,17 @@ function getNodes(node, parent, inlineLink, config) {
|
|
|
14820
14829
|
* @param text
|
|
14821
14830
|
* @param href
|
|
14822
14831
|
* @param type
|
|
14823
|
-
* @param
|
|
14832
|
+
* @param description
|
|
14824
14833
|
*/
|
|
14825
|
-
function createLinkNode(text, href, type) {
|
|
14834
|
+
function createLinkNode(text, href, type, description) {
|
|
14826
14835
|
return {
|
|
14827
14836
|
type: 'element',
|
|
14828
14837
|
tagName: 'a',
|
|
14829
14838
|
properties: {
|
|
14830
14839
|
href: href,
|
|
14831
14840
|
class: ['ng-doc-code-anchor', NG_DOC_ELEMENT],
|
|
14832
|
-
'data-link-type': type
|
|
14841
|
+
'data-link-type': type,
|
|
14842
|
+
ngDocTooltip: description
|
|
14833
14843
|
},
|
|
14834
14844
|
children: [{
|
|
14835
14845
|
type: 'text',
|
|
@@ -15194,17 +15204,18 @@ function sluggerPlugin(addAnchor, headings) {
|
|
|
15194
15204
|
slugger.reset();
|
|
15195
15205
|
visit(tree, 'element', node => {
|
|
15196
15206
|
const isHeading = headingRank(node) && !hasProperty(node, 'id') && headings?.includes(node.tagName.toLowerCase());
|
|
15197
|
-
const
|
|
15198
|
-
const
|
|
15207
|
+
const attrSlug = attrValue(node, 'dataSlug');
|
|
15208
|
+
const attrSlugTitle = attrValue(node, 'dataSlugTitle');
|
|
15209
|
+
const attrSlugType = attrValue(node, 'dataSlugType');
|
|
15210
|
+
const dataToSlug = isHeading ? toString(node) : attrSlug;
|
|
15199
15211
|
if (dataToSlug) {
|
|
15200
15212
|
if (node.properties) {
|
|
15201
|
-
const
|
|
15202
|
-
|
|
15203
|
-
node.properties['id'] = slug;
|
|
15213
|
+
const id = attrSlug && attrSlugType === 'member' ? attrSlug : slugger.slug(dataToSlug);
|
|
15214
|
+
node.properties['id'] = id;
|
|
15204
15215
|
addAnchor({
|
|
15205
|
-
anchor:
|
|
15206
|
-
title:
|
|
15207
|
-
type: isHeading &&
|
|
15216
|
+
anchor: id,
|
|
15217
|
+
title: attrSlugTitle || dataToSlug,
|
|
15218
|
+
type: isHeading && attrSlugType !== 'member' || attrSlug && attrSlugType === 'heading' ? 'heading' : 'member'
|
|
15208
15219
|
});
|
|
15209
15220
|
}
|
|
15210
15221
|
}
|