vimwiki_markdown 0.4.3 → 0.7.0

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
  SHA256:
3
- metadata.gz: 9350bfdab384da03bd60949b18575b0d29b69df197e73370e5e20d5124a2105e
4
- data.tar.gz: acf9164c1ff195e280364de0e3a341c618a7d892989a6d7702e6a7eab57bdd20
3
+ metadata.gz: d4893e1d18542936cff19882c791e51c9d8234cefaaec3751cff7fc9724eb70e
4
+ data.tar.gz: 1e51ef4d9df34eb09ad1cf0528efad3b3471e11790a3628594b27224e1560176
5
5
  SHA512:
6
- metadata.gz: 25a3d1674dd3b8511ccc76e0be69b77e08a7aa87a311895019e0cb5649d65e37e4ef12423521318a4e35d6415e9bd205c9836f0b26233eab8a360b112cd85d2a
7
- data.tar.gz: bdb112d177af8f0d5f039b847e9e94bd5d274aaf075b8a037ac7326f392c8393a4aac3fd6da18819c760066c447670d826b091b9c33d791b9f14e286a1994f3a
6
+ metadata.gz: d4301871b6d662d7f02c8c549dcdcd239633183f4bfb9a05f3c04c6d40405778da03ef88948a1d954a0d6b6b41c2c4df3a43602f2d3673108cbf1402b484442e
7
+ data.tar.gz: 908c6005ba6107459aa00297331a62eac008ccc88e4feb526943225d01dd6bdbd21307db1466303424a9fb0378c03cd29f7ca6a586b1274e82b39264739728d1
data/.travis.yml CHANGED
@@ -4,6 +4,8 @@ before_install:
4
4
  language: ruby
5
5
  rvm:
6
6
  - 2.3.8
7
- - 2.4.2
8
- - 2.5.3
9
- - 2.6.1
7
+ - 2.4.10
8
+ - 2.5.8
9
+ - 2.6.6
10
+ - 2.7.2
11
+ - 3.0.0
data/A.png ADDED
Binary file
data/B.png ADDED
Binary file
data/README.md CHANGED
@@ -6,6 +6,15 @@ to be converted to HTML.
6
6
 
7
7
  It is currently a work in progress (but working for me ;)
8
8
 
9
+ ## Example
10
+ It turns this:
11
+
12
+ ![markdown](A.png)
13
+
14
+ into
15
+
16
+ ![finished](B.png)
17
+
9
18
  ## Requirements
10
19
 
11
20
  Ruby installed on your computer & up to date version of vimwiki
@@ -56,14 +65,24 @@ of the site (e.g. `./` or `../../` etc)
56
65
  You can also have a `%date%` marker in your template file
57
66
  It will get rewritten with todays date in the format 29 March 2019
58
67
 
