summaryrefslogtreecommitdiffstats
path: root/tools/asciidoctor-unicodeconverter.rb
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
commitcfe5e3905201349e9cf3f95d52ff4bd100bde37d (patch)
treed0baf160cbee3195249d095f85e52d20c21acf02 /tools/asciidoctor-unicodeconverter.rb
parentInitial commit. (diff)
downloadutil-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.tar.xz
util-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.zip
Adding upstream version 2.39.3.upstream/2.39.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/asciidoctor-unicodeconverter.rb')
-rw-r--r--tools/asciidoctor-unicodeconverter.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/asciidoctor-unicodeconverter.rb b/tools/asciidoctor-unicodeconverter.rb
new file mode 100644
index 0000000..7b90bd3
--- /dev/null
+++ b/tools/asciidoctor-unicodeconverter.rb
@@ -0,0 +1,50 @@
+# Copyright (C) 2023 Thomas Weißschuh <thomas@t-8ch.de>
+# Extension for asciidoctor to remove unicode dash in first section of manpage
+
+require 'asciidoctor/extensions'
+
+module UnicodeConverter
+ BEFORE_NAME_SECTION = 1
+ IN_NAME_SECTION = 2
+ AFTER_NAME_SECTION = 3
+
+ class Preprocessor < Asciidoctor::Extensions::Preprocessor
+ include Asciidoctor::Logging
+
+ def process document, reader
+ lines = reader.read_lines
+ state = BEFORE_NAME_SECTION
+ command = document.attributes['docname'].rpartition('.')[0]
+ lines.map! do |line|
+ if state == IN_NAME_SECTION
+ if line.sub! " \u2013 ", " - " or line.sub! " \u2014 ", " - "
+ logger.warn "replacing unicode dash in name section of #{document.attributes['docfile']}"
+ end
+
+ if line.start_with? command and not line.include? ',' and not line.start_with? "#{command} - "
+ logger.warn "adding dash to name section of #{document.attributes['docfile']}"
+ line.sub! command, "#{command} - "
+ end
+ 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