Class: Kramdown::Parser::Bsmarkdown

Inherits:
Kramdown show all
Defined in:
lib/burr/kramdown_ext/parser.rb

Constant Summary collapse

BOXES =
%w(aside discussion error information question tip warning)
GFM_FENCED_CODEBLOCK_START =
/^`{3,}/
GFM_FENCED_CODEBLOCK_MATCH =
/^(`{3,})\s*?(\w+)?\s*?\n(.*?)^\1`*\s*?\n/m
ASIDE_BOX_START =
/^#{OPT_SPACE}A> ?/u
DISCUSSION_BOX_START =
/^#{OPT_SPACE}D> ?/
ERROR_BOX_START =
/^#{OPT_SPACE}E> ?/
INFORMATION_BOX_START =
/^#{OPT_SPACE}I> ?/
QUESTION_BOX_START =
/^#{OPT_SPACE}Q> ?/
TIP_BOX_START =
/^#{OPT_SPACE}T> ?/
WARNING_BOX_START =
/^#{OPT_SPACE}W> ?/

Instance Method Summary collapse

Constructor Details

#initialize(source, options) ⇒ Bsmarkdown

Returns a new instance of Bsmarkdown.



7
8
9
10
# File 'lib/burr/kramdown_ext/parser.rb', line 7

def initialize(source, options)
  super
  @block_parsers.unshift(:gfm_codeblock_fenced, *BOXES.map{ |b| :"#{b}_box" })
end

Instance Method Details

#parse_gfm_codeblock_fencedObject

Parser the GitHub Flavored Markdown fenced code block.

Examples

```ruby
def hello
  puts 'Hello'
end
```


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/burr/kramdown_ext/parser.rb', line 25

def parse_gfm_codeblock_fenced
  if @src.check(GFM_FENCED_CODEBLOCK_MATCH)
    @src.pos += @src.matched_size
    el = new_block_el(:codeblock, @src[3])
    lang = @src[2].to_s.strip
    el.attr['class'] = "language-#{lang}" unless lang.empty?
    @tree.children << el
    true
  else
    false
  end
end