diff options
| author | Jonas Smedegaard <dr@jones.dk> | 2025-05-17 15:49:00 +0200 |
|---|---|---|
| committer | Jonas Smedegaard <dr@jones.dk> | 2025-05-17 15:49:00 +0200 |
| commit | b4125c5a22700f86784b94fdb8587b7cef8d110b (patch) | |
| tree | 1ace25c00d76b7938a97a2fb0a935db371521db5 /_extensions/js/en2em/en2em.lua | |
| parent | 906e9b08450dd56dc5dfc7399fe74b6f2819e7f2 (diff) | |
include and use plugins en2em and nobreaks
Diffstat (limited to '_extensions/js/en2em/en2em.lua')
| -rw-r--r-- | _extensions/js/en2em/en2em.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/_extensions/js/en2em/en2em.lua b/_extensions/js/en2em/en2em.lua new file mode 100644 index 0000000..520474d --- /dev/null +++ b/_extensions/js/en2em/en2em.lua @@ -0,0 +1,38 @@ +--- en2em - replace space-enclosed en-dash with nospace em-dash +--- +--- Some typographical styles, including danish, +--- use en-dash with spaces around to indicate a short pause, +--- whereas others, including some british and american styles, +--- use an em-dash without spaces. +--- +--- This plugin allows to always use en-dash at the source -- +--- which also eases writing with semantic line breaks, like here -- +--- and then convert while rendering as needed. +--- +--- SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk> +--- SPDX-License-Identifier: GPL-3.0-or-later + +local em_dash = pandoc.Str("\u{2014}") +local nothing = pandoc.Str("") + +local TypeIsSpacy = { + Space = true, + SoftBreak = true +} + +function Para(el) + for i = 1, #el.content - 1 do + if el.content[i].t == "Str" and el.content[i].text == "\u{2013}" then + local el_prev = el.content[i - 1] + local el_next = el.content[i + 1] + if el_prev and el_next + and TypeIsSpacy[el_prev.t] and TypeIsSpacy[el_next.t] + then + el.content[i] = em_dash + el.content[i - 1] = nothing + el.content[i + 1] = nothing + end + end + end + return el +end |
