Class: MarkdownIt::RulesInline::Entity
- Inherits:
-
Object
- Object
- MarkdownIt::RulesInline::Entity
- Extended by:
- Common::Utils
- Defined in:
- lib/motion-markdown-it/rules_inline/entity.rb
Constant Summary collapse
- DIGITAL_RE =
/^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i- NAMED_RE =
/^&([a-z][a-z0-9]{1,31});/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
-
.entity(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
.entity(state, silent) ⇒ Object
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 |
# File 'lib/motion-markdown-it/rules_inline/entity.rb', line 12 def self.entity(state, silent) pos = state.pos max = state.posMax return false if charCodeAt(state.src, pos) != 0x26 # & return false if pos + 1 >= max ch = charCodeAt(state.src, pos + 1) if ch == 0x23 # '#' match = state.src[pos..-1].match(DIGITAL_RE) if match if !silent code = match[1][0].downcase == 'x' ? match[1][1..-1].to_i(16) : match[1].to_i token = state.push('text_special', '', 0) token.content = isValidEntityCode(code) ? fromCodePoint(code) : fromCodePoint(0xFFFD) token.markup = match[0] token.info = 'entity' end state.pos += match[0].length return true end else match = state.src[pos..-1].match(NAMED_RE) if match if MarkdownIt::HTMLEntities::MAPPINGS[match[1]] if !silent token = state.push('text_special', '', 0) token.content += fromCodePoint(MarkdownIt::HTMLEntities::MAPPINGS[match[1]]) token.markup = match[0] token.info = 'entity' end state.pos += match[0].length return true end end end return false end |