- 目的
-
注册一个名为`shout`的自定义块样式,将所有单词变为大写,并将句号转换为感叹号。
'''sample-with-shout-block.adoc'''
大声说: 现在就是时候了。快点行动起来。
ShoutBlock
class ShoutBlock < Asciidoctor::Extensions::BlockProcessor PeriodRx = /\.(?= |$)/ 使用DSL ruby named :shout on_context :paragraph name_positional_attributes 'vol' parse_content_as :simple def process parent, reader, attrs volume = ((attrs.delete 'vol') || 1).to_i create_paragraph parent, (reader.lines.map {|l| l.upcase.gsub PeriodRx, '!' * volume }), attrs end end
使用方法
Asciidoctor::Extensions.register do block ShoutBlock end Asciidoctor.convert_file 'sample-with-shout-block.adoc', safe: :safe