68
+ #### Support for tasklists
69
+ Vimwiki has support for complex todo lists which you can [read about in their help.txt](https://github.com/vimwiki/vimwiki/blob/619f04f89861c58e5a6415a4f83847752928252d/doc/vimwiki.txt#L1768). We do support turning them into HTML. This is _slightly different_ from the way that GitHub checklists are rendered, but, the syntax is a subset of GitHub lists so it should be fine. You can read about it in the [issue](https://github.com/patrickdavey/vimwiki_markdown/issues/27), but basically it should work fine. You will want to add `styles` in for the various states that the todo lists can be in. The easiest way is to simply add the `styles` into your template. You can see the styles [in the sample template here](https://github.com/patrickdavey/vimwiki_markdown/blob/293f99e656819b9c5ecc0c831698ce58904eb774/example_files/default.tpl#L7-L45)
70
+
71
+ #### Support for :local and :file links
72
+
73
+ We have partial support for the `:local` and `:file` link types for vimwiki.
74
+ If you are editing `foo.md` (in the root dir of your wiki) and you are linking to `bar.txt` stored in the same directory as `foo.md` you can do:
75
+
76
+ * `[link text](local:bar.txt)` when output to HTML becomes `<a href="../bar.txt">link text</a>`
77
+ * `[link text](file:bar.txt)` when output to HTML becomes `<a href="/absolute/path/to/file">link text</a>`
78
+
59
79
  #### Optional %nohtml
60
80
 
61
81
  If you place the text %nohtml anywhere in a wiki page, it will not be processed into html
62
82
 
63
83
  ## Contributing
64
84
 
65
- Pull requests are very welcome, especially if you want to implement some of the
66
- more interesting vimwiki links (e.g. :local etc.)
85
+ Pull requests are very welcome
67
86
 
68
87
  1. Fork it ( https://github.com/patrickdavey/vimwiki_markdown/fork )
69
88
  2. Create your feature branch (`git checkout -b my-new-feature`)
data/changelog.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.6.0 [April 26 2020]
2
+ Support for todo lists with enhanced state options. Thanks to @primercuervo
3
+
4
+ ## 0.5.0 [April 26 2020]
5
+ Partial support for `local` and `file` links in urls. Thanks to @tfachmann for the PR
6
+
7
+ ## 0.4.4 [June 16 2019]
8
+ Allow fragments if they are for local vimwiki links only
9
+
1
10
  ## 0.4.3 [June 16 2019]
2
11
  temporarily revoke fragments until we're not altering old links
3
12
 
@@ -4,6 +4,45 @@
4
4
  <title>%title%</title>
5
5
 
6
6
  %pygments%
7
+ <!--Style for Vimwiki Tasklist-->
8
+ <style>
9
+ .rejected {
10
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAMAAAAMCGV4AAAACXBIWXMAAADFAAAAxQEdzbqoAAAAB3RJTUUH4QgEFhAtuWgv9wAAAPZQTFRFmpqam5iYnJaWnJeXnpSUn5OTopCQpoqKpouLp4iIqIiIrYCAt3V1vW1tv2xsmZmZmpeXnpKS/x4e/x8f/yAg/yIi/yQk/yUl/yYm/ygo/ykp/yws/zAw/zIy/zMz/zQ0/zU1/zY2/zw8/0BA/0ZG/0pK/1FR/1JS/1NT/1RU/1VV/1ZW/1dX/1pa/15e/19f/2Zm/2lp/21t/25u/3R0/3p6/4CA/4GB/4SE/4iI/46O/4+P/52d/6am/6ur/66u/7Oz/7S0/7e3/87O/9fX/9zc/93d/+Dg/+vr/+3t/+/v//Dw//Ly//X1//f3//n5//z8////gzaKowAAAA90Uk5T/Pz8/Pz8/Pz8/Pz8/f39ppQKWQAAAAFiS0dEEnu8bAAAAACuSURBVAhbPY9ZF4FQFEZPSKbIMmWep4gMGTKLkIv6/3/GPbfF97b3w17rA0kQOPgvAeHW6uJ6+5h7HqLdwowgOzejXRXBdx6UdSru216xuOMBHHNU0clTzeSUA6EhF8V8kqroluMiU6HKcuf4phGPr1o2q9kYZWwNq1qfRRmTaXpqsyjj17KkWCxKBUBgXWueHIyiAIg18gsse4KHkLF5IKIY10WQgv7fOy4ST34BRiopZ8WLNrgAAAAASUVORK5CYII=);
11
+ background-repeat: no-repeat;
12
+ background-position: 0 .2em;
13
+ padding-left: 5.5em;
14
+ }
15
+ .done0 {
16
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAA7SURBVCiR7dMxEgAgCANBI3yVRzF5KxNbW6wsuH7LQ2YKQK1mkswBVERYF5Os3UV3gwd/jF2SkXy66gAZkxS6BniubAAAAABJRU5ErkJggg==);
17
+ background-repeat: no-repeat;
18
+ background-position: 0 .2em;
19
+ padding-left: 1.5em;
20
+ }
21
+ .done1 {
22
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAABtSURBVCiR1ZO7DYAwDER9BDmTeZQMFXmUbGYpOjrEryA0wOvO8itOslFrJYAug5BMM4BeSkmjsrv3aVTa8p48Xw1JSkSsWVUFwD05IqS1tmYzk5zzae9jnVVVzGyXb8sALjse+euRkEzu/uirFomVIdDGOLjuAAAAAElFTkSuQmCC);
23
+ background-repeat: no-repeat;
24
+ background-position: 0 .15em;
25
+ padding-left: 1.5em;
26
+ }
27
+ .done2 {
28
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAB1SURBVCiRzdO5DcAgDAVQGxjAYgTvxlDIu1FTIRYAp8qlFISkSH7l5kk+ZIwxKiI2mIyqWoeILYRgZ7GINDOLjnmF3VqklKCUMgTee2DmM661Qs55iI3Zm/1u5h9sm4ig9z4ERHTFzLyd4G4+nFlVrYg8+qoF/c0kdpeMsmcAAAAASUVORK5CYII=);
29
+ background-repeat: no-repeat;
30
+ background-position: 0 .15em;
31
+ padding-left: 1.5em;
32
+ }
33
+ .done3 {
34
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAABoSURBVCiR7dOxDcAgDATA/0DtUdiKoZC3YhLkHjkVKF3idJHiztKfvrHZWnOSE8Fx95RJzlprimJVnXktvXeY2S0SEZRSAAAbmxnGGKH2I5T+8VfxPhIReQSuuY3XyYWa3T2p6quvOgGrvSFGlewuUAAAAABJRU5ErkJggg==);
35
+ background-repeat: no-repeat;
36
+ background-position: 0 .15em;
37
+ padding-left: 1.5em;
38
+ }
39
+ .done4 {
40
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAQCAYAAAAbBi9cAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAzgAAAM4BlP6ToAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAIISURBVDiNnZQ9SFtRFMd/773kpTaGJoQk1im4VDpWQcTNODhkFBcVTCNCF0NWyeDiIIiCm82QoIMIUkHUxcFBg1SEQoZszSat6cdTn1qNue92CMbEr9Sey+XC/Z/zu+f8h6ukUil3sVg0+M+4cFxk42/jH2wAqqqKSCSiPQdwcHHAnDHH9s/tN1h8V28ETdP+eU8fT9Nt62ancYdIPvJNtsu87bmjrJlrTDVM4RROJs1JrHPrD4Bar7A6cpc54iKOaTdJXCUI2UMVrQZ0Js7YPN18ECKkYNQcJe/OE/4dZsw7VqNXQMvHy3QZXQypQ6ycrtwDjf8aJ+PNEDSCzLpn7+m2pD8ZKHlKarYhy6XjEoCYGcN95qansQeA3fNdki+SaJZGTMQIOoL3W/Z89rxv+tokubNajlvk/vm+LFpF2XnUKZHI0I+QrI7Dw0OZTqdzUkpsM7mZTyfy5OPGyw1tK7AFSvmB/Ks8w8YwbUYbe6/3QEKv0vugfxWPnMLJun+d/kI/WLdizpNjMbAIKrhMF4OuwadBALqqs+RfInwUvuNi+fBd+wjogfogAFVRmffO02q01mZZ0HHdgXIzdz0QQLPezIQygX6llxNKKgOFARYCC49CqhoHIUTlss/Vx2phlYwjw8j1CAlfAiwQiJpiy7o1VHnsG5FISkoJu7Q/2YmmaV+i0ei7v38L2CBguSi5AAAAAElFTkSuQmCC);
41
+ background-repeat: no-repeat;
42
+ background-position: 0 .15em;
43
+ padding-left: 1.5em;
44
+ }
45
+ </style>
7
46
  </head>
