Display word etymology if is present
This commit is contained in:
parent
65cf421cbe
commit
40feae7194
|
@ -9,7 +9,7 @@ import {
|
||||||
setupWordEditFormButtons,
|
setupWordEditFormButtons,
|
||||||
} from '../setupListeners/words';
|
} from '../setupListeners/words';
|
||||||
import { getPaginationData } from '../pagination';
|
import { getPaginationData } from '../pagination';
|
||||||
import { getOpenEditForms, translateOrthography, parseReferences } from '../wordManagement';
|
import { getOpenEditForms, translateOrthography, parseReferences, getWordReferenceMarkdown } from '../wordManagement';
|
||||||
import { renderAd } from '../ads';
|
import { renderAd } from '../ads';
|
||||||
import { getPublicLink } from '../account/utilities';
|
import { getPublicLink } from '../account/utilities';
|
||||||
import { renderPartsOfSpeech } from './details';
|
import { renderPartsOfSpeech } from './details';
|
||||||
|
@ -60,6 +60,8 @@ export function renderWords() {
|
||||||
partOfSpeech: removeTags(originalWord.partOfSpeech),
|
partOfSpeech: removeTags(originalWord.partOfSpeech),
|
||||||
definition: removeTags(originalWord.definition),
|
definition: removeTags(originalWord.definition),
|
||||||
details: parseReferences(removeTags(originalWord.details)),
|
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,
|
wordId: originalWord.wordId,
|
||||||
});
|
});
|
||||||
const homonymnNumber = getHomonymnNumber(originalWord);
|
const homonymnNumber = getHomonymnNumber(originalWord);
|
||||||
|
@ -86,6 +88,11 @@ export function renderWords() {
|
||||||
<dd class="details">
|
<dd class="details">
|
||||||
${md(word.details)}
|
${md(word.details)}
|
||||||
</dd>
|
</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>
|
</dl>
|
||||||
</article>`;
|
</article>`;
|
||||||
});
|
});
|
||||||
|
|
|
@ -116,7 +116,17 @@ export function parseReferences(detailsMarkdown) {
|
||||||
const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
|
const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
|
||||||
if (references && Array.isArray(references)) {
|
if (references && Array.isArray(references)) {
|
||||||
new Set(references).forEach(reference => {
|
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;
|
let homonymn = 0;
|
||||||
|
|
||||||
if (wordToFind.includes(':')) {
|
if (wordToFind.includes(':')) {
|
||||||
|
@ -147,12 +157,10 @@ export function parseReferences(detailsMarkdown) {
|
||||||
homonymn = 1;
|
homonymn = 1;
|
||||||
}
|
}
|
||||||
const homonymnSubHTML = homonymnIndexes.length > 1 && homonymn - 1 >= 0 ? '<sub>' + homonymn.toString() + '</sub>' : '';
|
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>`;
|
return `<span class="word-reference">[<span class="orthographic-translation">${translateOrthography(wordToFind)}</span>${homonymnSubHTML}](#${existingWordId})</span>`;
|
||||||
detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
return reference;
|
||||||
return detailsMarkdown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function expandAdvancedForm(id = false) {
|
export function expandAdvancedForm(id = false) {
|
||||||
|
|
Loading…
Reference in New Issue