require "asciidoctor/extensions" require "unicode2latex" require "mime/types" require "base64" require "English" require "plurimath" module Metanorma module Standoc module Inline def refid?(ref) @refids.include? ref end def inline_anchor(node) case node.type when :ref then inline_anchor_ref node when :xref then inline_anchor_xref node when :link then inline_anchor_link node when :bibref then inline_anchor_bibref node end end def inline_anchor_ref(node) noko do |xml| xml.bookmark nil, **attr_code(id: node.id) end.join end def inline_anchor_xref(node) noko do |xml| attrs = inline_anchor_xref_attrs(node) c = attrs[:text] attrs.delete(:text) unless c.nil? xml.xref **attr_code(attrs) do |x| x << c end end.join end def inline_anchor_xref_attrs(node) text = concatenate_attributes_to_xref_text(node) m = inline_anchor_xref_match(text) t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2") m.nil? and return { target: t, type: "inline", text: text } inline_anchor_xref_attrs1(m, t, text) end def concatenate_attributes_to_xref_text(node) node.attributes.each_with_object([]) do |(k, v), m| %w(path fragment refid).include?(k) and next m << "#{k}=#{v}%" end.map { |x| x.sub(/%+/, "%") }.join + (node.text || "") end def inline_anchor_xref_attrs1(match, target, text) { target: target, hidden: match[:hidden], type: match[:fn].nil? ? "inline" : "footnote", case: match[:case]&.sub(/%$/, ""), style: match[:style]&.sub(/^style=/, "")&.sub(/%$/, "") || @xrefstyle, droploc: match[:drop].nil? && match[:drop2].nil? ? nil : true, text: inline_anchor_xref_text(match, text) } end def inline_anchor_xref_match(text) /^(?:hidden%(?[^,]+),?)? (?