aboutsummaryrefslogtreecommitdiff
path: root/_extensions
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-05-17 15:49:00 +0200
committerJonas Smedegaard <dr@jones.dk>2025-05-17 15:49:00 +0200
commitb4125c5a22700f86784b94fdb8587b7cef8d110b (patch)
tree1ace25c00d76b7938a97a2fb0a935db371521db5 /_extensions
parent906e9b08450dd56dc5dfc7399fe74b6f2819e7f2 (diff)
include and use plugins en2em and nobreaks
Diffstat (limited to '_extensions')
-rw-r--r--_extensions/js/en2em/_extension.yml6
-rw-r--r--_extensions/js/en2em/en2em.lua38
-rw-r--r--_extensions/js/nobreaks/_extension.yml6
-rw-r--r--_extensions/js/nobreaks/nobreaks.lua23
4 files changed, 73 insertions, 0 deletions
diff --git a/_extensions/js/en2em/_extension.yml b/_extensions/js/en2em/_extension.yml
new file mode 100644
index 0000000..fc23c4a
--- /dev/null
+++ b/_extensions/js/en2em/_extension.yml
@@ -0,0 +1,6 @@
+title: En2em
+author: Jonas Smedegaard
+version: 0.0.1
+contributes:
+ filters:
+ - en2em.lua
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
diff --git a/_extensions/js/nobreaks/_extension.yml b/_extensions/js/nobreaks/_extension.yml
new file mode 100644
index 0000000..2522e4e
--- /dev/null
+++ b/_extensions/js/nobreaks/_extension.yml
@@ -0,0 +1,6 @@
+title: NoBreaks
+author: Jonas Smedegaard
+version: 0.0.3
+contributes:
+ filters:
+ - nobreaks.lua
diff --git a/_extensions/js/nobreaks/nobreaks.lua b/_extensions/js/nobreaks/nobreaks.lua
new file mode 100644
index 0000000..c3f0e7d
--- /dev/null
+++ b/_extensions/js/nobreaks/nobreaks.lua
@@ -0,0 +1,23 @@
+--- nobreaks - avoid linebreak between a number and a unit or quantifier
+---
+--- SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
+--- SPDX-License-Identifier: GPL-3.0-or-later
+
+local non_breaking_space = pandoc.Str("\u{00A0}")
+
+function Para(el)
+ for i = 1, #el.content - 1 do
+ if el.content[i].t == "Space" then
+ local el_prev = el.content[i - 1]
+ local el_next = el.content[i + 1]
+ if el_prev and el_next
+ and el_prev.t == "Str" and el_next.t == "Str"
+ and string.match(el_prev.text, "%d$")
+ and string.match(el_next.text, "^[%a%%§°Ωμµ]")
+ then
+ el.content[i] = non_breaking_space
+ end
+ end
+ end
+ return el
+end