@redpanda-data/docs-extensions-and-macros 3.6.5 → 3.6.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.
- package/macros/glossary.js +17 -6
- package/package.json +1 -1
package/macros/glossary.js
CHANGED
|
@@ -27,6 +27,11 @@ module.exports.register = function (registry, config = {}) {
|
|
|
27
27
|
|
|
28
28
|
const terms = termFiles.map(file => {
|
|
29
29
|
const content = file.contents.toString()
|
|
30
|
+
// Split content by lines and get the first non-empty line as the title
|
|
31
|
+
const lines = content.split('\n').map(line => line.trim())
|
|
32
|
+
const firstNonEmptyLine = lines.find(line => line.length > 0)
|
|
33
|
+
// Remove leading '=' characters (AsciiDoc syntax) and trim whitespace
|
|
34
|
+
const pageTitle = firstNonEmptyLine ? firstNonEmptyLine.replace(/^=+\s*/, '') : '#'
|
|
30
35
|
const attributes = {}
|
|
31
36
|
|
|
32
37
|
let match
|
|
@@ -50,6 +55,7 @@ module.exports.register = function (registry, config = {}) {
|
|
|
50
55
|
term: attributes['term-name'],
|
|
51
56
|
def: attributes['hover-text'],
|
|
52
57
|
category: attributes['category'] || '',
|
|
58
|
+
pageTitle,
|
|
53
59
|
content
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -76,13 +82,16 @@ module.exports.register = function (registry, config = {}) {
|
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
|
|
79
|
-
//
|
|
80
|
-
const IDRX = /[
|
|
85
|
+
// Characters to replace by '-' in generated idprefix
|
|
86
|
+
const IDRX = /[\/ _.-]+/g
|
|
81
87
|
|
|
82
|
-
function termId
|
|
83
|
-
|
|
88
|
+
function termId(term) {
|
|
89
|
+
// Remove brackets before replacing other characters
|
|
90
|
+
const noBracketsTerm = term.replace(/[\[\]\(\)]/g, '') // Remove brackets
|
|
91
|
+
return noBracketsTerm.toLowerCase().replace(IDRX, '-')
|
|
84
92
|
}
|
|
85
93
|
|
|
94
|
+
|
|
86
95
|
const TRX = /(<[a-z]+)([^>]*>.*)/
|
|
87
96
|
|
|
88
97
|
function glossaryInlineMacro () {
|
|
@@ -91,7 +100,7 @@ module.exports.register = function (registry, config = {}) {
|
|
|
91
100
|
self.named('glossterm')
|
|
92
101
|
//Specifying the regexp allows spaces in the term.
|
|
93
102
|
self.$option('regexp', /glossterm:([^[]+)\[(|.*?[^\\])\]/)
|
|
94
|
-
self.positionalAttributes(['definition', 'customText']);
|
|
103
|
+
self.positionalAttributes(['definition', 'customText']); // Allows for specifying custom link text
|
|
95
104
|
self.process(function (parent, target, attributes) {
|
|
96
105
|
const term = attributes.term || target
|
|
97
106
|
const customText = attributes.customText || term;
|
|
@@ -110,9 +119,11 @@ module.exports.register = function (registry, config = {}) {
|
|
|
110
119
|
}
|
|
111
120
|
const logTerms = document.hasAttribute('glossary-log-terms')
|
|
112
121
|
var definition;
|
|
122
|
+
var pageTitle;
|
|
113
123
|
const index = context.gloss.findIndex((candidate) => candidate.term === term)
|
|
114
124
|
if (index >= 0) {
|
|
115
125
|
definition = context.gloss[index].def
|
|
126
|
+
pageTitle = context.gloss[index].pageTitle
|
|
116
127
|
} else {
|
|
117
128
|
definition = attributes.definition;
|
|
118
129
|
}
|
|
@@ -138,7 +149,7 @@ module.exports.register = function (registry, config = {}) {
|
|
|
138
149
|
if ((termExistsInContext && links) || (links && customLink)) {
|
|
139
150
|
inline = customLink
|
|
140
151
|
? self.createInline(parent, 'anchor', customText, { type: 'link', target: customLink, attributes: { ...attrs, window: '_blank', rel: 'noopener noreferrer' } })
|
|
141
|
-
: self.createInline(parent, 'anchor', customText, { type: 'xref', target: `${glossaryPage}#${termId(
|
|
152
|
+
: self.createInline(parent, 'anchor', customText, { type: 'xref', target: `${glossaryPage}#${termId(pageTitle)}`, reftext: customText, attributes: attrs })
|
|
142
153
|
} else {
|
|
143
154
|
inline = self.createInline(parent, 'quoted', customText, { attributes: attrs })
|
|
144
155
|
}
|