Skip to content

Commit

Permalink
FIX: Glosses not rendering properly
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhieb committed Mar 17, 2024
1 parent 68f1635 commit 7eaaeb7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
32 changes: 32 additions & 0 deletions src/utilities/createGlossLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import addEmphasis from '../utilities/addEmphasis.js'
import replaceHyphens from '../utilities/replaceHyphens.js'

const glossRegExp = /(?<gloss>[1-4]|[A-Z]+)/gv
const numberRegExp = /\b(?<number>sg|du|pl)\b/gv

export default function createGlossLine(
data,
analysisLang,
cssClass,
{ abbreviations, glosses: glossesOption },
) {

const lang = analysisLang ? `lang='${ analysisLang }'` : ``

const wrapGloss = gloss => {
const title = abbreviations[gloss] ? `title='${ abbreviations[gloss] }'` : ``
return `<abbr ${ title }>${ gloss }</abbr>`
}

if (glossesOption === true) {
data = data
.replaceAll(glossRegExp, wrapGloss)
.replaceAll(numberRegExp, wrapGloss)
}

data = replaceHyphens(data)
data = addEmphasis(data)

return `<span class='${ cssClass }' ${ lang }>${ data }</span>`

}
33 changes: 5 additions & 28 deletions src/words/glosses.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
import addEmphasis from '../utilities/addEmphasis.js'
import replaceHyphens from '../utilities/replaceHyphens.js'
import createGlossLine from '../utilities/createGlossLine.js'

const glossRegExp = /(?<gloss>[1-4]|[A-Z]+)/gv
const numberRegExp = /\b(?<number>sg|du|pl)\b/gv

function createGlossLine(glosses, analysisLang, { abbreviations, glosses: glossesOption }) {

const lang = analysisLang ? `lang='${ analysisLang }'` : ``

const wrapGloss = gloss => {
const title = abbreviations[gloss] ? `title='${ abbreviations[gloss] }'` : ``
return `<abbr ${ title }>${ gloss }</abbr>`
}

if (glossesOption === true) {
glosses = glosses
.replaceAll(glossRegExp, wrapGloss)
.replaceAll(numberRegExp, wrapGloss)
}

glosses = replaceHyphens(glosses)
glosses = addEmphasis(glosses)

return `<span class=glosses ${ lang }>${ glosses }</span>`

}
const cssClass = `glosses`

export default function createGlosses(data, options) {


if (!data) return ``

if (typeof data === `string`) {
return createGlossLine(data, options.analysisLang, options)
return createGlossLine(data, options.analysisLang, cssClass, options)
}

let html = ``

for (const lang in data) {
html += createGlossLine(data[lang], lang, options)
html += createGlossLine(data[lang], lang, cssClass, options)
}

return html
Expand Down
12 changes: 6 additions & 6 deletions src/words/literal.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import addEmphasis from '../utilities/addEmphasis.js'
import createGlossLine from '../utilities/createGlossLine.js'

export default function createLiteral(data, { analysisLang }) {
const cssClass = `wlt`

export default function createLiteral(data, options) {

if (!data) return ``

if (typeof data === `string`) {
const lang = analysisLang ? `lang='${ analysisLang }'` : ``
return `<span class=wlt ${ lang }>${ addEmphasis(data) }</span>`
return createGlossLine(data, cssClass, options.analysisLang, options)
}

let html = ``

for (const lang in data) {
const tln = data[lang]
html += `<span class=wlt lang='${ lang }'>${ addEmphasis(tln) }</span>`
html += createGlossLine(data[lang], cssClass, lang, options)
}

return html
Expand Down

0 comments on commit 7eaaeb7

Please sign in to comment.