8
47
  <body id="%title%">
9
48
  <h2 id="title">%title%</h2>
@@ -70,7 +70,8 @@ module VimwikiMarkdown
70
70
  end
71
71
 
72
72
  def output_fullpath
73
- "#{output_dir}#{title.parameterize}.html"
73
+ filename = title.parameterize =~ /^\s*$/ ? title : title.parameterize
74
+ "#{output_dir}#{filename}.html"
74
75
  end
75
76
 
76
77
 
@@ -1,3 +1,3 @@
1
1
  module VimwikiMarkdown
2
- VERSION = "0.4.3"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -9,22 +9,24 @@
9
9
 
10
10
  module VimwikiMarkdown
11
11
  class VimwikiLink
12
- MARKDOWN_LINK_REGEX = /\[(?<title>.*)\]\((?<uri>.*)\)/
12
+ MARKDOWN_LINK_REGEX = /\[(?<title>.*)\]\((?<uri>(?:(?!#).)*)(?<fragment>(?:#)?.*)\)/
13
13
 
14
- attr_reader :title, :uri, :source_markdown_directory, :markdown_extension, :root_path
14
+ attr_reader :title, :uri, :fragment, :source_markdown_directory, :markdown_extension, :root_path, :output_dir
15
15
 
16
- def initialize(markdown_link, source_markdown_filepath, markdown_extension, root_path)
16
+ def initialize(markdown_link, source_markdown_filepath, markdown_extension, root_path, output_dir)
17
17
  @title = markdown_link.match(MARKDOWN_LINK_REGEX)[:title]
18
18
  @uri = markdown_link.match(MARKDOWN_LINK_REGEX)[:uri]
19
+ @fragment = markdown_link.match(MARKDOWN_LINK_REGEX)[:fragment]
19
20
  @markdown_extension = markdown_extension
20
21
  @root_path = root_path
21
22
  @source_markdown_directory = Pathname.new(source_markdown_filepath).dirname
23
+ @output_dir = output_dir
22
24
  rewrite_local_links!
23
25
  end
24
26
 
25
27
 
26
28
  def to_s
27
- "[#{title}](#{uri})"
29
+ "[#{title}](#{uri}#{fragment})"
28
30
  end
29
31
 
30
32
  private
@@ -32,8 +34,37 @@ module VimwikiMarkdown
32
34
  def rewrite_local_links!
33
35
  if vimwiki_markdown_file_exists?
34
36
  path = Pathname.new(uri)
35
- @uri = "#{path.dirname + path.basename(markdown_extension).to_s.parameterize}.html"
37
+
38
+ link_path = path.basename(markdown_extension).to_s.parameterize
39
+
40
+ link_path = path.basename(markdown_extension).to_s if link_path.match(/^\s*$/)
41
+
42
+ @uri = "#{path.dirname + link_path}.html"
43
+ @fragment = fragment.parameterize.prepend("#") unless fragment.empty?
44
+ elsif /^file:/.match(uri)
45
+ # begins with file: -> force absolute path if file exists
46
+ @uri = "#{source_markdown_directory + uri}" if uri_relative_path_exists?
47
+ elsif /^local:/.match(uri)
48
+ # begins with local: -> force relative path if file exists
49
+ source = Pathname.new(source_markdown_directory)
50
+ output = Pathname.new(output_dir)
51
+ @uri = "#{source.relative_path_from(output) + uri}" if uri_relative_path_exists?
52
+ end
53
+ end
54
+
55
+ def uri_relative_path_exists?
56
+ # remove file: or local: prefix
57
+ tmp = uri.sub(/^file:|^local:/, "") if uri.present?
58
+ path, title = tmp.split(/\.?\s+\"/) # handle image title
59
+ path = Pathname.new(path)
60
+ path = path.realpath.relative_path_from(source_markdown_directory) if path.absolute?
61
+
62
+ if File.exist?(source_markdown_directory + path)
63
+ title = "\"#{title}" unless title.nil? || title.empty?
64
+ @uri = "#{path.to_s.gsub(/\ /, '%20')} #{title}".strip
65
+ return true
36
66
  end
67
+ false
37
68
  end
38
69
 
39
70
  def vimwiki_markdown_file_exists?
@@ -25,8 +25,9 @@ class VimwikiMarkdown::WikiBody
25
25
  HTML::Pipeline::SyntaxHighlightFilter,
26
26
  HTML::Pipeline::TableOfContentsFilter
27
27
  ], { scope: "highlight"})
28
- result = pipeline.call(html)
29
- result[:output].to_s
28
+ @result = pipeline.call(html)
29
+ @result = @result[:output].to_s
30
+ enrich_li_class!
30
31
  end
31
32
 
32
33
 
@@ -63,7 +64,7 @@ class VimwikiMarkdown::WikiBody
63
64
 
64
65
  def convert_markdown_local_links!
65
66
  @markdown_body = @markdown_body.gsub(/\[.*?\]\(.*?\)/) do |match|
66
- VimwikiMarkdown::VimwikiLink.new(match, options.input_file, options.extension, options.root_path).to_s
67
+ VimwikiMarkdown::VimwikiLink.new(match, options.input_file, options.extension, options.root_path, options.output_dir).to_s
67
68
  end
68
69
  end
69
70
 
@@ -74,4 +75,15 @@ class VimwikiMarkdown::WikiBody
74
75
  CommonMarker.render_html(content, commonmarker_opts, commonmarker_exts)
75
76
  }
76
77
  end
78
+
79
+ def enrich_li_class!
80
+ syms_hash = { " ]" => 0, ".]" => 1, "o]" => 2, "O]" => 3, "X]" => 4 }
81
+ checkbox = /<li>\s*\[[\s.oOX]\]/
82
+ checkbox_start = /<li>\s*\[/
83
+ @result.gsub!(checkbox) do |m|
84
+ m.sub(checkbox_start, '<li class="done')
85
+ .sub(/[\s.oOX\]]*$/, syms_hash) << '">'
86
+ end
87
+ @result
88
+ end
77
89
  end
@@ -43,6 +43,11 @@ module VimwikiMarkdown
43
43
  expect(Options.new.output_fullpath).to eq("#{subject.output_dir}name-with-spaces.html")
44
44
  end
45
45
 
46
+ it "must not change filenames if paramteriezed returns an empty string" do
47
+ allow_any_instance_of(Options).to receive(:input_file) { "~/foo/世界.md" }
48
+ expect(Options.new.output_fullpath).to eq("#{subject.output_dir}世界.html")
49
+ end
50
+
46
51
  it "must correctly deal with filenames with capitalization issues" do
47
52
  allow_any_instance_of(Options).to receive(:input_file) { "~/foo/NAME WITH SPACES.md" }
48
53
  expect(Options.new.output_fullpath).to eq("#{subject.output_dir}name-with-spaces.html")
@@ -1,16 +1,33 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module VimwikiMarkdown
4
4
  describe VimwikiLink do
5
- let(:markdown_link) { "[title](http://www.google.com)" }
6
- let(:source_filepath) { "unimportant" }
7
5
  let(:markdown_extension) { ".md" }
8
6
  let(:root_path) { "-" }
9
7
 
10
- it "should leave external links alone" do
11
- link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
12
- expect(link.title).to eq("title")
13
- expect(link.uri).to eq("http://www.google.com")
8
+ context "external or fragment only" do
9
+ let(:markdown_link) { "[title](http://www.google.com)" }
10
+ let(:source_filepath) { "unimportant" }
11
+ let(:output_dir) { "unused in this scenario" }
12
+
13
+ it "should leave external links alone" do
14
+ link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
15
+ expect(link.to_s).to eq(markdown_link)
16
+ end
17
+
18
+ it "should not alter fragments which are part of a url" do
19
+ markdown_link = "[test](http://foo#Bar)"
20
+
21
+ link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
22
+ expect(link.to_s).to eq("[test](http://foo#Bar)")
23
+ end
24
+
25
+ it "should not alter fragment-only links" do
26
+ markdown_link = "[test](#GTD)"
27
+
28
+ link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
29
+ expect(link.to_s).to eq("[test](#GTD)")
30
+ end
14
31
  end
15
32
 
16
33
  context "with an existing markdown file matching name" do
@@ -19,10 +36,12 @@ module VimwikiMarkdown
19
36
  let(:temp_wiki_dir) { Pathname.new(Dir.mktmpdir("temp_wiki_")) }
20
37
  let(:markdown_link) { "[test](#{existing_file})" }
21
38
  let(:source_filepath) { temp_wiki_dir + "index.md" }
39
+ let(:output_dir) { temp_wiki_dir + "temp_output_dir" }
22
40
 
23
41
  before(:each) do
24
42
  # here we create a stub test filename in the directory,
25
43
  FileUtils.mkdir_p((temp_wiki_dir + existing_file).dirname)
44
+ FileUtils.mkdir_p(output_dir)
26
45
  FileUtils.touch(temp_wiki_dir + existing_file)
27
46
  end
28
47
 
@@ -31,35 +50,48 @@ module VimwikiMarkdown
31
50
  end
32
51
 
33
52
  it "must convert same-directory markdown links correctly" do
34
- link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
35
- expect(link.title).to eq("test")
36
- expect(link.uri).to eq("#{existing_file_no_extension}.html")
53
+ link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
54
+ expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
37
55
  end
38
56
 
39
57
  it "must convert same-directory markdown links with no extension correctly" do
40
- markdown_link = "[test](#{existing_file_no_extension})"
58
+ markdown_link = "[test](#{existing_file_no_extension})"
41
59
 
42
- link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
43
- expect(link.title).to eq("test")
44
- expect(link.uri).to eq("#{existing_file_no_extension}.html")
60
+ link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
61
+ expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
62
+ end
63
+
64
+ it "must convert same-directory markdown links with url fragments correctly" do
65
+ markdown_link = "[test](#{existing_file_no_extension}#Wiki Heading)"
66
+
67
+ link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
68
+ expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html#wiki-heading)")
69
+ end
70
+
71
+ context "with chinese or unparamaterizable chars" do
72
+ let(:existing_file) { "世界#{markdown_extension}" }
73
+
74
+ it "must convert same-directory markdown links without paramaterization correctly" do
75
+ markdown_link = "[test](#{existing_file_no_extension})"
76
+
77
+ link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
78
+ expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
79
+ end
45
80
  end
46
81
 
47
82
  context "subdirectory linked files" do
48
83
  let(:existing_file) { "subdirectory/test.md" }
49
84
 
50
85
  it "must convert markdown links correctly" do
51
- link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
52
- expect(link.title).to eq("test")
53
- expect(link.uri).to eq("#{existing_file_no_extension}.html")
86
+ link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
87
+ expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
54
88
  end
55
89
 
56
90
  it "must convert directory links correctly" do
57
- markdown_link = "[subdirectory](subdirectory/)"
58
- link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
59
- expect(link.title).to eq("subdirectory")
60
- expect(link.uri).to eq("subdirectory/")
91
+ markdown_link = "[subdirectory](subdirectory/)"
92
+ link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
93
+ expect(link.to_s).to eq("[subdirectory](subdirectory/)")
61
94
  end
62
-
63
95
  end
64
96
 
65
97
  context "../ style links" do
@@ -67,9 +99,8 @@ module VimwikiMarkdown
67
99
  let(:source_filepath) { temp_wiki_dir + "subdirectory/index.md" }
68
100
 
69
101
  it "must convert sub-directory markdown links correctly" do
70
- link = VimwikiLink.new("[test](../test)", source_filepath, markdown_extension, root_path)
71
- expect(link.title).to eq("test")
72
- expect(link.uri).to eq("../test.html")
102
+ link = VimwikiLink.new("[test](../test)", source_filepath, markdown_extension, root_path, output_dir)
103
+ expect(link.to_s).to eq("[test](../test.html)")
73
104
  end
74
105
  end
75
106
 
@@ -79,24 +110,50 @@ module VimwikiMarkdown
79
110
  let(:root_path) { "../"}
80
111
 
81
112
  it "must convert absolute paths correctly" do
82
- link = VimwikiLink.new("[test](/test.md)", source_filepath, markdown_extension, root_path)
83
- expect(link.uri).to eq("/test.html")
113
+ link = VimwikiLink.new("[test](/test.md)", source_filepath, markdown_extension, root_path, output_dir)
114
+ expect(link.to_s).to eq("[test](/test.html)")
84
115
  end
85
116
 
86
117
  it "must convert absolute paths without extension correctly" do
87
- link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, root_path)
88
- expect(link.uri).to eq("/test.html")
118
+ link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, root_path, output_dir)
119
+ expect(link.to_s).to eq("[test](/test.html)")
89
120
  end
