jekyll-gfm-admonitions 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9856856fa9908d633101b625732baafbb7f3c0cf73cfcbef406dc7b8632e9789
4
- data.tar.gz: 20e2d07f90fbcfb6d497fbb4b4253b1a8cc42822a9ae37a382cd9a32dab7e002
3
+ metadata.gz: 7f4d88903b4f39d857f537e963c51676d129aa64a1b01b1347384d450f1c715b
4
+ data.tar.gz: 27f1bb25919a5de02325aa0000fff47840ef0a96fdcccde1f55527cf4b1d2d7c
5
5
  SHA512:
6
- metadata.gz: cb773040f974fe2e1e6da8ef9b2964b621c1641fbbfc5b4ec4c744cf422d13734829784f798eec6e4549a3fa0b0e302ebb493c3412c2812094cd6b159f4ec908
7
- data.tar.gz: ae50729c18a1c4084d0e333282b8c7a47025edde3dd7bef466c73378e07b63d82c9fe26ae8e891fdc536b4c05ecca305f1003e0b2f827d9b81bdc279eaae2dac
6
+ metadata.gz: 8c6a301cf15df7bd44ed11138059799d73c494a092649c0b92bfe9c189c026b8642de86d52d1fc90151b0063f446f8fb56ec4ac625f2e59018a445400459377a
7
+ data.tar.gz: 90f9cd3ead495506ddc433b2b593286ec8ba1f6e8d3477d992b779b3f2d70d54f4e3b3f55e67a7099bb7ab73b141a84a276661d179e6c395de9e89024bdbc362
@@ -32,7 +32,7 @@
32
32
  border-left-color: #4493f8;
33
33
  }
34
34
 
35
- .markdown-body .markdown-alert.markdown-alert-note svg path {
35
+ .markdown-body .markdown-alert.markdown-alert-note .markdown-alert-title {
36
36
  color: #4493f8;
37
37
  }
38
38
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'octicons'
4
4
  require 'cssminify'
5
+ require 'liquid/template'
5
6
 
6
7
  ADMONITION_ICONS = {
7
8
  'important' => 'report',
@@ -22,6 +23,7 @@ module JekyllGFMAdmonitions
22
23
  # syntax with HTML markup that includes appropriate iconography and CSS styling.
23
24
  class GFMAdmonitionConverter < Jekyll::Generator
24
25
  safe true
26
+ @@admonition_pages = []
25
27
 
26
28
  def initialize(*args)
27
29
  super(*args)
@@ -29,13 +31,21 @@ module JekyllGFMAdmonitions
29
31
  end
30
32
 
31
33
  def generate(site)
34
+ @markdown = site.converters.find { |c| c.is_a?(Jekyll::Converters::Markdown) }
35
+ unless @markdown
36
+ raise "Markdown converter not found. Please ensure that you have a markdown converter configured in your Jekyll site."
37
+ end
38
+
32
39
  # Process admonitions in posts
33
40
  site.posts.docs.each do |doc|
41
+ Jekyll.logger.debug 'GFMA:', "Processing post '#{doc.path}' (#{doc.content.length} characters)."
34
42
  process(doc)
35
43
  end
36
44
 
37
45
  # Process admonitions in pages
38
46
  site.pages.each do |page|
47
+ Jekyll.logger.debug 'GFMA:', "Processing page '#{page.path}' (#{page.content.length} characters)."
48
+ Jekyll.logger.debug 'GFMA:', "#{page.content.inspect}"
39
49
  process(page)
40
50
  end
41
51
 
@@ -48,27 +58,38 @@ module JekyllGFMAdmonitions
48
58
 
49
59
  return unless doc.content != original_content
50
60
 
51
- inject_css(doc)
61
+ @@admonition_pages << doc
52
62
  @converted += 1
53
63
  end
54
64
 
65
+ def self.admonition_pages
66
+ return @@admonition_pages
67
+ end
68
+
55
69
  def convert_admonitions(doc)
56
70
  doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do
57
71
  type = ::Regexp.last_match(1).downcase
58
72
  title = type.capitalize
59
73
  text = ::Regexp.last_match(2).gsub(/^>\s*/, '').strip
60
74
  icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
75
+ Jekyll.logger.debug 'GFMA:', "Converting #{type} admonition."
61
76
 
62
77
  "<div class='markdown-alert markdown-alert-#{type}'>
63
78
  <p class='markdown-alert-title'>#{icon} #{title}</p>
64
- <p>#{text}</p>
79
+ <p>#{@markdown.convert(text)}</p>
65
80
  </div>"
66
81
  end
67
82
  end
83
+ end
84
+
85
+ Jekyll::Hooks.register :site, :post_render do |site|
86
+ Jekyll.logger.info 'GFMA:', "Injecting admonition CSS in #{GFMAdmonitionConverter.admonition_pages.length} page(s)."
68
87
 
69
- def inject_css(doc)
88
+ for page in GFMAdmonitionConverter.admonition_pages do
89
+ Jekyll.logger.debug 'GFMA:', "Appending admonition style to '#{page.path}'."
70
90
  css = File.read(File.expand_path('../assets/admonitions.css', __dir__))
71
- doc.content += "<style>#{CSSminify.compress(css)}</style>"
91
+
92
+ page.output += "<style>#{CSSminify.compress(css)}</style>"
72
93
  end
73
94
  end
74
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-gfm-admonitions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin De Schepper