Skip to content

Commit

Permalink
Fix splitting to handle sometimes /r/n
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jan 19, 2024
1 parent 1a7349f commit 204bf67
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/util/parseEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ function parseEntry(entry) {
const tags = parseTags(entryLines);

const explanationsText = entryLines.join('\n');
const explanationsTexts = explanationsText.split('\r\n----\r\n').map((text) => {
return text;
});
const explanationsTexts = explanationsText
.split(/^\-\-\-\-$/gm)
.map((text) => {
return text;
});

/**
* @type {Gloss[]}
*/
const glosses = [];
for (const explanationText of explanationsTexts) {
glosses.push(parseGloss(explanationText));
for (const text of explanationsTexts) {
glosses.push(parseGloss(text));
}

return {
Expand Down Expand Up @@ -101,8 +103,8 @@ function parseTags(entryLines) {
*/
function parseGloss(entryText) {
// Remove first line explanations
entryText = entryText.replace('<explanation>\r\n', '');
const [explanationText, ...examplesTexts] = entryText.split('\r\n<eg>\r\n');
entryText = entryText.replace('<explanation>\n', '');
const [explanationText, ...examplesTexts] = entryText.split(/^<eg>$/gm);

/**
* @type {LanguageData}
Expand Down Expand Up @@ -131,7 +133,7 @@ function parseLanguageData(text) {
* @type {LanguageData}
*/
const languageData = {};
const lines = text.split('\r\n');
const lines = text.split('\n');
let currentLang = '';
let currentLangData = '';
for (const line of lines) {
Expand Down

0 comments on commit 204bf67

Please sign in to comment.