90
121
 
91
122
  context "from the root directory" do
92
123
  let(:source_filepath) { temp_wiki_dir + "index.md" }
93
124
 
94
125
  it "must convert absolute paths correctly" do
95
- link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, ".")
96
- expect(link.uri).to eq("/test.html")
126
+ link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, ".", output_dir)
127
+ expect(link.to_s).to eq("[test](/test.html)")
97
128
  end
98
129
  end
99
130
  end
131
+
132
+ context "links with local: files" do
133
+ let(:sample_png) { "foo.png" }
134
+
135
+ before do
136
+ FileUtils.touch(temp_wiki_dir + sample_png)
137
+ end
138
+
139
+ it "must convert local paths correctly" do
140
+ link = VimwikiLink.new("[test](local:#{sample_png})", source_filepath, markdown_extension, root_path, output_dir)
141
+ expect(link.to_s).to eq("[test](../#{sample_png})")
142
+ end
143
+ end
144
+
145
+ context "links with file: files" do
146
+ let(:sample_png) { "foo.png" }
147
+
148
+ before do
149
+ FileUtils.touch(temp_wiki_dir + sample_png)
150
+ end
151
+
152
+ it "must convert local paths correctly" do
153
+ link = VimwikiLink.new("[test](file:#{sample_png})", source_filepath, markdown_extension, root_path, output_dir)
154
+ expect(link.to_s).to eq("[test](#{temp_wiki_dir + sample_png})")
155
+ end
156
+ end
100
157
  end
