Class: RedQuilt::ExtendedAutolinkPass

Inherits:
Object
  • Object
show all
Defined in:
lib/red_quilt/extended_autolink_pass.rb

Overview

GFM Extended autolinks: rewrites bare URLs (‘https://…`, `http://…`, `ftp://…`, `www.…`) and email addresses inside TEXT nodes into LINK nodes. Runs as an optional pass after the ordinary inline pipeline, so by then all CommonMark inline structure (real `<…>` autolinks, code spans, links, …) is already in place and protected from rewriting.

Defined Under Namespace

Classes: Match

Constant Summary collapse

URL_RE =
%r{
  (?<![A-Za-z0-9_])
  (?:https?://|ftp://|www\.)
  [^\s<>]+
}x
EMAIL_RE =
/
  (?<![A-Za-z0-9._+-])
  [A-Za-z0-9._+-]+
  @
  [A-Za-z0-9](?:[A-Za-z0-9\-_]{0,61}[A-Za-z0-9])?
  (?:\.[A-Za-z0-9](?:[A-Za-z0-9\-_]{0,61}[A-Za-z0-9])?)+
/x
TRAILING_PUNCT_RE =
/[?!.,:*_~]+\z/
TRAILING_ENTITY_RE =
/&[A-Za-z0-9]+;\z/
SKIP_TYPES =

AST contexts whose TEXT descendants must not be auto-linkified.

[
  NodeType::LINK,
  NodeType::IMAGE,
  NodeType::CODE_SPAN,
  NodeType::HTML_INLINE,
  NodeType::CODE_BLOCK,
  NodeType::HTML_BLOCK,
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ ExtendedAutolinkPass

Returns a new instance of ExtendedAutolinkPass.



38
39
40
41
# File 'lib/red_quilt/extended_autolink_pass.rb', line 38

def initialize(document)
  @document = document
  @arena = document.arena
end

Instance Method Details

#applyObject



43
44
45
# File 'lib/red_quilt/extended_autolink_pass.rb', line 43

def apply
  walk(@document.root_id)
end