Skip to content

Instantly share code, notes, and snippets.

@steven-r
Created November 3, 2020 17:54
Show Gist options
  • Save steven-r/581728c7ff797787f1d8967564413897 to your computer and use it in GitHub Desktop.
Save steven-r/581728c7ff797787f1d8967564413897 to your computer and use it in GitHub Desktop.
asciidoctor extension to replace patterns to enable german quotes
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
MAP_CHARS = {
'@,,' => '„',
'@,' => '‚',
'@´´' => '“',
'@´' => '‘',
};
class ReplaceSubsProcessor < Asciidoctor::Extensions::Postprocessor
FindReplacementTokensRx = /@(,,?|´´?)/
def process document, output
output.gsub(FindReplacementTokensRx) { decimal_for_name $& }
end
def decimal_for_name name
if (ref = MAP_CHARS[name])
ref
else
name
end
end
end
Extensions.register :sr_replace_chars do
if (@document.backend === 'html5')
postprocessor ReplaceSubsProcessor
end
end
@steven-r
Copy link
Author

steven-r commented Nov 3, 2020

this extension can be accessed via the -r option in asciidoctor:

asciidoctor -r replace-chars sample.adoc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment