diff --git a/package-lock.json b/package-lock.json index 70dabc1..cb4f4d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "license": "MIT", "dependencies": { - "@digitallinguistics/scription2dlx": "^0.12.3" + "@digitallinguistics/scription2dlx": "^0.13.1" }, "devDependencies": { "@digitallinguistics/eslint-config": "^0.3.0", @@ -43,9 +43,9 @@ } }, "node_modules/@digitallinguistics/scription2dlx": { - "version": "0.12.3", - "resolved": "https://registry.npmjs.org/@digitallinguistics/scription2dlx/-/scription2dlx-0.12.3.tgz", - "integrity": "sha512-i9qY4nYKLu2k3ThATp+Ax5hCX67ApdTR12NY9FKIYQlgjtCY433lV9DW5eU5cuY/Z8mfyJwSqQ1x2iLELP+ijg==" + "version": "0.13.1", + "resolved": "https://registry.npmjs.org/@digitallinguistics/scription2dlx/-/scription2dlx-0.13.1.tgz", + "integrity": "sha512-gLC7fYKrCD0xud9D4eVYWaLgYG5viiYO66kogOZtx9Znols6lMf9AOy2BmukSOJDcN2hdZz1EAqJKQ8PKw5hNw==" }, "node_modules/@esbuild/android-arm": { "version": "0.19.5", @@ -2486,9 +2486,9 @@ "requires": {} }, "@digitallinguistics/scription2dlx": { - "version": "0.12.3", - "resolved": "https://registry.npmjs.org/@digitallinguistics/scription2dlx/-/scription2dlx-0.12.3.tgz", - "integrity": "sha512-i9qY4nYKLu2k3ThATp+Ax5hCX67ApdTR12NY9FKIYQlgjtCY433lV9DW5eU5cuY/Z8mfyJwSqQ1x2iLELP+ijg==" + "version": "0.13.1", + "resolved": "https://registry.npmjs.org/@digitallinguistics/scription2dlx/-/scription2dlx-0.13.1.tgz", + "integrity": "sha512-gLC7fYKrCD0xud9D4eVYWaLgYG5viiYO66kogOZtx9Znols6lMf9AOy2BmukSOJDcN2hdZz1EAqJKQ8PKw5hNw==" }, "@esbuild/android-arm": { "version": "0.19.5", diff --git a/package.json b/package.json index 84a1a3e..7aa9010 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,12 @@ "stop-only": "stop-only --folder src", "test": "mocha test/*.test.js" }, + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@digitallinguistics/scription2dlx": "^0.13.1" + }, "devDependencies": { "@digitallinguistics/eslint-config": "^0.3.0", "@web/parse5-utils": "^2.0.2", @@ -40,11 +46,5 @@ "mocha": "^10.2.0", "parse5": "^7.1.2", "stop-only": "^3.3.1" - }, - "publishConfig": { - "access": "public" - }, - "dependencies": { - "@digitallinguistics/scription2dlx": "^0.12.3" } } diff --git a/src/lines/translation.js b/src/lines/translation.js index 2b4db73..815b6fc 100644 --- a/src/lines/translation.js +++ b/src/lines/translation.js @@ -1,14 +1,16 @@ +import addEmphasis from '../utilities/addEmphasis.js' + export default function createTranslation(data) { if (typeof data === `string`) { - return `

${ data }

` + return `

${ addEmphasis(data) }

` } let html = `` for (const lang in data) { const tln = data[lang] - html += `

${ tln }

` + html += `

${ addEmphasis(tln) }

` } return html diff --git a/src/utilities/addEmphasis.js b/src/utilities/addEmphasis.js new file mode 100644 index 0000000..4bb3844 --- /dev/null +++ b/src/utilities/addEmphasis.js @@ -0,0 +1,5 @@ +const emRegExp = /\*(?.*)\*/gsu + +export default function addEmphasis(text) { + return text.replaceAll(emRegExp, `$`) +} diff --git a/test/lines.test.js b/test/lines.test.js index d3b62bc..f1ef1a3 100644 --- a/test/lines.test.js +++ b/test/lines.test.js @@ -1,31 +1,65 @@ import { expect } from 'chai' import findElementByClass from './utilities/findElementByClass.js' import findElementsByClass from './utilities/findElementsByClass.js' -import { getAttribute } from '@web/parse5-utils' import { getTextContent } from '../node_modules/@web/parse5-utils/src/index.js' import parse from './utilities/convertAndParse.js' -import parseClassString from './utilities/parseClassString.js' + +import { + findElement, + getAttribute, + getTagName, +} from '@web/parse5-utils' import { ChitimachaText, OldLatin, Swahili } from '../samples/data/data.js' describe(`lines`, function() { - it(`free translation`, function() { + describe(`free translation`, function() { + + it(`renders`, function() { + + const { dom } = parse(OldLatin) + const tln = findElementsByClass(dom, `tln`) + + expect(tln).to.have.length(2) + + const [lat, eng] = tln + + expect(getAttribute(lat, `lang`)).to.equal(`lat`) + expect(getAttribute(eng, `lang`)).to.equal(`eng`) + expect(getTextContent(lat)).to.include(`mittit`) + expect(getTextContent(eng)).to.include(`sends`) + + }) - const { dom } = parse(OldLatin) - const tln = findElementsByClass(dom, `tln`) + it(`renders with emphasis`, function() { - expect(tln).to.have.length(2) + // Mandinka, from ex. 2 of your dissertation + const scription = ` + \\txn *Kuuráŋ*o mâŋ díyaa. + \\m *kuuráŋ*-o mâŋ díyaa + \\gl *sick*-def pfv.neg pleasant + \\tln *Sickness* is not pleasant. + \\s Creissels 2017: 46 + + \\txn Díndíŋo máŋ *kuraŋ*. + \\m díndíŋ-o máŋ *kuraŋ* + \\gl child-def pfv.neg *sick* + \\tln The child is not *sick*. + \\s Creissels 2017: 46 + ` - const [lat, eng] = tln + const { dom } = parse(scription) + const tln = findElementByClass(dom, `tln`) + const b = findElement(tln, el => getTagName(el) === `b`) - expect(getAttribute(lat, `lang`)).to.equal(`lat`) - expect(getAttribute(eng, `lang`)).to.equal(`eng`) - expect(getTextContent(lat)).to.include(`mittit`) - expect(getTextContent(eng)).to.include(`sends`) + expect(getTextContent(b)).to.equal(`Sickness`) + + }) }) + it(`literal translation`, function() { const scription = `