Class: MarkdownIt::RulesInline::StateInline
- Inherits:
-
Object
- Object
- MarkdownIt::RulesInline::StateInline
- Includes:
- Common::Utils
- Defined in:
- lib/motion-markdown-it/rules_inline/state_inline.rb
Constant Summary
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
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#delimiters ⇒ Object
Returns the value of attribute delimiters.
-
#env ⇒ Object
Returns the value of attribute env.
-
#level ⇒ Object
Returns the value of attribute level.
-
#md ⇒ Object
Returns the value of attribute md.
-
#pending ⇒ Object
Returns the value of attribute pending.
-
#pendingLevel ⇒ Object
Returns the value of attribute pendingLevel.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#posMax ⇒ Object
Returns the value of attribute posMax.
-
#src ⇒ Object
Returns the value of attribute src.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
-
#tokens_meta ⇒ Object
Returns the value of attribute tokens_meta.
Instance Method Summary collapse
-
#initialize(src, md, env, outTokens) ⇒ StateInline
constructor
——————————————————————————.
-
#push(type, tag, nesting) ⇒ Object
Push new token to “stream”.
-
#pushPending ⇒ Object
Flush pending text ——————————————————————————.
-
#scanDelims(start, canSplitWord) ⇒ Object
Scan a sequence of emphasis-like markers, and determine whether it can start an emphasis sequence or end an emphasis sequence.
Methods included from Common::Utils
#arrayReplaceAt, #assign, #charCodeAt, #escapeHtml, #escapeRE, #fromCharCode, #fromCodePoint, #isMdAsciiPunct, #isPunctChar, #isSpace, #isValidEntityCode, #isWhiteSpace, #normalizeReference, #replaceEntityPattern, #unescapeAll, #unescapeMd
Constructor Details
#initialize(src, md, env, outTokens) ⇒ StateInline
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 12 def initialize(src, md, env, outTokens) @src = src @env = env @md = md @tokens = outTokens @tokens_meta = Array.new(outTokens.length) @pos = 0 @posMax = @src.length @level = 0 @pending = '' @pendingLevel = 0 # Stores { start: end } pairs. Useful for backtrack # optimization of pairs parse (emphasis, strikes). @cache = {} # List of emphasis-like delimiters for current tag @delimiters = [] # Stack of delimiter lists for upper level tags @_prev_delimiters = []; end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
9 10 11 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 9 def cache @cache end |
#delimiters ⇒ Object
Returns the value of attribute delimiters.
9 10 11 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 9 def delimiters @delimiters end |
#env ⇒ Object
Returns the value of attribute env.
8 9 10 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8 def env @env end |
#level ⇒ Object
Returns the value of attribute level.
8 9 10 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8 def level @level end |
#md ⇒ Object
Returns the value of attribute md.
8 9 10 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8 def md @md end |
#pending ⇒ Object
Returns the value of attribute pending.
9 10 11 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 9 def pending @pending end |
#pendingLevel ⇒ Object
Returns the value of attribute pendingLevel.
9 10 11 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 9 def pendingLevel @pendingLevel end |
#pos ⇒ Object
Returns the value of attribute pos.
8 9 10 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8 def pos @pos end |
#posMax ⇒ Object
Returns the value of attribute posMax.
8 9 10 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8 def posMax @posMax end |
#src ⇒ Object
Returns the value of attribute src.
8 9 10 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8 def src @src end |
#tokens ⇒ Object
Returns the value of attribute tokens.
8 9 10 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8 def tokens @tokens end |
#tokens_meta ⇒ Object
Returns the value of attribute tokens_meta.
8 9 10 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8 def @tokens_meta end |
Instance Method Details
#push(type, tag, nesting) ⇒ Object
Push new token to “stream”. If pending text exists - flush it as text token
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 51 def push(type, tag, nesting) pushPending unless @pending.empty? token = Token.new(type, tag, nesting) = nil if nesting < 0 # closing tag @level -= 1 @delimiters = @_prev_delimiters.pop end token.level = @level if nesting > 0 # opening tag @level += 1 @_prev_delimiters.push(@delimiters) @delimiters = [] = { delimiters: @delimiters } end @pendingLevel = @level @tokens.push(token) @tokens_meta.push() return token end |
#pushPending ⇒ Object
Flush pending text
39 40 41 42 43 44 45 46 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 39 def pushPending token = Token.new('text', '', 0) token.content = @pending token.level = @pendingLevel @tokens.push(token) @pending = '' return token end |
#scanDelims(start, canSplitWord) ⇒ Object
Scan a sequence of emphasis-like markers, and determine whether it can start an emphasis sequence or end an emphasis sequence.
- start - position to scan from (it should point at a valid marker);
- canSplitWord - determine if these markers can be found inside a word
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 86 def scanDelims(start, canSplitWord) pos = start left_flanking = true right_flanking = true max = @posMax marker = charCodeAt(@src, start) # treat beginning of the line as a whitespace lastChar = start > 0 ? charCodeAt(@src, start - 1) : 0x20 while (pos < max && charCodeAt(@src, pos) == marker) pos += 1 end count = pos - start # treat end of the line as a whitespace nextChar = pos < max ? charCodeAt(@src, pos) : 0x20 isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctChar(fromCodePoint(lastChar)) isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctChar(fromCodePoint(nextChar)) isLastWhiteSpace = isWhiteSpace(lastChar) isNextWhiteSpace = isWhiteSpace(nextChar) if (isNextWhiteSpace) left_flanking = false elsif (isNextPunctChar) if (!(isLastWhiteSpace || isLastPunctChar)) left_flanking = false end end if isLastWhiteSpace right_flanking = false elsif isLastPunctChar if !(isNextWhiteSpace || isNextPunctChar) right_flanking = false end end if !canSplitWord can_open = left_flanking && (!right_flanking || isLastPunctChar) can_close = right_flanking && (!left_flanking || isNextPunctChar) else can_open = left_flanking can_close = right_flanking end return { can_open: can_open, can_close: can_close, length: count } end |