qiita-markdown 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 778b3df4d04671c390617f51ec231bb2929fb77c
4
- data.tar.gz: e5474939d020ce354844259c1f37d11e10567c4f
3
+ metadata.gz: bea900399e3f98f773a66f64b0f513b7df75a9ef
4
+ data.tar.gz: 9e662b826ce1e8bb783a93ef1b4dd20c12c3e16d
5
5
  SHA512:
6
- metadata.gz: 3ab6e4e68ce78816662dabe71a9a150fc10655be8933f65d8de26903608ef12dcdca53824e761e6e3d7acca7dda5327cd4714b1652e356a4cee11772779585d8
7
- data.tar.gz: c567e7488ef2aae1065d5ad0ca4399102867464ef42fdbf6ec409c7ecb394b96e73851b3005d29951703eaf7256b8eb4e08f010178530d0b064a01ee28b2a7fd
6
+ metadata.gz: 43d04fc9ed20153039185cc685e8b2b8ca4fcd89373a89bdcc553a0819232e2f5010ba567d207a749b9805375f060303655a227951b880ac89e3ba36d965d7d3
7
+ data.tar.gz: 99cc9042b28fe2f2972c184b95af6f2f044251ab835565a4617779b70c06526509809f154bf2e8cfd213e13c68ed104a2436f491578221b9e562b7802f7e690e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.8
2
+ * Support gapped task list
3
+
1
4
  ## 0.0.7
2
5
  * Change dependent gem version
3
6
 
data/README.md CHANGED
@@ -9,6 +9,7 @@ Qiita-specified markdown processor.
9
9
  * Emoji
10
10
  * Syntax highlighting
11
11
  * Mention
12
+ * Task list
12
13
 
13
14
  ## Usage
14
15
  Qiita::Markdown::Processor provides markdown rendering logic.
@@ -43,9 +44,21 @@ processor.call(text)
43
44
  ```
44
45
 
45
46
  ### Context
46
- Processor takes optional context as a Hash which is shared by all filters.
47
+ `.new` and `#call` can take optional context as a Hash with following keys:
48
+
49
+ ```
50
+ :allowed_usernames - A list of usernames allowed to be username. (Array<String>)
51
+ :asset_path - URL path to link to emoji sprite. (String)
52
+ :asset_root - Base URL to link to emoji sprite. (String)
53
+ :base_url - Used to construct links to user profile pages for each. (String)
54
+ :checkbox_disabled - Pass true to add `disabled` attribute to input element/ (Boolean)
55
+ :default_language - Default language used if no language detected from code. (String)
56
+ :language_aliases - Alias table for some language names. (Hash)
57
+ :rule - Sanitization rule table. (Hash)
58
+ :script - A flag to allow to embed script element. (Boolean)
59
+ ```
47
60
 
48
61
  ```ruby
49
62
  processor = Qiita::Markdown::Processor.new(asset_root: "http://example.com/assets")
50
- processor.call(text, asset_root: "http://cdn.example.com")
63
+ processor.call(text)
51
64
  ```
@@ -1,6 +1,7 @@
1
1
  require "active_support/core_ext/object/blank"
2
2
  require "html/pipeline"
3
3
  require "linguist"
4
+ require "mem"
4
5
  require "nokogiri"
5
6
  require "redcarpet"
6
7
  require "sanitize"
@@ -21,6 +21,8 @@ module Qiita
21
21
  end
22
22
 
23
23
  class List
24
+ include Mem
25
+
24
26
  CHECKBOX_CLOSE_MARK = "[x] "
25
27
  CHECKBOX_OPEN_MARK = "[ ] "
26
28
 
@@ -36,7 +38,7 @@ module Qiita
36
38
 
37
39
  def convert
38
40
  first_text_node.content = first_text_node.content.sub(checkbox_mark, "")
39
- @node.prepend_child(checkbox_node)
41
+ first_text_node.add_previous_sibling(checkbox_node)
40
42
  @node["class"] = "task-list-item"
41
43
  end
42
44
 
@@ -60,25 +62,23 @@ module Qiita
60
62
  end
61
63
 
62
64
  def first_text_node
63
- @first_text_node ||= @node.children.first
65
+ @first_text_node ||= begin
66
+ if @node.children.first.name == "p"
67
+ @node.children.first.children.first
68
+ else
69
+ @node.children.first
70
+ end
71
+ end
64
72
  end
65
73
 
74
+ memoize\
66
75
  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
76
+ @has_close_checkbox = first_text_node.text? && first_text_node.content.start_with?(CHECKBOX_CLOSE_MARK)
73
77
  end
74
78
 
79
+ memoize\
75
80
  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
81
+ @has_open_checkbox = first_text_node.text? && first_text_node.content.start_with?(CHECKBOX_OPEN_MARK)
82
82
  end
83
83
  end
84
84
  end
@@ -1,5 +1,5 @@
1
1
  module Qiita
2
2
  module Markdown
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "gemoji"
21
21
  spec.add_dependency "github-linguist"
22
22
  spec.add_dependency "html-pipeline"
23
+ spec.add_dependency "mem"
23
24
  spec.add_dependency "redcarpet"
24
25
  spec.add_dependency "rugged", ">= 0.21.1b2"
25
26
  spec.add_dependency "sanitize"
@@ -376,7 +376,7 @@ describe Qiita::Markdown::Processor do
376
376
  end
377
377
  end
378
378
 
379
- context "with checkbox list" do
379
+ context "with task list" do
380
380
  let(:markdown) do
381
381
  <<-EOS.strip_heredoc
382
382
  - [ ] a
@@ -396,7 +396,7 @@ describe Qiita::Markdown::Processor do
396
396
  end
397
397
  end
398
398
 
399
- context "with nested checkbox list" do
399
+ context "with nested task list" do
400
400
  let(:markdown) do
401
401
  <<-EOS.strip_heredoc
402
402
  - [ ] a
@@ -420,7 +420,7 @@ describe Qiita::Markdown::Processor do
420
420
  end
421
421
  end
422
422
 
423
- context 'with checkbox list in code block' do
423
+ context 'with task list in code block' do
424
424
  let(:markdown) do
425
425
  <<-EOS.strip_heredoc
426
426
  ```
@@ -439,7 +439,7 @@ describe Qiita::Markdown::Processor do
439
439
  end
440
440
  end
441
441
 
442
- context "with checkbox list and :checkbox_disabled context" do
442
+ context "with task list and :checkbox_disabled context" do
443
443
  before do
444
444
  context[:checkbox_disabled] = true
445
445
  end
@@ -462,5 +462,24 @@ describe Qiita::Markdown::Processor do
462
462
  EOS
463
463
  end
464
464
  end
465
+
466
+ context 'with empty line between task list' do
467
+ let(:markdown) do
468
+ <<-EOS.strip_heredoc
469
+ - [ ] a
470
+
471
+ - [x] b
472
+ EOS
473
+ end
474
+
475
+ it "inserts checkbox with disabled attribute" do
476
+ should eq <<-EOS.strip_heredoc
477
+ <ul>
478
+ <li class="task-list-item"><p><input type="checkbox" class="task-list-item-checkbox" data-checkbox-index="0">a</p></li>
479
+ <li class="task-list-item"><p><input type="checkbox" class="task-list-item-checkbox" data-checkbox-index="1" checked>b</p></li>
480
+ </ul>
481
+ EOS
482
+ end
483
+ end
465
484
  end
466
485
  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.7
4
+ version: 0.0.8
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-15 00:00:00.000000000 Z
11
+ date: 2014-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mem
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: redcarpet
71
85
  requirement: !ruby/object:Gem::Requirement