Skip to content

Instantly share code, notes, and snippets.

@fuka
Last active September 21, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuka/231470d03b45f7c59bdaa098977332d0 to your computer and use it in GitHub Desktop.
Save fuka/231470d03b45f7c59bdaa098977332d0 to your computer and use it in GitHub Desktop.
Asciidoctor Diagramでditaaに日本語が含まれていたら後ろに半角スペースを挿入するExtension
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