Skip to content

Commit

Permalink
NEW: Support emphasis in literal word translations
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhieb committed Jan 2, 2024
1 parent 67fbd69 commit 3029855
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/words/literal.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import addEmphasis from '../utilities/addEmphasis.js'

export default function createLiteral(data, { analysisLang }) {

if (!data) return ``

if (typeof data === `string`) {
const lang = analysisLang ? `lang='${ analysisLang }'` : ``
return `<span class=w-lit ${ lang }>${ data }</span>`
return `<span class=w-lit ${ lang }>${ addEmphasis(data) }</span>`
}

let html = ``

for (const lang in data) {
const tln = data[lang]
html += `<span class=w-lit lang='${ lang }'>${ tln }</span>`
html += `<span class=w-lit lang='${ lang }'>${ addEmphasis(tln) }</span>`
}

return html
Expand Down
26 changes: 20 additions & 6 deletions test/words.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ describe(`words`, function() {

})

it.only(`word transcription supports emphasis`, async function() {
it(`word transcription supports emphasis`, async function() {

const scription = `
\\w *waxdungu* qasi
\\wlt *day-one* man
\\wlt *one.day* man
`

const { dom, html } = await parse(scription)
const b = findElement(dom, el => getTagName(el) === `b`)
const { dom } = await parse(scription)
const b = findElement(dom, el => getTagName(el) === `b`)

expect(getTextContent(b)).to.equal(`waxdungu`)

})

it(`word literal translation (single language)`, async function() {
it(`literal word translation (single language)`, async function() {

const scription = `
\\w waxdungu qasi
Expand All @@ -95,7 +95,7 @@ describe(`words`, function() {

})

it(`word literal translation (single language)`, async function() {
it(`literal word translation (single language)`, async function() {

const scription = `
\\w waxdungu qasi
Expand All @@ -114,4 +114,18 @@ describe(`words`, function() {

})

it(`literal word translation supports emphasis`, async function() {

const scription = `
\\w waxdungu qasi
\\wlt *one.day* man
`

const { dom } = await parse(scription)
const b = findElement(dom, el => getTagName(el) === `b`)

expect(getTextContent(b)).to.equal(`one.day`)

})

})

0 comments on commit 3029855

Please sign in to comment.