Created
November 3, 2020 17:54
-
-
Save steven-r/581728c7ff797787f1d8967564413897 to your computer and use it in GitHub Desktop.
asciidoctor extension to replace patterns to enable german quotes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this extension can be accessed via the
-r
option in asciidoctor: