| 1 |
/** |
| 2 |
* Replaces double asterisks with `<strong>` tags. |
| 3 |
* |
| 4 |
* @param {string} text |
| 5 |
* @returns {string} |
| 6 |
*/ |
| 7 |
export function transformStrong(text) { |
| 8 |
// Keep track of whether we're inside a <strong> tag. |
| 9 |
let startingTag = false; |
| 10 |
|
| 11 |
return text.replaceAll('**', () => { |
| 12 |
// Reverse the starting tag state to determine the current state. |
| 13 |
startingTag = !startingTag; |
| 14 |
// Return the appropriate tag. |
| 15 |
return startingTag ? '<strong>' : '</strong>'; |
| 16 |
}); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Replaces double asterisks with `<em>` tags. |
| 21 |
* |
| 22 |
* @param {string} text |
| 23 |
* @returns {string} |
| 24 |
*/ |
| 25 |
export function transformEmphasis(text) { |
| 26 |
// Keep track of whether we're inside an <em> tag. |
| 27 |
let startingTag = false; |
| 28 |
|
| 29 |
return text.replaceAll('**', () => { |
| 30 |
// Reverse the starting tag state to determine the current state. |
| 31 |
startingTag = !startingTag; |
| 32 |
// Return the appropriate tag. |
| 33 |
return startingTag ? '<em>' : '</em>'; |
| 34 |
}); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Get an asset URL. |
| 39 |
* |
| 40 |
* @param {string} filename (without leading slash). |
| 41 |
* @returns {string} asset URL |
| 42 |
*/ |
| 43 |
export const assetUrl = (filename) => `${window.GiveAddons.assetsUrl}${filename}`; |
| 44 |
|