serif 0.5.2 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +58 -21
  4. data/LICENSE +1 -1
  5. data/README.md +11 -13
  6. data/lib/serif.rb +3 -2
  7. data/lib/serif/admin_server.rb +10 -10
  8. data/lib/serif/commands.rb +2 -2
  9. data/lib/serif/config.rb +1 -1
  10. data/lib/serif/content_file.rb +9 -9
  11. data/lib/serif/draft.rb +1 -1
  12. data/lib/serif/errors.rb +1 -1
  13. data/lib/serif/markup_renderer.rb +28 -17
  14. data/lib/serif/post.rb +1 -1
  15. data/lib/serif/server.rb +1 -1
  16. data/lib/serif/site.rb +5 -29
  17. data/rakefile +3 -6
  18. data/serif.gemspec +9 -3
  19. data/statics/assets/js/attachment.js +3 -3
  20. data/statics/skeleton/_config.yml +1 -1
  21. data/statics/skeleton/_layouts/default.html +1 -1
  22. data/statics/skeleton/_templates/archive_page.html +1 -1
  23. data/statics/skeleton/_templates/post.html +1 -1
  24. data/statics/skeleton/archive.html +1 -1
  25. data/statics/skeleton/index.html +1 -1
  26. data/statics/templates/admin/bookmarks.liquid +1 -1
  27. data/statics/templates/admin/edit_draft.liquid +1 -1
  28. data/statics/templates/admin/index.liquid +1 -1
  29. data/statics/templates/admin/layout.liquid +6 -4
  30. data/statics/templates/admin/new_draft.liquid +1 -1
  31. metadata +123 -127
  32. data/test/commands_spec.rb +0 -77
  33. data/test/config_spec.rb +0 -55
  34. data/test/content_file_spec.rb +0 -113
  35. data/test/draft_spec.rb +0 -275
  36. data/test/file_digest_tag_spec.rb +0 -38
  37. data/test/filters_spec.rb +0 -90
  38. data/test/liquid_filter_date_extension_spec.rb +0 -15
  39. data/test/markup_renderer_spec.rb +0 -47
  40. data/test/post_spec.rb +0 -139
  41. data/test/site_dir/_config.yml +0 -18
  42. data/test/site_dir/_drafts/another-sample-draft +0 -3
  43. data/test/site_dir/_drafts/sample-draft +0 -3
  44. data/test/site_dir/_layouts/alt-layout.html +0 -3
  45. data/test/site_dir/_layouts/default.html +0 -8
  46. data/test/site_dir/_posts/2012-01-05-sample-post +0 -4
  47. data/test/site_dir/_posts/2013-01-01-second-post +0 -4
  48. data/test/site_dir/_posts/2013-03-07-post-with-custom-layout +0 -5
  49. data/test/site_dir/_posts/2399-01-01-penultimate-post +0 -4
  50. data/test/site_dir/_posts/2400-01-01-final-post +0 -4
  51. data/test/site_dir/_templates/archive_page.html +0 -9
  52. data/test/site_dir/_templates/post.html +0 -10
  53. data/test/site_dir/archive.html +0 -7
  54. data/test/site_dir/file-digest-test.html +0 -4
  55. data/test/site_dir/index.html +0 -9
  56. data/test/site_dir/page-alt-layout.html +0 -3
  57. data/test/site_dir/page-header-but-no-layout.html +0 -3
  58. data/test/site_dir/test-smarty-filter.html +0 -3
  59. data/test/site_dir/test-stylesheet.css +0 -3
  60. data/test/site_generation_spec.rb +0 -204
  61. data/test/site_spec.rb +0 -189
  62. data/test/test_helper.rb +0 -61
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b61c8d068281185219f5f139140b82536a96f3a0
4
+ data.tar.gz: cef7780b4d90162f5fa472274d0430fe2036b141
5
+ SHA512:
6
+ metadata.gz: 2d083eb99ab7f1bc4e3161b9402d6bffea20700c3e624fdf01287caadda0605a70fcc6ef33ccc8301e9f5f8a3bf8ab284c32a719cbc44c684e1fb7ec09caaf9b
7
+ data.tar.gz: 792eefd28de31b30f1a096d90fdb37f828f889d18d6938dd9f45199860647d1cd2240bcdda425002666c41df756c50971f89f5cbc0a546c8933e4184d099cfcc
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "http://rubygems.org/"
2
2
 
3
- gemspec
3
+ gemspec
@@ -1,20 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- serif (0.4)
4
+ serif (0.5.2)
5
+ kramdown (~> 1.3)
5
6
  liquid (~> 2.4)
6
7
  nokogiri (~> 1.5)
7
8
  rack (~> 1.0)
8
- redcarpet (~> 2.2)
9
9
  redhead (~> 0.0.8)
10
- reverse_markdown (~> 0.4.3)
10
+ reverse_markdown
11
11
  rouge (~> 0.3.2)
12
+ rubypants
12
13
  sinatra (~> 1.3)
13
14
  timeout_cache
14
15
 
15
16
  GEM
16
17
  remote: http://rubygems.org/
17
18
  specs:
19
+ capybara (2.2.1)
20
+ mime-types (>= 1.16)
21
+ nokogiri (>= 1.3.3)
22
+ rack (>= 1.0.0)
23
+ rack-test (>= 0.5.4)
24
+ xpath (~> 2.0)
25
+ cliver (0.3.2)
26
+ coderay (1.1.0)
18
27
  colorize (0.5.8)
19
28
  coveralls (0.6.3)
20
29
  colorize
@@ -22,55 +31,83 @@ GEM
22
31
  rest-client
23
32
  simplecov (>= 0.7)
24
33
  thor
25
- diff-lcs (1.2.2)
34
+ diff-lcs (1.2.5)
35
+ gherkin (2.12.2)
36
+ multi_json (~> 1.3)
26
37
  json (1.7.7)
27
- liquid (2.5.0)
38
+ kramdown (1.3.3)
39
+ liquid (2.6.1)
40
+ method_source (0.8.2)
28
41
  mime-types (1.22)
42
+ mini_portile (0.5.3)
29
43
  multi_json (1.7.2)
30
- nokogiri (1.5.9)
44
+ nokogiri (1.6.1)
45
+ mini_portile (~> 0.5.0)
46
+ poltergeist (1.5.0)
47
+ capybara (~> 2.1)
48
+ cliver (~> 0.3.1)
49
+ multi_json (~> 1.0)
50
+ websocket-driver (>= 0.2.0)
51
+ pry (0.9.12.6)
52
+ coderay (~> 1.0)
53
+ method_source (~> 0.8)
54
+ slop (~> 3.4)
31
55
  rack (1.5.2)
32
- rack-protection (1.5.0)
56
+ rack-protection (1.5.3)
33
57
  rack
58
+ rack-test (0.6.2)
59
+ rack (>= 1.0)
34
60
  rake (0.9.6)
35
61
  rdoc (4.0.1)
36
62
  json (~> 1.4)
37
- redcarpet (2.2.2)
38
- redhead (0.0.8)
63
+ redhead (0.0.9)
39
64
  rest-client (1.6.7)
40
65
  mime-types (>= 1.16)
41
- reverse_markdown (0.4.4)
66
+ reverse_markdown (0.5.1)
42
67
  nokogiri
43
- rouge (0.3.2)
68
+ rouge (0.3.10)
44
69
  thor
45
- rspec (2.13.0)
46
- rspec-core (~> 2.13.0)
47
- rspec-expectations (~> 2.13.0)
48
- rspec-mocks (~> 2.13.0)
49
- rspec-core (2.13.1)
50
- rspec-expectations (2.13.0)
70
+ rspec (2.14.1)
71
+ rspec-core (~> 2.14.0)
72
+ rspec-expectations (~> 2.14.0)
73
+ rspec-mocks (~> 2.14.0)
74
+ rspec-core (2.14.7)
75
+ rspec-expectations (2.14.5)
51
76
  diff-lcs (>= 1.1.3, < 2.0)
52
- rspec-mocks (2.13.0)
77
+ rspec-mocks (2.14.5)
78
+ rubypants (0.2.0)
53
79
  simplecov (0.7.1)
54
80
  multi_json (~> 1.0)
55
81
  simplecov-html (~> 0.7.1)
56
82
  simplecov-html (0.7.1)
57
- sinatra (1.4.2)
58
- rack (~> 1.5, >= 1.5.2)
83
+ sinatra (1.4.5)
84
+ rack (~> 1.4)
59
85
  rack-protection (~> 1.4)
60
86
  tilt (~> 1.3, >= 1.3.4)
87
+ slop (3.4.7)
61
88
  thor (0.18.1)
62
- tilt (1.3.6)
89
+ tilt (1.4.1)
63
90
  timecop (0.6.1)
64
91
  timeout_cache (0.0.2)
92
+ turnip (1.2.1)
93
+ gherkin (>= 2.5)
94
+ rspec (>= 2.0, < 4.0)
95
+ websocket-driver (0.3.2)
96
+ xpath (2.0.0)
97
+ nokogiri (~> 1.3)
65
98
 
66
99
  PLATFORMS
67
100
  ruby
68
101
 
69
102
  DEPENDENCIES
103
+ capybara
70
104
  coveralls
105
+ poltergeist
106
+ pry
71
107
  rake (~> 0.9)
72
108
  rdoc (~> 4.0.0)
73
109
  rspec (~> 2.5)
74
110
  serif!
75
111
  simplecov (~> 0.7)
76
112
  timecop (~> 0.6.1)
113
+ turnip
data/LICENSE CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -56,14 +56,12 @@ Serif is sort of a blend between Jekyll, [Second Crack](https://github.com/marco
56
56
 
57
57
  Serif is released under the MIT license. See LICENSE for details.
58
58
 
59
- Any contributions will be assumed by default to be under the same terms.
60
-
61
59
  The quickest way to get changes contributed:
62
60
 
63
61
  1. Visit the [GitHub repository for Serif](https://github.com/aprescott/serif).
64
62
  2. [Fork the repository](https://help.github.com/articles/fork-a-repo).
65
63
  3. Check out a branch on the latest master for your change: `git checkout -b master new-feature` --- do not make changes on `master`! Make sure that anything added or changed has a test in the `test/` directory. Use the existing files as examples. All tests for new/changed behaviour should pass.
66
- 4. [Send a pull request on GitHub](https://help.github.com/articles/fork-a-repo), including a description of what you've changed. (Note: your contribution will be assumed to be under the same terms of the project by default.)
64
+ 4. [Send a pull request on GitHub](https://help.github.com/articles/fork-a-repo), including a description of what you've changed.
67
65
 
68
66
  For more info on development, see the section at the bottom of this README.
69
67
 
@@ -162,7 +160,7 @@ Drafts go in `_drafts`, posts go in `_posts`. Simple enough.
162
160
 
163
161
  Posts must have filenames in the format of `YYYY-MM-DD-your-post`. Drafts do not have a date part, since they're drafts and not published.
164
162
 
165
- All files in these directories are assumed to be written in Markdown, with simple HTTP-style headers. The Markdown renderer is [Redcarpet](https://github.com/vmg/redcarpet) (with fenced code blocks enabled), with Smarty for punctuation tweaks, and Pygments to allow syntax highlighting (although you'll need your own CSS).
163
+ All files in these directories are assumed to be written in Markdown, with simple HTTP-style headers. The Markdown renderer is [Kramdown](http://kramdown.gettalong.org/), with Smarty for punctuation tweaks, and Pygments to get syntax highlighting for [GitHub-flavoured fenced code blocks](https://help.github.com/articles/github-flavored-markdown#syntax-highlighting) (although you'll need your own CSS).
166
164
 
167
165
  Here's an example post:
168
166
 
@@ -427,30 +425,30 @@ These tags can be used in templates, in addition to the [standard Liquid filters
427
425
  ## List of filters
428
426
 
429
427
  * `date` with `'now'`
430
-
428
+
431
429
  This is a standard filter, but there is a [workaround](https://github.com/Shopify/liquid/pull/117) for
432
430
  `{{ 'now' | date: "%Y" }}` to work, so you can use this in templates.
433
431
 
434
432
  * `markdown`
435
-
433
+
436
434
  e.g., `{{ post.content | markdown }}`.
437
435
 
438
436
  This runs the given input through a Markdown + SmartyPants renderer, with fenced codeblocks enabled.
439
437
 
440
438
  * `smarty`
441
-
439
+
442
440
  e.g., `{{ post.title | smarty }}`.
443
441
 
444
442
  This runs the given input through a SmartyPants processor, so quotes, dashes and ellipses come out better. Note that the **`markdown` filter already does SmartyPants** processing.
445
443
 
446
444
  * `strip`
447
-
445
+
448
446
  Strips trailing and leading whitespace.
449
447
 
450
448
  e.g., `{{ " hello " | strip }}` will render as `hello`.
451
449
 
452
450
  * `xmlschema`
453
-
451
+
454
452
  e.g., `{{ post.created | xmlschema }}`.
455
453
 
456
454
  Takes a Time value and returns an ISO8601-format string, as per Ruby's `Time#xmlschema` definition.
@@ -460,7 +458,7 @@ These tags can be used in templates, in addition to the [standard Liquid filters
460
458
  If the time value is in UTC: 2013-02-16T22:55:22Z
461
459
 
462
460
  * `encode_uri_component`
463
-
461
+
464
462
  e.g., `example.com/foo?url=http://mysite.com{{ post.url | encode_uri_component }}`
465
463
 
466
464
  Intended to provide the functionality of JavaScript's `encode_uri_component()` function. Essentially:
@@ -469,9 +467,9 @@ These tags can be used in templates, in addition to the [standard Liquid filters
469
467
  ## List of tags
470
468
 
471
469
  * `file_digest <path> [prefix:<prefix>]`
472
-
470
+
473
471
  (Note: For this tag to return anything, `ENV=production` must be set as an environment variable.)
474
-
472
+
475
473
  Computes a hex digest of the contents of `<path>`, optionally prefixed with `<prefix>`. `<path>` is delimited by whitespace.
476
474
 
477
475
  Useful for URL fingerprinting for long-lived caching.
@@ -537,7 +535,7 @@ Variable | Value
537
535
  ## Directory structure
538
536
 
539
537
  * `lib/serif/` is generally where files go.
540
- * `test/` contains the test files. Any new files should have `require "test_helper"` at the top of the, which pulls in `test/test_helper.rb`.
538
+ * `spec/` contains the test files. Any new files should have `require "spec_helper"` at the top of the, which pulls in `spec/test_helper.rb`.
541
539
 
542
540
  # Changes and what's new
543
541
 
@@ -1,7 +1,8 @@
1
1
  require "time"
2
2
 
3
3
  require "liquid"
4
- require "redcarpet"
4
+ require "kramdown"
5
+ require "rubypants"
5
6
  require "rouge"
6
7
  require "redhead"
7
8
  require "timeout_cache"
@@ -20,4 +21,4 @@ require "serif/site"
20
21
  require "serif/config"
21
22
 
22
23
  module Serif
23
- end
24
+ end
@@ -71,7 +71,7 @@ class AdminServer
71
71
  html_content = document.to_html
72
72
 
73
73
  html_content = "<blockquote>#{html_content}</blockquote>"
74
- markdown = ReverseMarkdown.parse(html_content, github_style_code_blocks: true)
74
+ markdown = ReverseMarkdown.convert(html_content, github_flavored: true, unknown_tags: :bypass)
75
75
 
76
76
  # markdown URLs need to have any )s escaped
77
77
  markdown = "[#{title}](#{url.gsub(")", "\\)")}):\n\n#{markdown}"
@@ -88,7 +88,7 @@ class AdminServer
88
88
  # there is actually an overall site conflict, then
89
89
  # keep on trucking so it doesn't interrupt the user.
90
90
  if site.conflicts(draft)
91
- liquid :new_draft, locals: { conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), post: draft, error_message: "There is a conflict on this draft." }
91
+ liquid :new_draft, locals: { draft_content: draft.content, conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), post: draft, error_message: "There is a conflict on this draft." }
92
92
  else
93
93
  draft.save(markdown)
94
94
 
@@ -109,7 +109,7 @@ class AdminServer
109
109
  get "/admin/new/draft" do
110
110
  content = Draft.new(site)
111
111
  autofocus = "slug"
112
- liquid :new_draft, locals: { conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), post: content, autofocus: autofocus }
112
+ liquid :new_draft, locals: { draft_content: content.content.to_s, conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), post: content, autofocus: autofocus }
113
113
  end
114
114
 
115
115
  post "/admin/new/draft" do
@@ -128,11 +128,11 @@ class AdminServer
128
128
  autofocus = "title" unless params[:title]
129
129
  autofocus = "slug" unless params[:slug]
130
130
 
131
- liquid :new_draft, locals: { conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), error_message: error_message, post: content, autofocus: autofocus }
131
+ liquid :new_draft, locals: { draft_content: params[:markdown].to_s, conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), error_message: error_message, post: content, autofocus: autofocus }
132
132
  else
133
133
  if Draft.exist?(site, params[:slug])
134
134
  error_message = "Draft already eixsts with the given slug #{params[:slug]}."
135
- liquid :new_draft, locals: { conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), error_message: error_message, post: content, autofocus: autofocus }
135
+ liquid :new_draft, locals: { draft_content: params[:markdown].to_s, conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), error_message: error_message, post: content, autofocus: autofocus }
136
136
  else
137
137
  content.save(params[:markdown])
138
138
  begin
@@ -179,10 +179,10 @@ class AdminServer
179
179
  error_message = "You must pick a URL to use"
180
180
  end
181
181
 
182
- liquid :edit_draft, locals: { conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), error_message: error_message, post: content, private_url: site.private_url(content) }
182
+ liquid :edit_draft, locals: { draft_content: params[:markdown].to_s, conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), error_message: error_message, post: content, private_url: site.private_url(content) }
183
183
  elsif (conflicts = site.conflicts)
184
184
  error_message = "The site has a conflict and cannot be generated."
185
- liquid :edit_draft, locals: { conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), error_message: error_message, post: content, private_url: site.private_url(content) }
185
+ liquid :edit_draft, locals: { draft_content: params[:markdown].to_s, conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), error_message: error_message, post: content, private_url: site.private_url(content) }
186
186
  else
187
187
  content.save(params[:markdown])
188
188
 
@@ -233,7 +233,7 @@ class AdminServer
233
233
  redirect to("/admin") unless params[:slug]
234
234
 
235
235
  content = Draft.from_slug(site, params[:slug])
236
- liquid :edit_draft, locals: { conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), post: content, autofocus: "markdown", private_url: site.private_url(content) }
236
+ liquid :edit_draft, locals: { draft_content: content.content, conflicts: @conflicts, images_path: site.config.image_upload_path.gsub(/"/, '\"'), post: content, autofocus: "markdown", private_url: site.private_url(content) }
237
237
  end
238
238
 
239
239
  post "/admin/delete/?" do
@@ -247,7 +247,7 @@ class AdminServer
247
247
  content = params["content"]
248
248
 
249
249
  if request.xhr?
250
- Redcarpet::Markdown.new(Serif::MarkupRenderer, fenced_code_blocks: true).render(content).strip
250
+ Serif::Markdown.render(content).strip
251
251
  end
252
252
  end
253
253
 
@@ -289,4 +289,4 @@ class AdminServer
289
289
  app.run!
290
290
  end
291
291
  end
292
- end
292
+ end
@@ -44,7 +44,7 @@ class Commands
44
44
  end
45
45
 
46
46
  def generate_site(source_dir)
47
-
47
+
48
48
  site = Serif::Site.new(source_dir)
49
49
 
50
50
  begin
@@ -148,4 +148,4 @@ class Commands
148
148
  END_HELP
149
149
  end
150
150
  end
151
- end
151
+ end
@@ -42,4 +42,4 @@ class Config
42
42
  @yaml ||= YAML.load_file(@config_file)
43
43
  end
44
44
  end
45
- end
45
+ end
@@ -50,7 +50,7 @@ class ContentFile
50
50
 
51
51
  @cached_headers = nil
52
52
  end
53
-
53
+
54
54
  # Returns true if the file is in the directory for draft content, or
55
55
  # has no saved path yet.
56
56
  def draft?
@@ -68,7 +68,7 @@ class ContentFile
68
68
 
69
69
  File.dirname(path) == File.join(site.directory, Post.dirname)
70
70
  end
71
-
71
+
72
72
  def content(include_headers = false)
73
73
  include_headers ? "#{@source.headers.to_s}\n\n#{@source.to_s}" : @source.to_s
74
74
  end
@@ -82,7 +82,7 @@ class ContentFile
82
82
  return nil if !@source
83
83
  (headers[:updated] || created).utc
84
84
  end
85
-
85
+
86
86
  def headers
87
87
  return @cached_headers if @cached_headers
88
88
 
@@ -97,7 +97,7 @@ class ContentFile
97
97
  if key == :created || key == :updated
98
98
  value = Time.parse(value)
99
99
  end
100
-
100
+
101
101
  converted_headers[key] = value
102
102
  end
103
103
 
@@ -106,7 +106,7 @@ class ContentFile
106
106
 
107
107
  def save(markdown = nil)
108
108
  markdown ||= content if @source
109
-
109
+
110
110
  save_path = path || "#{self.class.dirname}/#{@slug}"
111
111
 
112
112
  # TODO: when a draft is being saved, it will call set_publish_time
@@ -115,7 +115,7 @@ class ContentFile
115
115
  # between the update time of a brand new published post and the
116
116
  # creation time.
117
117
  set_updated_time(Time.now)
118
-
118
+
119
119
  File.open(save_path, "w") do |f|
120
120
  f.puts %Q{#{@source.headers.to_s}
121
121
 
@@ -127,11 +127,11 @@ class ContentFile
127
127
 
128
128
  true # always return true for now
129
129
  end
130
-
130
+
131
131
  def inspect
132
132
  %Q{<#{self.class} #{headers.inspect}>}
133
133
  end
134
-
134
+
135
135
  protected
136
136
 
137
137
  def set_publish_time(time)
@@ -160,4 +160,4 @@ class ContentFile
160
160
  @cached_headers = nil
161
161
  end
162
162
  end
163
- end
163
+ end
@@ -111,4 +111,4 @@ class Draft < ContentFile
111
111
  new(site, path)
112
112
  end
113
113
  end
114
- end
114
+ end
@@ -7,4 +7,4 @@ module Serif
7
7
  # This should be used whenever two posts would occupy the same
8
8
  # URL / file path.
9
9
  class PostConflictError < Error; end
10
- end
10
+ end
@@ -1,21 +1,32 @@
1
- module Serif
2
- class MarkupRenderer < Redcarpet::Render::SmartyHTML
3
- def block_code(code, language)
4
- # bypass it all to avoid sticking highlighting markup on stuff with no language.
5
- #
6
- # note that we add a new line after the initial ``` but not before the closing
7
- # ``` because otherwise it introduces an extra \n.
8
- if !language
9
- simple_code = %Q{```\n#{code}```}
10
- renderer = Redcarpet::Markdown.new(Redcarpet::Render::SmartyHTML, fenced_code_blocks: true)
11
- return renderer.render(simple_code).strip
1
+ module Kramdown
2
+ module Converter
3
+ class SerifCustom < Html
4
+ def convert_codeblock(el, indent)
5
+ attr = el.attr.dup
6
+ language = extract_code_language!(attr)
7
+ if language
8
+ out = Rouge.highlight(el.value, language, "html")
9
+ out.sub!(/^(<pre class=\"highlight\">)/, '\1<code>')
10
+ out.sub!(/<\/pre>\z/, "</code></pre>\n")
11
+ else
12
+ super
13
+ end
14
+ end
12
15
  end
16
+ end
17
+ end
13
18
 
14
- out = Rouge.highlight(code, language, "html")
15
- out.sub!(/^(<pre class=\"highlight\">)/, '\1<code>')
16
- out.sub!(/<\/pre>\z/, "</code></pre>\n")
17
-
18
- out
19
+ module Serif
20
+ class Markdown
21
+ def self.render(markdown)
22
+ options = {
23
+ input: "GFM",
24
+ auto_id_stripping: true,
25
+ enable_coderay: false,
26
+ hard_wrap: false,
27
+ parse_block_html: false
28
+ }
29
+ Kramdown::Document.new(markdown, options).to_serif_custom
19
30
  end
20
31
  end
21
- end
32
+ end