aboutsummaryrefslogtreecommitdiff
path: root/_extensions/js/nobreaks/nobreaks.lua
blob: c3f0e7ddbb2c21ebf83686b43ff3b65fcd420be6 (plain)
  1. --- nobreaks - avoid linebreak between a number and a unit or quantifier
  2. ---
  3. --- SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  4. --- SPDX-License-Identifier: GPL-3.0-or-later
  5. local non_breaking_space = pandoc.Str("\u{00A0}")
  6. function Para(el)
  7. for i = 1, #el.content - 1 do
  8. if el.content[i].t == "Space" then
  9. local el_prev = el.content[i - 1]
  10. local el_next = el.content[i + 1]
  11. if el_prev and el_next
  12. and el_prev.t == "Str" and el_next.t == "Str"
  13. and string.match(el_prev.text, "%d$")
  14. and string.match(el_next.text, "^[%a%%§°Ωμµ]")
  15. then
  16. el.content[i] = non_breaking_space
  17. end
  18. end
  19. end
  20. return el
  21. end