Method: MarkdownIt::RulesInline::Emphasis.tokenize
- Defined in:
- lib/motion-markdown-it/rules_inline/emphasis.rb
.tokenize(state, silent) ⇒ Object
Insert each marker as a separate text token, and add it to delimiter list
10 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 |
# File 'lib/motion-markdown-it/rules_inline/emphasis.rb', line 10 def self.tokenize(state, silent) start = state.pos marker = charCodeAt(state.src, start) return false if silent return false if (marker != 0x5F && marker != 0x2A) # _ and * scanned = state.scanDelims(state.pos, marker == 0x2A) 0.upto(scanned[:length] - 1) do |i| token = state.push('text', '', 0) token.content = fromCodePoint(marker) state.delimiters.push({ # Char code of the starting marker (number). # marker: marker, # Total length of these series of delimiters. # length: scanned[:length], # A position of the token this delimiter corresponds to. # token: state.tokens.length - 1, # If this delimiter is matched as a valid opener, `end` will be # equal to its position, otherwise it's `-1`. # end: -1, # Boolean flags that determine if this delimiter could open or close # an emphasis. # open: scanned[:can_open], close: scanned[:can_close] }) end state.pos += scanned[:length] return true end |