lib/asciidoctor/iso/utils.rb in asciidoctor-iso-0.6.1 vs lib/asciidoctor/iso/utils.rb in asciidoctor-iso-0.7.0
- old
+ new
@@ -22,39 +22,45 @@
return "ID #{n.id}" if n.respond_to?(:id) && !n.id.nil?
while !n.nil? &&
(!n.respond_to?(:level) || n.level.positive?) &&
(!n.respond_to?(:context) || n.context != :section)
n = n.parent
- return "Section: #{n.title}" if !n.nil? && n.context == :section
+ return "Section: #{n.title}" if n&.respond_to?(:context) &&
+ n&.context == :section
end
"??"
end
def warning(node, msg, text)
+ return if @novalid
warntext = "asciidoctor: WARNING"\
"(#{current_location(node)}): #{msg}"
warntext += ": #{text}" if text
warn warntext
end
+ def flatten_rawtext_lines(node, result)
+ node.lines.each do |x|
+ if node.respond_to?(:context) && (node.context == :literal ||
+ node.context == :listing)
+ result << x.gsub(/</, "<").gsub(/>/, ">")
+ else
+ # strip not only HTML <tag>, and Asciidoc xrefs <<xref>>
+ result << x.gsub(/<[^>]*>+/, "")
+ end
+ end
+ result
+ end
+
# if node contains blocks, flatten them into a single line;
# and extract only raw text
def flatten_rawtext(node)
result = []
if node.respond_to?(:blocks) && node.blocks?
node.blocks.each { |b| result << flatten_rawtext(b) }
elsif node.respond_to?(:lines)
- node.lines.each do |x|
- if node.respond_to?(:context) && (node.context == :literal ||
- node.context == :listing)
- result << x.gsub(/</, "<").gsub(/>/, ">")
- else
- # strip not only HTML tags <tag>,
- # but also Asciidoc crossreferences <<xref>>
- result << x.gsub(/<[^>]*>+/, "")
- end
- end
+ result = flatten_rawtext_lines(node, result)
elsif node.respond_to?(:text)
result << node.text.gsub(/<[^>]*>+/, "")
else
result << node.content.gsub(/<[^>]*>+/, "")
end
@@ -69,11 +75,11 @@
def document_ns_attributes(_doc)
nil
end
- NOKOHEAD = <<~HERE
+ NOKOHEAD = <<~HERE.freeze
<!DOCTYPE html SYSTEM
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <title></title> <meta charset="UTF-8" /> </head>
<body> </body> </html>
@@ -103,9 +109,8 @@
if node.blocks? then out << node.content
else
out.p { |p| p << node.content }
end
end
-
end
end
end