require 'asciidoctor' unless RUBY_PLATFORM == 'opal'

module Asciidoctor
  # XXX: Modifies constant defined in Asciidoctor.
  REPLACEMENTS.unshift(
    # foo --- bar -> &thinsp;&mdash;&thinsp;
    [/(^|\n| )---( |\n|$)/, '&#8201;&#8212;&#8201;', :none],
    # foo---bar -> &mdash;{ZERO WIDTH SPACE}
    [/(#{CG_WORD})---(?=#{CG_WORD})/, '&#8212;&#8203;', :leading],

    # foo -- bar -> &thinksp;&ndash;&thinsp;
    # Note: The regexp is copied from Asciidoctor.
    [/(^|\n| |\\)--( |\n|$)/, '&#8201;&#8211;&#8201;', :none],
    # foo--bar -> &ndash;
    # Note: The regexp is copied from Asciidoctor.
    [/(#{CG_WORD})\\?--(?=#{CG_WORD})/, '&#8211;', :leading],
  )
end

require 'asciidoctor' unless RUBY_PLATFORM == 'opal'

module Asciidoctor
  # XXX: Regexps escaping is kinda broken in Opal 0.11.x. This is a hack how to
  # make the third regexp work both in Ruby and Opal.
  _BACKSLASH = '\\\\'

  # XXX: Modifies constant defined in Asciidoctor.
  REPLACEMENTS.unshift(
    # foo --- bar -> &thinsp;&mdash;&thinsp;
    [/(^|\n| )---( |\n|$)/, '&#8201;&#8212;&#8201;', :none],
    # foo---bar -> &mdash;{ZERO WIDTH SPACE}
    [/(#{CG_WORD})---(?=#{CG_WORD})/, '&#8212;&#8203;', :leading],

    # foo -- bar -> &thinksp;&ndash;&thinsp;
    # Note: The regexp is copied from Asciidoctor.
    [/(^|\n|#{_BACKSLASH}| )--( |\n|$)/, '&#8201;&#8211;&#8201;', :none],
    # foo--bar -> &ndash;
    # Note: The regexp is copied from Asciidoctor.
    [/(#{CG_WORD})\\?--(?=#{CG_WORD})/, '&#8211;', :leading],
  )
end

Fix broken regexp under Opal
Fix broken regexp under Opal

    Opal.const_get_relative($nesting, 'REPLACEMENTS').$unshift([/(^|\n| )---( |\n|$)/, "&#8201;&#8212;&#8201;", "none"], [new RegExp("" + "(" + (Opal.const_get_relative($nesting, 'CG_WORD')) + ")---(?=" + (Opal.const_get_relative($nesting, 'CG_WORD')) + ")"), "&#8212;&#8203;", "leading"], [/(^|\n| |\)--( |\n|$)/, "&#8201;&#8211;&#8201;", "none"], [new RegExp("" + "(" + (Opal.const_get_relative($nesting, 'CG_WORD')) + ")\\?--(?=" + (Opal.const_get_relative($nesting, 'CG_WORD')) + ")"), "&#8211;", "leading"])
                                                                                                                          ^

    SyntaxError: Invalid regular expression: /(^|\n| |\)--( |\n|$)/: Unterminated group
        at dist/asciidoctor-html5s.js:37:123
