Skip to content

Commit

Permalink
FIX: Number glosses are double-wrapped in <abbr>
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhieb committed Mar 17, 2024
1 parent bb7cc6c commit c166f31
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ Calling the `dlx2html` function returns an HTML string.

## Options

| Option | type | Default | Description |
| --------------- | ------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `abbreviations` | Object | `{}` | An object hash providing the full descriptions of gloss abbreviations, e.g. `"sg"` => `"singular"`. If present, these will be used to populate the `title` attribute of `<abbr>` elements for glosses. Note that the abbreviations are case-sensitive. |
| `analysisLang` | String | undefined | An [IETF language tag][lang-tags] to use as the default value of the `lang` attribute for any data in the analysis language (metadata, literal translation, free translation, glosses, literal word translation). If `undefined`, no `lang` tag is added, which means that browsers will assume that the analysis language is the same as the HTML document. |
| `classes` | Array<String> | `['igl']` | An array of classes to apply to the wrapper element. |
| `glosses` | Boolean | `false` | Options for wrapping glosses in `<abbr>` tags.<br><br>If set to `false` (default), no `<abbr>` tags are added to the glosses.<br><br>If set to `true`, an `<abbr>` tag is wrapped around any glosses in CAPS, any numbers, and any of `sg`, `du`, or `pl` (lowercased). |
| `tag` | String | `'div'` | The HTML tag to wrap each interlinear gloss in. Can also be a custom tag (useful for HTML custom elements). |
| `targetLang` | String | undefined | An [IETF language tag][lang-tags] to use as the default value of the `lang` attribute for any data in the target language. |
| Option | type | Default | Description |
| --------------- | ------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `abbreviations` | Object | `{}` | An object hash providing the full descriptions of gloss abbreviations, e.g. `"sg"` => `"singular"`. If present, these will be used to populate the `title` attribute of `<abbr>` elements for glosses. Note that the abbreviations are case-sensitive. |
| `analysisLang` | String | undefined | An [IETF language tag][lang-tags] to use as the default value of the `lang` attribute for any data in the analysis language (metadata, literal translation, free translation, glosses, literal word translation). If `undefined`, no `lang` tag is added, which means that browsers will assume that the analysis language is the same as the HTML document. |
| `classes` | Array<String> | `['igl']` | An array of classes to apply to the wrapper element. |
| `glosses` | Boolean | `false` | Options for wrapping glosses in `<abbr>` tags.<br><br>If set to `false` (default), no `<abbr>` tags are added to the glosses.<br><br>If set to `true`, an `<abbr>` tag is wrapped around any glosses in CAPS, any numbers, and any of `sg`, `du`, or `pl` (lowercased). Note that text within the `<abbr>` will be converted to lowercase, since by convention glosses are rendered in smallcaps (and uppercase letters display as normal uppercase letters even when in smallcaps). |
| `tag` | String | `'div'` | The HTML tag to wrap each interlinear gloss in. Can also be a custom tag (useful for HTML custom elements). |
| `targetLang` | String | undefined | An [IETF language tag][lang-tags] to use as the default value of the `lang` attribute for any data in the target language. |

## HTML Structure

Expand Down
4 changes: 2 additions & 2 deletions src/utilities/createGlossLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export default function createGlossLine(

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

if (glossesOption === true) {
data = data
.replaceAll(numberRegExp, wrapGloss) // This replacement should come first, in order to avoid double-wrapping of number glosses.
.replaceAll(glossRegExp, wrapGloss)
.replaceAll(numberRegExp, wrapGloss)
}

data = replaceHyphens(data)
Expand Down
22 changes: 20 additions & 2 deletions test/words.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe(`words`, function() {
const { dom } = await parse(scription, { glosses: true })
const abbr = findElement(dom, el => getTagName(el) === `abbr`)

expect(getTextContent(abbr)).to.equal(`ERG`)
expect(getTextContent(abbr)).to.equal(`erg`)

})

Expand Down Expand Up @@ -288,7 +288,7 @@ describe(`words`, function() {

expect(glosses).to.have.length(8)
expect(getTextContent(person)).to.equal(`1`)
expect(getTextContent(num)).to.equal(`SG`)
expect(getTextContent(num)).to.equal(`sg`)

})

Expand All @@ -311,6 +311,24 @@ describe(`words`, function() {

})

it(`option: glosses (lowercase smallcaps)`, async function() {

const scription = `
ninakupenda
ni-na-ku-pend-a
1SG.SUBJ-PRES-2SG.OBJ-love-IND
I love you
`

const { dom, html } = await parse(scription, { glosses: true })
const glosses = findElements(dom, el => getTagName(el) === `abbr`)
const [person, num] = glosses

expect(getTextContent(person)).to.equal(`1`)
expect(getTextContent(num)).to.equal(`sg`)

})

it(`option: abbreviations`, async function() {

const scription = `
Expand Down

0 comments on commit c166f31

Please sign in to comment.