module Metanorma::Utils
def to_ncname(name, asciionly: false)
It follows the requirements of the specification for NCName: https://www.w3.org/TR/xml-names/#NT-NCName
# => "1___2___3"
to_ncname('1 < 2 & 3')
A utility method for escaping XML NCNames (XML Names without colons).
def to_ncname(name, asciionly: false) name, valid = to_ncname_prep(name, asciionly) valid and return name starting_char = name[0] starting_char.gsub!(INVALID_NCNAME_START_REGEXP, NCNAME_INVALID) name.size == 1 and return starting_char following_chars = name[1..-1] following_chars.gsub!(INVALID_NCNAME_CHAR_REGEXP, NCNAME_INVALID) following_chars.gsub!(":", NCNAME_INVALID) starting_char << following_chars end