module LinkifyRe

Constants

SRC_ANY

Use direct extract instead of `regenerate` to reduce size

SRC_AUTH

Prohibit any of “@/[]()” in user/pass to avoid wrong domain fetch.

SRC_CC
SRC_DOMAIN
SRC_DOMAIN_ROOT

More to read about domain names serverfault.com/questions/638260/

SRC_EMAIL_NAME

moved SRC_PATH into re_src_path

SRC_HOST
SRC_HOST_PORT_STRICT
SRC_HOST_STRICT
SRC_HOST_TERMINATOR
SRC_IP4
SRC_P
SRC_PORT
SRC_PSEUDO_LETTER

All possible word characters (everything without punctuation, spaces & controls) Defined via punctuation & spaces to save space Should be something like p{LNSM} (w but without `_`)

SRC_XN
SRC_Z
SRC_Z_CC

p{ZCc} (white spaces + control)

SRC_Z_P_CC

p{ZPCcCf} (white spaces + control + format + punctuation)

TEXT_SEPARATORS

Experimental. List of chars, completely prohibited in links because can separate it from other part of text

TPL_EMAIL_FUZZY
TPL_HOST_FUZZY
TPL_HOST_FUZZY_STRICT
TPL_HOST_FUZZY_TEST

Rude test fuzzy links by host, for quick deny

TPL_HOST_NO_IP_FUZZY
TPL_HOST_PORT_FUZZY_STRICT
TPL_HOST_PORT_NO_IP_FUZZY_STRICT

Public Instance Methods

build_re(opts) click to toggle source
# File lib/linkify-it-rb/re.rb, line 99
def build_re(opts)
  re = {
    src_Any:              SRC_ANY,
    src_Cc:               SRC_CC,
    src_Z:                SRC_Z,
    src_P:                SRC_P,
    src_XPCc:             SRC_Z_P_CC,
    src_ZCc:              SRC_Z_CC,
    src_pseudo_letter:    SRC_PSEUDO_LETTER,
    src_ip4:              SRC_IP4,
    src_auth:             SRC_AUTH,
    src_port:             SRC_PORT,
    src_host_terminator:  SRC_HOST_TERMINATOR,
    src_path:             re_src_path(opts),
    src_email_name:       SRC_EMAIL_NAME,
    src_xn:               SRC_XN,
    src_domain_root:      SRC_DOMAIN_ROOT,
    src_domain:           SRC_DOMAIN,
    src_host:             SRC_HOST,

    tpl_host_fuzzy:                   TPL_HOST_FUZZY,
    tpl_host_no_ip_fuzzy:             TPL_HOST_NO_IP_FUZZY,
    src_host_strict:                  SRC_HOST_STRICT,
    tpl_host_fuzzy_strict:            TPL_HOST_FUZZY_STRICT,
    src_host_port_strict:             SRC_HOST_PORT_STRICT,
    tpl_host_port_fuzzy_strict:       TPL_HOST_PORT_FUZZY_STRICT,
    tpl_host_port_no_ip_fuzzy_strict: TPL_HOST_PORT_NO_IP_FUZZY_STRICT,

    tpl_host_fuzzy_test:  TPL_HOST_FUZZY_TEST,
    tpl_email_fuzzy:      TPL_EMAIL_FUZZY
  }

  # Fuzzy link can't be prepended with .:/\- and non punctuation.
  # but can start with > (markdown blockquote)
  re[:tpl_link_fuzzy] =
      '(^|(?![.:/\\-_@])(?:[$+<=>^`|\uff5c]|' + SRC_Z_P_CC + '))' +
      '((?![$+<=>^`|\uff5c])' + TPL_HOST_PORT_FUZZY_STRICT + re[:src_path] + ')'

  # Fuzzy link can't be prepended with .:/\- and non punctuation.
  # but can start with > (markdown blockquote)
  re[:tpl_link_no_ip_fuzzy] =
    '(^|(?![.:/\\-_@])(?:[$+<=>^`|\uff5c]|' + SRC_Z_P_CC + '))' +
    '((?![$+<=>^`|\uff5c])' + TPL_HOST_PORT_NO_IP_FUZZY_STRICT + re[:src_path] + ')'

  return re
end
re_src_path(opts = nil) click to toggle source
# File lib/linkify-it-rb/re.rb, line 147
  def re_src_path(opts = nil)
    '(?:' +
      '[/?#]' +
        '(?:' +
          '(?!' + SRC_Z_CC + '|' + TEXT_SEPARATORS + '|[()\\[\\]{}.,"\'?!\\-]).|' +
          '\\[(?:(?!' + SRC_Z_CC + '|\\]).)*\\]|' +
          '\\((?:(?!' + SRC_Z_CC + '|[)]).)*\\)|' +
          '\\{(?:(?!' + SRC_Z_CC + '|[}]).)*\\}|' +
          '\\"(?:(?!' + SRC_Z_CC + '|["]).)+\\"|' +
          "\\'(?:(?!" + SRC_Z_CC + "|[']).)+\\'|" +
          "\\'(?=" + SRC_PSEUDO_LETTER + '|[-]).|' +  # allow `I'm_king` if no pair found
          '\\.{2,3}[a-zA-Z0-9%/]|' + # github has ... in commit range links. Restrict to
                                     # - english
                                     # - percent-encoded
                                     # - parts of file path
                                     # until more examples found.
          '\\.(?!' + SRC_Z_CC + '|[.]).|' +
          (opts && opts[:'---'] ?
            '\\-(?!--(?:[^-]|$))(?:-*)|'  # `---` => long dash, terminate
          :
            '\\-+|'
          ) +
          '\\,(?!' + SRC_Z_CC + ').|' +      # allow `,,,` in paths
          '\\!(?!' + SRC_Z_CC + '|[!]).|' +
          '\\?(?!' + SRC_Z_CC + '|[?]).' +
        ')+' +
      '|\\/' +
    ')?'
end