jekyll-markly 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +32 -16
- data/lib/jekyll/markly/version.rb +1 -1
- data/lib/jekyll/markly.rb +15 -9
- data/test/jekyll_markly_test.rb +50 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 373c40119a536a69530b3b67433d0672f6d7a72c427f26cc02532a66119dbc22
|
|
4
|
+
data.tar.gz: a92db070578e1bf8cbb0648e800af57248fa2acac604b715e077fc6fc1cf3a56
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35df5c81714314fb6c5292b8e692a53d233e62e8ecc7bcab02705c69cdbf1adb201071f1d22f1f42ad1136aff5d6d49d42ffe73b3d08c6673106f61f1589c686
|
|
7
|
+
data.tar.gz: b6854973256e3126ac4466be85eeb562eb4fcab29e899b1840fb6ade3af047639029f1bd654172df08aa28aeb0c1e6fd94dea5a3eac519fb966639b7b90f9442
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,39 +1,55 @@
|
|
|
1
1
|
# Jekyll::Markly
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Jekyll Markdown converter that uses [`cmark-gfm`], Github's fork of the
|
|
4
|
+
reference parser for CommonMark, through the [`markly`] gem.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
[`cmark-gfm`]: https://github.com/github/cmark-gfm
|
|
7
|
+
[`markly`]: https://github.com/socketry/markly
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
Add `jekyll-markly` to the `jekyll_plugins` group in your `Gemfile`
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
```ruby
|
|
14
|
+
group :jekyll_plugins do
|
|
15
|
+
gem "jekyll-markly"
|
|
16
|
+
end
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
and update the `markdown` configuration in `_config.yml`
|
|
12
20
|
|
|
13
|
-
```
|
|
14
|
-
|
|
21
|
+
```yml
|
|
22
|
+
markdown: Markly
|
|
15
23
|
```
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
## Configuration
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
`cmark-cfm` extensions and options can be configured with the `commonmark`
|
|
28
|
+
configuration in `_config.yml`
|
|
29
|
+
|
|
30
|
+
```yml
|
|
31
|
+
commonmark:
|
|
32
|
+
extensions: [table, strikethrough, autolink]
|
|
33
|
+
options: [unsafe, footnotes]
|
|
21
34
|
```
|
|
22
35
|
|
|
23
|
-
|
|
36
|
+
The full list of supported extensions and options can be found in the `Markly`
|
|
37
|
+
[documentation][].
|
|
24
38
|
|
|
25
|
-
|
|
39
|
+
[documentation]: https://socketry.github.io/markly/guides/getting-started/index.html#options
|
|
26
40
|
|
|
27
41
|
## Development
|
|
28
42
|
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
44
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
|
45
|
+
prompt that will allow you to experiment.
|
|
32
46
|
|
|
33
47
|
## Contributing
|
|
34
48
|
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at
|
|
49
|
+
Bug reports and pull requests are welcome on GitHub at
|
|
50
|
+
https://github.com/skipkayhil/jekyll-markly.
|
|
36
51
|
|
|
37
52
|
## License
|
|
38
53
|
|
|
39
|
-
The gem is available as open source under the terms of the [MIT
|
|
54
|
+
The gem is available as open source under the terms of the [MIT
|
|
55
|
+
License](https://opensource.org/licenses/MIT).
|
data/lib/jekyll/markly.rb
CHANGED
|
@@ -48,11 +48,11 @@ class Jekyll::Markly::HtmlRenderer < Markly::Renderer::HTML
|
|
|
48
48
|
|
|
49
49
|
def code_block(node)
|
|
50
50
|
block do
|
|
51
|
-
lang = extract_code_lang(node.fence_info)
|
|
51
|
+
lang, lang_with_options = extract_code_lang(node.fence_info)
|
|
52
52
|
|
|
53
53
|
out('<div class="')
|
|
54
54
|
out("language-", lang, " ") if lang
|
|
55
|
-
out('highlighter-rouge"
|
|
55
|
+
out('highlighter-rouge">')
|
|
56
56
|
out("<pre", source_position(node), ' class="highlight"')
|
|
57
57
|
|
|
58
58
|
if flag_enabled?(Markly::GITHUB_PRE_LANG)
|
|
@@ -63,8 +63,8 @@ class Jekyll::Markly::HtmlRenderer < Markly::Renderer::HTML
|
|
|
63
63
|
out_data_attr(lang)
|
|
64
64
|
out(">")
|
|
65
65
|
end
|
|
66
|
-
out(render_with_rouge(node.string_content,
|
|
67
|
-
out("</code></pre></div
|
|
66
|
+
out(render_with_rouge(node.string_content, lang_with_options))
|
|
67
|
+
out("</code></pre></div>")
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
@@ -74,7 +74,10 @@ class Jekyll::Markly::HtmlRenderer < Markly::Renderer::HTML
|
|
|
74
74
|
return unless info.is_a?(String)
|
|
75
75
|
return if info.empty?
|
|
76
76
|
|
|
77
|
-
info.split(%r{\s+})[0]
|
|
77
|
+
lang_with_options = info.split(%r{\s+})[0]
|
|
78
|
+
lang = lang_with_options.split("?")[0]
|
|
79
|
+
|
|
80
|
+
[lang, lang_with_options]
|
|
78
81
|
end
|
|
79
82
|
|
|
80
83
|
def out_data_attr(lang)
|
|
@@ -98,11 +101,14 @@ end
|
|
|
98
101
|
|
|
99
102
|
class Jekyll::Converters::Markdown::Markly
|
|
100
103
|
def initialize(config)
|
|
101
|
-
@extensions = config.dig("commonmark", "extensions")
|
|
104
|
+
@extensions = config.dig("commonmark", "extensions")&.map!(&:to_sym) || [].freeze
|
|
102
105
|
|
|
103
|
-
symbol_options = config.dig("commonmark", "options")
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
if (symbol_options = config.dig("commonmark", "options")&.map!(&:to_sym))
|
|
107
|
+
@parse_flags = symbol_options.filter_map { |k| Markly::PARSE_FLAGS[k] }.reduce(&:|)
|
|
108
|
+
@render_flags = symbol_options.filter_map { |k| Markly::RENDER_FLAGS[k] }.reduce(&:|)
|
|
109
|
+
else
|
|
110
|
+
@parse_flags = @render_flags = 0
|
|
111
|
+
end
|
|
106
112
|
end
|
|
107
113
|
|
|
108
114
|
def convert(content)
|
data/test/jekyll_markly_test.rb
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class JekyllMarklyTest < JekyllMarklyTestCase
|
|
2
|
-
test "
|
|
3
|
-
|
|
4
|
+
test "syntax highlighting" do
|
|
5
|
+
html = md_to_html(<<~MD)
|
|
6
|
+
```ruby
|
|
7
|
+
3.times {}
|
|
8
|
+
```
|
|
9
|
+
MD
|
|
10
|
+
|
|
11
|
+
assert_snapshot(<<~SNAP, html)
|
|
12
|
+
<div class="language-ruby highlighter-rouge"><pre class="highlight"><code data-lang="ruby"><span class="mi">3</span><span class="p">.</span><span class="nf">times</span> <span class="p">{}</span>
|
|
13
|
+
</code></pre></div>
|
|
14
|
+
SNAP
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "lang attributes include lexer options" do
|
|
18
|
+
html = md_to_html(<<~MD)
|
|
19
|
+
```console?comments=true
|
|
20
|
+
# frank
|
|
21
|
+
```
|
|
22
|
+
MD
|
|
23
|
+
|
|
24
|
+
assert_snapshot(<<~SNAP, html)
|
|
25
|
+
<div class="language-console highlighter-rouge"><pre class="highlight"><code data-lang="console"><span class="c"># frank
|
|
26
|
+
</span></code></pre></div>
|
|
27
|
+
SNAP
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def assert_snapshot(expected, actual)
|
|
33
|
+
if expected.empty?
|
|
34
|
+
flunk <<~OUT
|
|
35
|
+
Empty snapshot at line #{caller_locations(1, 1).first.lineno}. Replace with
|
|
36
|
+
|
|
37
|
+
assert_snapshot(<<~SNAP, html)
|
|
38
|
+
#{actual.strip}
|
|
39
|
+
SNAP
|
|
40
|
+
OUT
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
assert_equal expected.strip, actual.strip
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def md_to_html(md)
|
|
47
|
+
converter.convert(md)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def converter(config = {})
|
|
51
|
+
@converter ||= Jekyll::Converters::Markdown::Markly.new(config)
|
|
4
52
|
end
|
|
5
53
|
end
|