Class: MarkdownIt::RulesInline::Linkify
- Inherits:
-
Object
- Object
- MarkdownIt::RulesInline::Linkify
- Extended by:
- Common::Utils
- Defined in:
- lib/motion-markdown-it/rules_inline/linkify.rb
Constant Summary collapse
- SCHEME_RE =
RFC3986: scheme = ALPHA *( ALPHA / DIGIT / “+” / “-” / “.” )
/(?:^|[^a-z0-9.+-])([a-z][a-z0-9.+-]*)$/i
Constants included from Common::Utils
Common::Utils::DIGITAL_ENTITY_TEST_RE, Common::Utils::ENTITY_RE, Common::Utils::HTML_ESCAPE_REPLACE_RE, Common::Utils::HTML_ESCAPE_TEST_RE, Common::Utils::HTML_REPLACEMENTS, Common::Utils::REGEXP_ESCAPE_RE, Common::Utils::UNESCAPE_ALL_RE, Common::Utils::UNESCAPE_MD_RE, Common::Utils::UNICODE_PUNCT_RE
Class Method Summary collapse
-
.linkify(state, silent) ⇒ Object
——————————————————————————.
Methods included from Common::Utils
arrayReplaceAt, assign, charCodeAt, escapeHtml, escapeRE, fromCharCode, fromCodePoint, isMdAsciiPunct, isPunctChar, isSpace, isValidEntityCode, isWhiteSpace, normalizeReference, replaceEntityPattern, unescapeAll, unescapeMd
Class Method Details
.linkify(state, silent) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/motion-markdown-it/rules_inline/linkify.rb', line 11 def self.linkify(state, silent) return false if (!state.md.[:linkify]) return false if (state.linkLevel > 0) pos = state.pos max = state.posMax return false if (pos + 3 > max) return false if (charCodeAt(state.src, pos) != 0x3A) # : return false if (charCodeAt(state.src, pos + 1) != 0x2F) # / return false if (charCodeAt(state.src, pos + 2) != 0x2F) # / match = state.pending.match(SCHEME_RE) return false if (!match) proto = match[1] link = state.md.linkify.matchAtStart(state.src.slice((pos - proto.length)..-1)) return false if (!link) url = link.url # disallow '*' at the end of the link (conflicts with emphasis) url = url.sub(/\*+$/, '') fullUrl = state.md.normalizeLink.call(url) return false if (!state.md.validateLink.call(fullUrl)) if (!silent) state.pending = state.pending[0...-proto.length] token = state.push('link_open', 'a', 1) token.attrs = [ [ 'href', fullUrl ] ] token.markup = 'linkify' token.info = 'auto' token = state.push('text', '', 0) token.content = state.md.normalizeLinkText.call(url) token = state.push('link_close', 'a', -1) token.markup = 'linkify' token.info = 'auto' end state.pos += url.length - proto.length return true end |