Class: Kramdown::Parser::Cheemarkdown

Inherits:
GFM
  • Object
show all
Defined in:
lib/kramdown/parser/cheemarkdown.rb

Constant Summary collapse

RUBY_START =
/(?:\{)           ## begin
([^:\|}][^\|}]*) ## base text
\|               ## separator
([^\|}]+)        ## ruby text
(?:\})/x
TCY_START =

end

/\^([\u0020-\u005d\u005f\u007e]+)\^/

Instance Method Summary collapse

Constructor Details

#initialize(source, options) ⇒ Cheemarkdown

Returns a new instance of Cheemarkdown.



13
14
15
16
17
# File 'lib/kramdown/parser/cheemarkdown.rb', line 13

def initialize(source, options)
  super
  @span_parsers.unshift(:ruby)
  @span_parsers.unshift(:tcy)
end

Instance Method Details

#parse_rubyObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kramdown/parser/cheemarkdown.rb', line 27

def parse_ruby
  start_line_number = @src.current_line_number
  @src.pos += @src.matched_size
  ruby_base, ruby_text = @src[1], @src[2]
  ruby_el = Element.new(:html_element, :ruby, nil, :category => :span, :localtion => start_line_number)
  @tree.children << ruby_el

  @stack.push([@tree, @text_type])
  @tree = ruby_el
  add_text(ruby_base)

  ruby_text_el = Element.new(:html_element, :rt, nil, :category => :span, :localtion => start_line_number)
  @tree.children << ruby_text_el

  @stack.push([@tree, @text_type])

  @tree = ruby_text_el
  add_text(ruby_text)

  @tree, @text_type = @stack.pop
  @tree, @text_type = @stack.pop
end

#parse_tcyObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/kramdown/parser/cheemarkdown.rb', line 50

def parse_tcy
  start_line_number = @src.current_line_number
  @src.pos += @src.matched_size

  tcy_text = @src[1]
  tcy_el = Element.new(:html_element, :span, {class: "tcy"}, :category => :span, :localtion => start_line_number)
  @tree.children << tcy_el

  @stack.push([@tree, @text_type])
  @tree = tcy_el
  add_text(tcy_text)

  @tree, @text_type = @stack.pop
end