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 note warning danger).join('|')

Constants included from Filters::PostFilter

Filters::PostFilter::ALL_HTML, Filters::PostFilter::DANGER_HTML, Filters::PostFilter::INTRO_HTML, Filters::PostFilter::LINUX_HTML, Filters::PostFilter::MAC_HTML, Filters::PostFilter::NOTE_HTML, Filters::PostFilter::TIP_HTML, Filters::PostFilter::WARNING_HTML, Filters::PostFilter::WIN_HTML

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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/extended-markdown-filter.rb', line 11

def initialize(text, context = nil, result = nil)
  if context[:emf_use_blocks]
    text = self.class.convert_curly_to_bracket(text)
    @front_wrap = "\\[\\["
    @end_wrap = "\\]\\]"
    @wrap_symbol = "\\]"
  else
    @front_wrap = "\{\{"
    @end_wrap = "\}\}"
    @wrap_symbol = "}"
  end

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

  super text, context, result
end

Class Method Details

.convert_curly_to_bracket(text) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/extended-markdown-filter.rb', line 30

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

  text
end

.should_jekyll_replace?(site) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/extended-markdown-filter.rb', line 39

def self.should_jekyll_replace?(site)
  html_pipeline_context = site.site_payload["site"]["html_pipeline"] && site.site_payload["site"]["html_pipeline"]["context"]
  return false if html_pipeline_context.nil?
  pipeline_emf_context = site.site_payload["site"]["html_pipeline"]["context"][:emf_use_blocks] || site.site_payload["site"]["html_pipeline"]["context"]["emf_use_blocks"]
  site.site_payload["site"]["markdown"] == "HTMLPipeline" && html_pipeline_context && pipeline_emf_context
end

Instance Method Details

#callObject



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

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