101
158
  end
102
159
  end
@@ -6,7 +6,7 @@ require 'rspec-html-matchers'
6
6
  module VimwikiMarkdown
7
7
  describe WikiBody do
8
8
 
9
- let(:wiki_body) { WikiBody.new(double(:options, input_file: 'blah', extension: 'md', root_path: '-')) }
9
+ let(:wiki_body) { WikiBody.new(double(:options, input_file: 'blah', extension: 'md', root_path: '-', output_dir: ".")) }
10
10
  let(:markdown_file_content) { wiki_index_markdown }
11
11
 
12
12
  it "must convert wiki links" do
@@ -52,6 +52,36 @@ module VimwikiMarkdown
52
52
  expect(wiki_body.to_s).to match(/<a href="there.html">there<\/a>/)
53
53
  end
54
54
 
55
+ it "must enrich task list unchecked" do
56
+ allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
57
+ allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [ ] This is one line")
58
+ expect(wiki_body.to_s).to match(/<li class="done0"> This is one line<\/li>/)
59
+ end
60
+
61
+ it "must enrich task list checked" do
62
+ allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
63
+ allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [X] This is a checked line")
64
+ expect(wiki_body.to_s).to match(/<li class="done4"> This is a checked line<\/li>/)
65
+ end
66
+
67
+ it "must enrich task list parent 1" do
68
+ allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
69
+ allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [.] This is a parent 1 line")
70
+ expect(wiki_body.to_s).to match(/<li class="done1"> This is a parent 1 line<\/li>/)
71
+ end
72
+
73
+ it "must enrich task list parent 2" do
74
+ allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
75
+ allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [o] This is a parent 2 line")
76
+ expect(wiki_body.to_s).to match(/<li class="done2"> This is a parent 2 line<\/li>/)
77
+ end
78
+
79
+ it "must enrich task list parent 3" do
80
+ allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
81
+ allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("- [O] This is a parent 3 line")
82
+ expect(wiki_body.to_s).to match(/<li class="done3"> This is a parent 3 line<\/li>/)
83
+ end
84
+
55
85
  describe "syntax highlighting" do
