Class: ExtendedMarkdownFilter

Inherits:
HTML::Pipeline::MarkdownFilter
  • Object
show all
Includes:
Filters::PostFilter, Filters::PreFilter
Defined in:
lib/extended-markdown-filter.rb

Constant Summary collapse

EMF_CURLY_TAGS =
%w(intro mac windows linux all tip warning error).join('|')

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Filters::PostFilter

#format_admonitions!, #format_intro!, #format_octicons!, #format_os_blocks!

Methods included from Filters::PreFilter

#format_command_line!, #format_helper!

Constructor Details

#initialize(text, context = nil, result = nil) ⇒ ExtendedMarkdownFilter

Returns a new instance of ExtendedMarkdownFilter.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/extended-markdown-filter.rb', line 18

def initialize(text, context = nil, result = nil)
  if defined?(Jekyll) && context[:emf_use_blocks]
    require 'jekyll-override'
  end

  if context[:emf_use_blocks]
    text = self.class.convert_curly_to_bracket(text)
  end

  Filters.context = context

  # do preprocessing, then call HTML::Pipeline::Markdown
  format_command_line!    text
  format_helper!          text

  super text, context, result
end

Class Method Details

.convert_curly_to_bracket(text) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/extended-markdown-filter.rb', line 36

def self.convert_curly_to_bracket(text)
  text = text.gsub(/\{\{\s*#(#{EMF_CURLY_TAGS})\s*\}\}/, '[[#\1]]')
  text = text.gsub(/\{\{\s*\/(#{EMF_CURLY_TAGS})\s*\}\}/, '[[/\1]]')
  text = text.gsub(/\{\{\s*(octicon-\S+\s*[^\}]+)\s*\}\}/,  '[[\1]]')

  text
end

Instance Method Details

#callObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/extended-markdown-filter.rb', line 44

def call
  # initialize HTML::Pipeline::Markdown, then do post-processing
  html = super

  format_intro!           html
  format_os_blocks!       html
  format_admonitions!     html
  format_octicons!        html

  html
end