From 08cadfb121b66650360eb445cba5b50d18a9f140 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Wed, 29 May 2019 15:36:44 -0600 Subject: [PATCH] Prevent rendering reference if specified does not exist --- src/js/wordManagement.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/js/wordManagement.js b/src/js/wordManagement.js index 3a2a3c5..2e55dec 100644 --- a/src/js/wordManagement.js +++ b/src/js/wordManagement.js @@ -50,26 +50,30 @@ export function parseReferences(detailsMarkdown, references) { new Set(references).forEach(reference => { let wordToFind = reference.replace(/\{\{|\}\}/g, ''); let homonymn = 0; + if (wordToFind.includes(':')) { const separator = wordToFind.indexOf(':'); homonymn = wordToFind.substr(separator + 1); wordToFind = wordToFind.substring(0, separator); - if (homonymn && homonymn.trim() && !isNaN(parseInt(homonymn.trim()))) { + if (homonymn && homonymn.trim() + && !isNaN(parseInt(homonymn.trim())) && parseInt(homonymn.trim()) > 0) { homonymn = parseInt(homonymn.trim()); } else { - homonymn = 0; + homonymn = false; } } + let existingWordId = false; const homonymnIndexes = getHomonymnIndexes({ name: wordToFind, wordId: -1 }); - console.log(homonymn, homonymnIndexes); - if (homonymn > 0) { + + if (homonymn !== false && homonymn > 0) { if (typeof homonymnIndexes[homonymn - 1] !== 'undefined') { existingWordId = window.currentDictionary.words[homonymnIndexes[homonymn - 1]].wordId; } - } else { + } else if (homonymn !== false) { existingWordId = wordExists(wordToFind, true); } + if (existingWordId !== false) { if (homonymn < 1 && homonymnIndexes.length > 0) { homonymn = 1;