diff --git a/example_files/default.tpl b/example_files/default.tpl index 76bbd76..e54be46 100644 --- a/example_files/default.tpl +++ b/example_files/default.tpl @@ -4,6 +4,45 @@ %title% %pygments% + +

%title%

diff --git a/lib/vimwiki_markdown/wiki_body.rb b/lib/vimwiki_markdown/wiki_body.rb index c55c65b..5f8e83e 100644 --- a/lib/vimwiki_markdown/wiki_body.rb +++ b/lib/vimwiki_markdown/wiki_body.rb @@ -25,8 +25,9 @@ def to_s HTML::Pipeline::SyntaxHighlightFilter, HTML::Pipeline::TableOfContentsFilter ], { scope: "highlight"}) - result = pipeline.call(html) - result[:output].to_s + @result = pipeline.call(html) + @result = @result[:output].to_s + enrich_li_class! end @@ -74,4 +75,15 @@ def hack_replace_commonmarker_proc! CommonMarker.render_html(content, commonmarker_opts, commonmarker_exts) } end + + def enrich_li_class! + syms_hash = { " ]" => 0, ".]" => 1, "o]" => 2, "O]" => 3, "X]" => 4 } + checkbox = /
  • \s*\[[\s.oOX]\]/ + checkbox_start = /
  • \s*\[/ + @result.gsub!(checkbox) do |m| + m.sub(checkbox_start, '
  • ' + end + @result + end end diff --git a/spec/lib/vimwiki_markdown/wiki_body_spec.rb b/spec/lib/vimwiki_markdown/wiki_body_spec.rb index 637fd05..e3de173 100644 --- a/spec/lib/vimwiki_markdown/wiki_body_spec.rb +++ b/spec/lib/vimwiki_markdown/wiki_body_spec.rb @@ -52,6 +52,36 @@ module VimwikiMarkdown expect(wiki_body.to_s).to match(/there<\/a>/) end + it "must enrich task list unchecked" do + allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true) + allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [ ] This is one line") + expect(wiki_body.to_s).to match(/
  • This is one line<\/li>/) + end + + it "must enrich task list checked" do + allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true) + allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [X] This is a checked line") + expect(wiki_body.to_s).to match(/
  • This is a checked line<\/li>/) + end + + it "must enrich task list parent 1" do + allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true) + allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [.] This is a parent 1 line") + expect(wiki_body.to_s).to match(/
  • This is a parent 1 line<\/li>/) + end + + it "must enrich task list parent 2" do + allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true) + allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [o] This is a parent 2 line") + expect(wiki_body.to_s).to match(/
  • This is a parent 2 line<\/li>/) + end + + it "must enrich task list parent 3" do + allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true) + allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [O] This is a parent 3 line") + expect(wiki_body.to_s).to match(/
  • This is a parent 3 line<\/li>/) + end + describe "syntax highlighting" do it "must give correct classes" do allow(wiki_body).to receive(:get_wiki_markdown_contents) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 392a7b1..84abf03 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -107,6 +107,28 @@ def wiki_index_markdown > this is a blockquote > without a linebreak + +## Test for checks + +- [ ] This is one line +- [X] This is a checked line +- [ ] This is a parent line 1 + - [ ] This is a child line 1 + - [ ] This is a child line 2 +- [.] This is a parent line 2 + - [X] This is a child line 1 + - [ ] This is a child line 2 + - [ ] This is a child line 3 +- [o] This is a parent line 2 + - [X] This is a child line 1 + - [X] This is a child line 2 + - [ ] This is a child line 3 +- [O] This is a parent line 3 + - [X] This is a child line 1 + - [X] This is a child line 2 + - [X] This is a child line 3 + - [ ] This is a child line 4 + " end