 # CHR ESCAPING
 #-----------------------------------------------------------------------------------------------------------
 ### TAINT don't keep state here ###
-### TAINT soon to be obsoleted: ###
-@XXX_comment_by_ids        = new Map()
-@XXX_id_by_comments        = new Map()
-@XXX_raw_content_by_ids    = new Map()
-@XXX_raw_id_by_contents    = new Map()
-@XXX_command_by_ids        = new Map()
-@XXX_id_by_commands        = new Map()
-### TAINT new: ###
 @XXX_registry              = []
 @XXX_registry_index        = new Map()
-  # [ 'action',       new Map(), ]
-  # [ 'comment',      new Map(), ]
-  # [ 'do',           new Map(), ]
-  # [ 'raw',          new Map(), ]
-
-#-----------------------------------------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------------------------------------
+### Code duplication ###
 @XXX_html_comment_pattern = ///
   (?: ( ^ | [^\\] ) <!--                      --> ) |
   (?: ( ^ | [^\\] ) <!-- ( [ \s\S ]*? [^\\] ) --> )
   ///g
 
 #-----------------------------------------------------------------------------------------------------------
+### Code duplication ###
 @XXX_do_bracketed_pattern = ///
   (?: ( ^ | [^\\] ) <<\{ do >>                      << do \}>> ) |
   (?: ( ^ | [^\\] ) <<\{ do >> ( [ \s\S ]*? [^\\] ) << do \}>> )
   ///g
 
 #-----------------------------------------------------------------------------------------------------------
+### Code duplication ###
 @XXX_raw_bracketed_pattern = ///
   (?: ( ^ | [^\\] ) <<\( raw >>                      << raw \)>> ) |
   (?: ( ^ | [^\\] ) <<\( raw >> ( [ \s\S ]*? [^\\] ) << raw \)>> )

    key                 = @XXX_register_content 'action', raw_content, parsed_content
    return "#{$1}\x15#{key}\x13"
  #.........................................................................................................
  return R

#-----------------------------------------------------------------------------------------------------------
@XXX_raw_id_from_content = ( collection_name, raw_content, parsed_content = null ) ->
  switch collection_name
    when 'comment'
      fragment_by_ids = @XXX_comment_by_ids
      id_by_fragments = @XXX_id_by_comments
    when 'raw'
      fragment_by_ids = @XXX_raw_content_by_ids
      id_by_fragments = @XXX_raw_id_by_contents
    when 'command'
      fragment_by_ids = @XXX_command_by_ids
      id_by_fragments = @XXX_id_by_commands
    else throw new Error "unknown collection collection_name #{rpr collection_name}"
  unless ( R = id_by_fragments.get raw_content )?
    R = fragment_by_ids.size
    fragment_by_ids.set R, parsed_content ? raw_content
    id_by_fragments.set raw_content, R
  return R

#-----------------------------------------------------------------------------------------------------------

    ### TAINT environment becomes important for footnotes ###
    environment = {}
    md_source   = @XXX_escape_html_comments_raw_spans_and_commands md_source
    urge 'registry           ', @XXX_registry
    urge 'registry_index     ', @XXX_registry_index
    tokens      = md_parser.parse md_source, environment
