Skip to content

Commit

Permalink
fix: Linker sometimes adds '...' when there are no alternative defini…
Browse files Browse the repository at this point in the history
…tions (Closes #148)
  • Loading branch information
about-code committed Feb 14, 2021
1 parent 684648f commit 24f26c0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ function getLinkifyVisitor(context, vFile, indexEntriesMap) {
*/
function linkifyAst(paragraphNode, headingNode, indexEntrySet, context, vFile) {
const {linking} = context.conf;
const skipOnTooMuchAlternativeDefs = Math.sign(linking.limitByAlternatives) < 0;
const maxAlternativeDefs = Math.abs(linking.limitByAlternatives);
const countDefinitions = indexEntrySet.length;
const maxAlternativeDefs = linking.limitByAlternatives;
const hasAlternativeDefs = countDefinitions > 1;
const hasMoreAlternativeDefs = countDefinitions > maxAlternativeDefs;
const countAlternativeDefs = countDefinitions - 1;
const hasAlternativeDefs = countAlternativeDefs > 0;
const hasMoreAlternativeDefs = countAlternativeDefs > maxAlternativeDefs;
const termNodes = indexEntrySet.map(e => e.node);
const termNode = termNodes[0];
const maxReplacements = (linking.mentions === "first-in-paragraph") ? 1 : Infinity;
Expand All @@ -136,13 +138,12 @@ function linkifyAst(paragraphNode, headingNode, indexEntrySet, context, vFile) {
if (linking.headingDepths[termNode.headingDepth] !== true) {
return;
}

if (maxAlternativeDefs < 0 && countDefinitions > Math.abs(maxAlternativeDefs)) {
if (skipOnTooMuchAlternativeDefs && countAlternativeDefs >= maxAlternativeDefs) {
return;
}
if (hasAlternativeDefs) {
if (hasAlternativeDefs && maxAlternativeDefs !== 0) {
linkNodes = termNodes
.filter((e, idx) => idx < maxAlternativeDefs)
.filter((e, idx) => idx > 0 && idx <= maxAlternativeDefs)
.map(getSuperscriptLinkMapper(context, vFile));
if (hasMoreAlternativeDefs) {
linkNodes.push(html("<sup>...</sup>"));
Expand Down Expand Up @@ -186,7 +187,7 @@ function getSuperscriptLinkMapper(context, vFile) {
const shortDesc = tNode.getShortDescription();
const glossUrl = resolveGlossaryUrl(context, vFile, tNode);
return link(glossUrl, shortDesc,
html(j === 0 ? `<sup>${j+1})</sup>` : `<sup> ${j+1})</sup>`)
html(j === 0 ? `<sup>${j+2})</sup>` : `<sup> ${j+2})</sup>`)
);
};
}
Expand Down

0 comments on commit 24f26c0

Please sign in to comment.