Class: MarkdownExtension::Summary
- Inherits:
-
Object
- Object
- MarkdownExtension::Summary
- Defined in:
- lib/markdown_extension/summary.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#markdown ⇒ Object
Returns the value of attribute markdown.
-
#raw_md ⇒ Object
Returns the value of attribute raw_md.
Instance Method Summary collapse
- #html(dir = nil) ⇒ Object
-
#initialize(config, lang = nil) ⇒ Summary
constructor
A new instance of Summary.
- #pre_processing(dir) ⇒ Object
Constructor Details
#initialize(config, lang = nil) ⇒ Summary
Returns a new instance of Summary.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/markdown_extension/summary.rb', line 7 def initialize(config, lang=nil) @config = config if lang file = config.src+"/"+lang+"/summary.md" else file = config.src+"/summary.md" end if File.exist?(file) @raw_md = File.read(file) else @raw_md = "" end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/markdown_extension/summary.rb', line 6 def config @config end |
#markdown ⇒ Object
Returns the value of attribute markdown.
6 7 8 |
# File 'lib/markdown_extension/summary.rb', line 6 def markdown @markdown end |
#raw_md ⇒ Object
Returns the value of attribute raw_md.
6 7 8 |
# File 'lib/markdown_extension/summary.rb', line 6 def raw_md @raw_md end |
Instance Method Details
#html(dir = nil) ⇒ Object
38 39 40 41 |
# File 'lib/markdown_extension/summary.rb', line 38 def html(dir=nil) pre_processing(dir) return Kramdown::Document.new(@markdown, input: 'GFM').to_html end |
#pre_processing(dir) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/markdown_extension/summary.rb', line 21 def pre_processing(dir) @markdown = @raw_md if @config.preprocessing["backlinks"] @markdown = @markdown.gsub(/\[\[(.*)\]\]/) do |s| s = s[2..-3] "[#{s}](#{s}.html)" end end unless dir.empty? @markdown = @markdown.gsub(/\[.*\]\((.*)\)/) do |s| url = Regexp.last_match[1] pn = Pathname.new(url) s.gsub(url, "./"+pn.relative_path_from(dir+"/").to_s) end end end |