56
86
  it "must give correct classes" do
57
87
  allow(wiki_body).to receive(:get_wiki_markdown_contents)
data/spec/spec_helper.rb CHANGED
@@ -107,6 +107,28 @@ def wiki_index_markdown
107
107
 
108
108
  > this is a blockquote
109
109
  > without a linebreak
110
+
111
+ ## Test for checks
112
+
113
+ - [ ] This is one line
114
+ - [X] This is a checked line
115
+ - [ ] This is a parent line 1
116
+ - [ ] This is a child line 1
117
+ - [ ] This is a child line 2
118
+ - [.] This is a parent line 2
119
+ - [X] This is a child line 1
120
+ - [ ] This is a child line 2
121
+ - [ ] This is a child line 3
122
+ - [o] This is a parent line 2
123
+ - [X] This is a child line 1
124
+ - [X] This is a child line 2
125
+ - [ ] This is a child line 3
126
+ - [O] This is a parent line 3
127
+ - [X] This is a child line 1
128
+ - [X] This is a child line 2
129
+ - [X] This is a child line 3
130
+ - [ ] This is a child line 4
131
+
110
132
  "
111
133
  end
112
134
 
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.0"
22
- spec.add_development_dependency "rake", "~> 11.2"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake", "~> 12.3"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
24
  spec.add_development_dependency "pry", "~> 0.12"
25
25
  spec.add_development_dependency "rspec-its", "~> 1.1"
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimwiki_markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Davey
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-23 00:00:00.000000000 Z
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '11.2'
33
+ version: '12.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '11.2'
40
+ version: '12.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +220,8 @@ files:
220
220
  - ".rspec"
221
221
  - ".rubocop.yml"
222
222
  - ".travis.yml"
223
+ - A.png
224
+ - B.png
223
225
  - Gemfile
224
226
  - Guardfile
225
227
  - LICENSE.txt
@@ -245,7 +247,7 @@ homepage: https://github.com/patrickdavey/wimwiki_markdown
245
247
  licenses:
246
248
  - MIT
247
249
  metadata: {}
248
- post_install_message:
250
+ post_install_message:
249
251
  rdoc_options: []
250
252
  require_paths:
251
253
  - lib
@@ -260,8 +262,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
262
  - !ruby/object:Gem::Version
261
263
  version: '0'
262
264
  requirements: []
263
- rubygems_version: 3.0.4
264
- signing_key:
265
+ rubygems_version: 3.2.3
266
+ signing_key:
265
267
  specification_version: 4
266
268
  summary: Converts a github flavoured markdown vimwiki file into html.
267
269
  test_files: