in src/_plugins/code_excerpt_processor.rb [157:194]
def process_code_pane(pi, _attrs, args)
# TODO: support use of globally set replace args.
title = args['title'] || trim_file_vers(args[''])
escaped_code = get_code_frag(args['path'],
full_frag_path(args['path'], args['region']),
src_path(args['path'], args['region']),
args['region'])
# args['replace'] syntax: /regex/replacement/g
# Replacement and '_g' are currently mandatory (but not checked)
if args['replace']
_, re, replacement, _g = args['replace'].split '/'
escaped_code.gsub!(Regexp.new(re)) {
match = Regexp.last_match
# TODO: doesn't yet recognize escaped '$' ('\$')
while (arg_match = /(?<=\$)(\d)(?!\d)/.match(replacement)) do
next unless arg_match
replacement.gsub!("$#{arg_match[0]}", match[arg_match[0].to_i])
end
if /\$\d+|\\\$/.match?(replacement)
raise "Plugin doesn't support \\$, or more than 9 match groups $1, ..., $9: #{replacement}.\nAborting."
end
if replacement.include? '$&'
replacement.gsub('$&', match[0])
else
replacement
end
}
end
escaped_code = _process_highlight_markers(escaped_code)
attrs = {}
attrs[:language] = _attrs[:lang] if _attrs[:lang]
attrs[:format] = _attrs[:class] if _attrs[:class]
<<~TEMPLATE
<code-pane name="#{title}"
TEMPLATE
end