Last active
September 21, 2019 09:50
-
-
Save fuka/231470d03b45f7c59bdaa098977332d0 to your computer and use it in GitHub Desktop.
Asciidoctor Diagramでditaaに日本語が含まれていたら後ろに半角スペースを挿入するExtension
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' | |
include Asciidoctor | |
Extensions.register do | |
preprocessor do | |
process do |document, reader| | |
new_lines = [] | |
status = Status::OUTSIDE | |
reader.readlines.each do |line| | |
if status == Status::OUTSIDE | |
status = Status::DETECT if line.start_with? "[ditaa" | |
new_lines.push line | |
elsif status == Status::INSIDE | |
status = Status::OUTSIDE if line.start_with? "...." | |
new_line = "" | |
line.each_char do |c| | |
new_line << c | |
new_line << " " if c.bytesize > 1 | |
end | |
new_lines.push new_line | |
elsif status == Status::DETECT | |
status = Status::INSIDE if line.start_with? "...." | |
new_lines.push line | |
end | |
end | |
Reader.new new_lines | |
end | |
end | |
end | |
module Status | |
OUTSIDE = 1 | |
INSIDE = 2 | |
DETECT = 3 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment