qiita-markdown 0.0.6 → 0.0.7

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.

Potentially problematic release.


This version of qiita-markdown might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6afb669f682c7011cb3d63a82f6eeb3b6a57ca2d
4
- data.tar.gz: a648ad7e1cdf3a6b524c9457d4d6b2a72d411d54
3
+ metadata.gz: 778b3df4d04671c390617f51ec231bb2929fb77c
4
+ data.tar.gz: e5474939d020ce354844259c1f37d11e10567c4f
5
5
  SHA512:
6
- metadata.gz: 565ff262b6b042f303519937c5a042f4343676f2cca01b57508f3e4eff6b2c95820452ff090a80612579d6fe8ef828cf2ad321c1dd083f5351514d5dc9c4fb34
7
- data.tar.gz: 94c40140d79c856cb8fe9f5700984e0f20fd5051b27493c6a3a1249cba5f2b3a1329262c907817f262afe02281d7431d162563da39c488c15763c2a5aca9df4a
6
+ metadata.gz: 3ab6e4e68ce78816662dabe71a9a150fc10655be8933f65d8de26903608ef12dcdca53824e761e6e3d7acca7dda5327cd4714b1652e356a4cee11772779585d8
7
+ data.tar.gz: c567e7488ef2aae1065d5ad0ca4399102867464ef42fdbf6ec409c7ecb394b96e73851b3005d29951703eaf7256b8eb4e08f010178530d0b064a01ee28b2a7fd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.7
2
+ * Change dependent gem version
3
+
1
4
  ## 0.0.6
2
5
  * Remove target="_blank" from a element of mention
3
6
 
data/README.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Qiita::Markdown [![Build Status](https://travis-ci.org/increments/qiita-markdown.svg)](https://travis-ci.org/increments/qiita-markdown)
2
- Qiita-specified markdown renderer.
2
+ Qiita-specified markdown processor.
3
+
4
+ * Markdown conversion
5
+ * Sanitization
6
+ * Code and language detection
7
+ * Task list
8
+ * ToC
9
+ * Emoji
10
+ * Syntax highlighting
11
+ * Mention
3
12
 
4
13
  ## Usage
5
14
  Qiita::Markdown::Processor provides markdown rendering logic.
@@ -5,6 +5,7 @@ require "nokogiri"
5
5
  require "redcarpet"
6
6
  require "sanitize"
7
7
 
8
+ require "qiita/markdown/filters/checkbox"
8
9
  require "qiita/markdown/filters/code"
9
10
  require "qiita/markdown/filters/mention"
10
11
  require "qiita/markdown/filters/redcarpet"
@@ -0,0 +1,87 @@
1
+ module Qiita
2
+ module Markdown
3
+ module Filters
4
+ # Converts [ ] and [x] into checkbox elements.
5
+ #
6
+ # * [x] Foo
7
+ # * [ ] Bar
8
+ # * [ ] Baz
9
+ #
10
+ # Takes following context options:
11
+ #
12
+ # * :checkbox_disabled - Pass true to add `disabled` attribute to input element
13
+ #
14
+ class Checkbox < HTML::Pipeline::Filter
15
+ def call
16
+ doc.search("li").each_with_index do |li, index|
17
+ list = List.new(disabled: context[:checkbox_disabled], index: index, node: li)
18
+ list.convert if list.has_checkbox?
19
+ end
20
+ doc
21
+ end
22
+
23
+ class List
24
+ CHECKBOX_CLOSE_MARK = "[x] "
25
+ CHECKBOX_OPEN_MARK = "[ ] "
26
+
27
+ def initialize(disabled: nil, index: nil, node: nil)
28
+ @disabled = disabled
29
+ @index = index
30
+ @node = node
31
+ end
32
+
33
+ def has_checkbox?
34
+ has_open_checkbox? || has_close_checkbox?
35
+ end
36
+
37
+ def convert
38
+ first_text_node.content = first_text_node.content.sub(checkbox_mark, "")
39
+ @node.prepend_child(checkbox_node)
40
+ @node["class"] = "task-list-item"
41
+ end
42
+
43
+ private
44
+
45
+ def checkbox_mark
46
+ case
47
+ when has_close_checkbox?
48
+ CHECKBOX_CLOSE_MARK
49
+ when has_open_checkbox?
50
+ CHECKBOX_OPEN_MARK
51
+ end
52
+ end
53
+
54
+ def checkbox_node
55
+ node = Nokogiri::HTML.fragment('<input type="checkbox" class="task-list-item-checkbox">')
56
+ node.children.first["data-checkbox-index"] = @index
57
+ node.children.first["checked"] = true if has_close_checkbox?
58
+ node.children.first["disabled"] = true if @disabled
59
+ node
60
+ end
61
+
62
+ def first_text_node
63
+ @first_text_node ||= @node.children.first
64
+ end
65
+
66
+ def has_close_checkbox?
67
+ if instance_variable_defined?(:@has_close_checkbox)
68
+ @has_close_checkbox
69
+ else
70
+ inner = @node.children.first
71
+ @has_close_checkbox = inner.text? && inner.content.start_with?(CHECKBOX_CLOSE_MARK)
72
+ end
73
+ end
74
+
75
+ def has_open_checkbox?
76
+ if instance_variable_defined?(:@has_open_checkbox)
77
+ @has_open_checkbox
78
+ else
79
+ inner = @node.children.first
80
+ @has_open_checkbox = inner.text? && inner.content.start_with?(CHECKBOX_OPEN_MARK)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -7,7 +7,7 @@ module Qiita
7
7
  }
8
8
 
9
9
  # 1. Detects language written in <pre> element.
10
- # 2. Adds lang attribute (but this attribute is consumed by syntax highliter).
10
+ # 2. Adds lang attribute (but this attribute is consumed by syntax highlighter).
11
11
  # 3. Adds detected code data into `result[:codes]`.
12
12
  #
13
13
  # You can pass language aliases table via context[:language_aliases].
@@ -9,6 +9,7 @@ module Qiita
9
9
  Filters::Redcarpet,
10
10
  Filters::Sanitize,
11
11
  Filters::Code,
12
+ Filters::Checkbox,
12
13
  Filters::Toc,
13
14
  HTML::Pipeline::EmojiFilter,
14
15
  Filters::SyntaxHighlight,
@@ -1,5 +1,5 @@
1
1
  module Qiita
2
2
  module Markdown
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = Qiita::Markdown::VERSION
8
8
  spec.authors = ["Ryo Nakamura"]
9
9
  spec.email = ["r7kamura@gmail.com"]
10
- spec.summary = "Qiita-specified markdown renderer."
10
+ spec.summary = "Qiita-specified markdown processor."
11
11
  spec.homepage = "https://github.com/increments/qiita-markdown"
12
12
  spec.license = "MIT"
13
13
 
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "github-linguist"
22
22
  spec.add_dependency "html-pipeline"
23
23
  spec.add_dependency "redcarpet"
24
+ spec.add_dependency "rugged", ">= 0.21.1b2"
24
25
  spec.add_dependency "sanitize"
25
26
  spec.add_development_dependency "bundler", "~> 1.7"
26
27
  spec.add_development_dependency "pry"
@@ -157,7 +157,7 @@ describe Qiita::Markdown::Processor do
157
157
  end
158
158
 
159
159
  it "removes script element" do
160
- should eq "\n"
160
+ should eq "<p></p>\n"
161
161
  end
162
162
  end
163
163
 
@@ -168,7 +168,7 @@ describe Qiita::Markdown::Processor do
168
168
 
169
169
  let(:markdown) do
170
170
  <<-EOS.strip_heredoc
171
- <script>alert(1)</script>
171
+ <p><script>alert(1)</script></p>
172
172
  EOS
173
173
  end
174
174
 
@@ -184,7 +184,7 @@ describe Qiita::Markdown::Processor do
184
184
 
185
185
  let(:markdown) do
186
186
  <<-EOS.strip_heredoc
187
- <script async data-a="b">alert(1)</script>
187
+ <p><script async data-a="b">alert(1)</script></p>
188
188
  EOS
189
189
  end
190
190
 
@@ -375,5 +375,92 @@ describe Qiita::Markdown::Processor do
375
375
  EOS
376
376
  end
377
377
  end
378
+
379
+ context "with checkbox list" do
380
+ let(:markdown) do
381
+ <<-EOS.strip_heredoc
382
+ - [ ] a
383
+ - [x] b
384
+ EOS
385
+ end
386
+
387
+ it "inserts checkbox" do
388
+ should eq <<-EOS.strip_heredoc
389
+ <ul>
390
+ <li class="task-list-item">
391
+ <input type="checkbox" class="task-list-item-checkbox" data-checkbox-index="0">a</li>
392
+ <li class="task-list-item">
393
+ <input type="checkbox" class="task-list-item-checkbox" data-checkbox-index="1" checked>b</li>
394
+ </ul>
395
+ EOS
396
+ end
397
+ end
398
+
399
+ context "with nested checkbox list" do
400
+ let(:markdown) do
401
+ <<-EOS.strip_heredoc
402
+ - [ ] a
403
+ - [ ] b
404
+ EOS
405
+ end
406
+
407
+ it "inserts checkbox" do
408
+ should eq <<-EOS.strip_heredoc
409
+ <ul>
410
+ <li class="task-list-item">
411
+ <input type="checkbox" class="task-list-item-checkbox" data-checkbox-index="0">a
412
+
413
+ <ul>
414
+ <li class="task-list-item">
415
+ <input type="checkbox" class="task-list-item-checkbox" data-checkbox-index="1">b</li>
416
+ </ul>
417
+ </li>
418
+ </ul>
419
+ EOS
420
+ end
421
+ end
422
+
423
+ context 'with checkbox list in code block' do
424
+ let(:markdown) do
425
+ <<-EOS.strip_heredoc
426
+ ```
427
+ - [ ] a
428
+ - [x] b
429
+ ```
430
+ EOS
431
+ end
432
+
433
+ it "does not replace checkbox" do
434
+ should eq <<-EOS.strip_heredoc
435
+ <div class="code-frame" data-lang="text"><div class="highlight"><pre>- [ ] a
436
+ - [x] b
437
+ </pre></div></div>
438
+ EOS
439
+ end
440
+ end
441
+
442
+ context "with checkbox list and :checkbox_disabled context" do
443
+ before do
444
+ context[:checkbox_disabled] = true
445
+ end
446
+
447
+ let(:markdown) do
448
+ <<-EOS.strip_heredoc
449
+ - [ ] a
450
+ - [x] b
451
+ EOS
452
+ end
453
+
454
+ it "inserts checkbox with disabled attribute" do
455
+ should eq <<-EOS.strip_heredoc
456
+ <ul>
457
+ <li class="task-list-item">
458
+ <input type="checkbox" class="task-list-item-checkbox" data-checkbox-index="0" disabled>a</li>
459
+ <li class="task-list-item">
460
+ <input type="checkbox" class="task-list-item-checkbox" data-checkbox-index="1" checked disabled>b</li>
461
+ </ul>
462
+ EOS
463
+ end
464
+ end
378
465
  end
379
466
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rugged
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.21.1b2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.21.1b2
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: sanitize
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -167,6 +181,7 @@ files:
167
181
  - Rakefile
168
182
  - lib/qiita-markdown.rb
169
183
  - lib/qiita/markdown.rb
184
+ - lib/qiita/markdown/filters/checkbox.rb
170
185
  - lib/qiita/markdown/filters/code.rb
171
186
  - lib/qiita/markdown/filters/mention.rb
172
187
  - lib/qiita/markdown/filters/redcarpet.rb
@@ -201,7 +216,7 @@ rubyforge_project:
201
216
  rubygems_version: 2.2.2
202
217
  signing_key:
203
218
  specification_version: 4
204
- summary: Qiita-specified markdown renderer.
219
+ summary: Qiita-specified markdown processor.
205
220
  test_files:
206
221
  - spec/qiita/markdown/processor_spec.rb
207
222
  - spec/spec_helper.rb