Display word etymology if is present

This commit is contained in:
Robbie Antenesse 2020-05-03 22:28:31 -06:00
parent 65cf421cbe
commit 40feae7194
2 changed files with 48 additions and 33 deletions

View File

@ -9,7 +9,7 @@ import {
setupWordEditFormButtons,
} from '../setupListeners/words';
import { getPaginationData } from '../pagination';
import { getOpenEditForms, translateOrthography, parseReferences } from '../wordManagement';
import { getOpenEditForms, translateOrthography, parseReferences, getWordReferenceMarkdown } from '../wordManagement';
import { renderAd } from '../ads';
import { getPublicLink } from '../account/utilities';
import { renderPartsOfSpeech } from './details';
@ -60,6 +60,8 @@ export function renderWords() {
partOfSpeech: removeTags(originalWord.partOfSpeech),
definition: removeTags(originalWord.definition),
details: parseReferences(removeTags(originalWord.details)),
etymology: typeof originalWord.etymology === 'undefined' || originalWord.etymology.length < 1 ? null
: originalWord.etymology.map(root => getWordReferenceMarkdown(removeTags(root))).join(', '),
wordId: originalWord.wordId,
});
const homonymnNumber = getHomonymnNumber(originalWord);
@ -86,6 +88,11 @@ export function renderWords() {
<dd class="details">
${md(word.details)}
</dd>
${word.etymology === null ? '' : `<hr>
<dt>Etymology <small>(Root Word${originalWord.etymology.length !== 1 ? 's' : ''})</small></dt>
<dd class="etymology">
${md(word.etymology).replace(/<\/?p>/g, '')}
</dd>`}
</dl>
</article>`;
});

View File

@ -116,7 +116,17 @@ export function parseReferences(detailsMarkdown) {
const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
if (references && Array.isArray(references)) {
new Set(references).forEach(reference => {
let wordToFind = reference.replace(/\{\{|\}\}/g, '');
const wordMarkdownLink = getWordReferenceMarkdown(reference);
if (wordMarkdownLink !== reference) {
detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink);
}
});
}
return detailsMarkdown;
}
export function getWordReferenceMarkdown(reference) {
const wordToFind = reference.replace(/\{\{|\}\}/g, '');
let homonymn = 0;
if (wordToFind.includes(':')) {
@ -147,12 +157,10 @@ export function parseReferences(detailsMarkdown) {
homonymn = 1;
}
const homonymnSubHTML = homonymnIndexes.length > 1 && homonymn - 1 >= 0 ? '<sub>' + homonymn.toString() + '</sub>' : '';
const wordMarkdownLink = `<span class="word-reference">[<span class="orthographic-translation">${translateOrthography(wordToFind)}</span>${homonymnSubHTML}](#${existingWordId})</span>`;
detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink);
return `<span class="word-reference">[<span class="orthographic-translation">${translateOrthography(wordToFind)}</span>${homonymnSubHTML}](#${existingWordId})</span>`;
}
});
}
return detailsMarkdown;
return reference;
}
export function expandAdvancedForm(id = false) {