]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
po-man: remove unicode dash from manpage NAME section
authorThomas Weißschuh <thomas@t-8ch.de>
Sat, 7 Jan 2023 02:10:27 +0000 (02:10 +0000)
committerThomas Weißschuh <thomas@t-8ch.de>
Sat, 7 Jan 2023 13:28:05 +0000 (13:28 +0000)
Translators seem to like using unicode dashes.
When used in the NAME section of a manpage, asciidoctor will break.
Instead of trying to force all translators to keep this in mind, add an
extension to asciidoctor that takes care of this.

po-man/Makefile.am
tools/Makemodule.am
tools/asciidoctor-unicodeconverter.rb [new file with mode: 0644]

index ea9103877e159383b3e2bf4de528d6ac8330bbc7..c40e74793c9f0df0a359788e0b885d67582a4a69 100644 (file)
@@ -33,7 +33,9 @@ asciidoc_man_cmd = $(ASCIIDOCTOR) \
        -a 'release-version=$(VERSION)' \
        -a 'package-docdir=$(docdir)' \
        -a 'VERSION=$(VERSION)' \
-       -a 'ADJTIME_PATH=$(ADJTIME_PATH)'
+       -a 'ADJTIME_PATH=$(ADJTIME_PATH)' \
+       --load-path '$(top_srcdir)/tools' \
+       --require asciidoctor-unicodeconverter
 
 gen-mans: gen-trans
        @for l in $(PO_LANGS); do \
index 59f9803fc78a3a71792a95af8aff839c548a13c6..dbda62587229a7a84cb8d3ce7d810e8ffff2836a 100644 (file)
@@ -55,4 +55,5 @@ EXTRA_DIST += \
        tools/config-gen.d/non-widechar.conf \
        tools/config-gen.d/non-libmount.conf \
        \
-       tools/asciidoctor-includetracker.rb
+       tools/asciidoctor-includetracker.rb \
+       tools/asciidoctor-unicodeconverter.rb
diff --git a/tools/asciidoctor-unicodeconverter.rb b/tools/asciidoctor-unicodeconverter.rb
new file mode 100644 (file)
index 0000000..344eeb8
--- /dev/null
@@ -0,0 +1,39 @@
+# Copyright (C) 2023 Thomas Weißschuh <thomas@t-8ch.de>
+# Extension for asciidoctor to remove unicode dash in first section of manpage
+
+module UnicodeConverter
+  BEFORE_NAME_SECTION = 1
+  IN_NAME_SECTION = 2
+  AFTER_NAME_SECTION = 3
+
+  class Preprocessor < Asciidoctor::Extensions::Preprocessor
+    def process document, reader
+      lines = reader.read_lines
+      state = BEFORE_NAME_SECTION
+      lines.map! do |line|
+        if state = IN_NAME_SECTION
+          line.sub! " \u2013 ", " - "
+          line.sub! " \u2014 ", " - "
+        end
+
+        if line.start_with? '== '
+          if state == BEFORE_NAME_SECTION
+            state = IN_NAME_SECTION
+          else if state == IN_NAME_SECTION
+            state = AFTER_NAME_SECTION
+          end
+        end
+      end
+
+        line
+      end
+      reader.restore_lines lines
+      reader
+    end
+  end
+
+  Asciidoctor::Extensions.register do
+    preprocessor Preprocessor
+  end
+
+end