require "asciidoctor/extensions" require "htmlentities" require "unicode2latex" require "mime/types" require "base64" require "English" require "latexmath" 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) m = inline_anchor_xref_match(node) t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2") m.nil? and return { target: t, type: "inline", text: node.text } { target: t, type: m[:fn].nil? ? "inline" : "footnote", case: m[:case]&.sub(/%$/, ""), style: m[:style]&.sub(/^style=/, "")&.sub(/%$/, "") || @xrefstyle, droploc: m[:drop].nil? && m[:drop2].nil? ? nil : true, text: inline_anchor_xref_text(m, node), hidden: m[:hidden] } end def inline_anchor_xref_match(node) /^(?:hidden%(?[^,]+),?)? (?