Skip to content

Commit

Permalink
NEW: Support different types of emphasis (#63)
Browse files Browse the repository at this point in the history
closes #63
  • Loading branch information
dwhieb committed Mar 16, 2024
1 parent 77b61ff commit 6092676
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ const options = {
}
```

You can apply three different types of emphasis to the data:

| Scription | HTML Output | Renders As |
| ------------ | ----------------------- | --------------------- |
| `***text***` | `<strong>text</strong>` | <strong>text</strong> |
| `**text**` | `<em>text</em>` | <em>text</em> |
| `*text*` | `<b>text</b>` | <b>text</b> |
| `_text_` | `<u>text</u>` | <u>text</u> |

### Additional Notes

- The speaker (`\sp`) and source (`\s`) data are combined into a single element strutured as follows: `<p class=ex-source>{speaker} ({source})</p>`.
Expand Down
11 changes: 9 additions & 2 deletions src/utilities/addEmphasis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const emRegExp = /\*(?<text>.*?)\*/gsu
const strongRegExp = /\*{3}(?<text>.*?)\*{3}/gsu
const emRegExp = /\*{2}(?<text>.*?)\*{2}/gsu
const bRegExp = /\*(?<text>.*?)\*/gsu
const uRegExp = /_(?<text>.*?)_/gsu

export default function addEmphasis(text) {
return text.replaceAll(emRegExp, `<b>$<text></b>`)
return text
.replaceAll(strongRegExp, `<strong>$<text></strong>`)
.replaceAll(emRegExp, `<em>$<text></em>`)
.replaceAll(bRegExp, `<b>$<text></b>`)
.replaceAll(uRegExp, `<u>$<text></u>`)
}

0 comments on commit 6092676

Please sign in to comment.