vimwiki_markdown 0.4.4 → 0.5.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 +4 -4
- data/README.md +9 -2
- data/changelog.md +3 -0
- data/lib/vimwiki_markdown/version.rb +1 -1
- data/lib/vimwiki_markdown/vimwiki_link.rb +26 -2
- data/lib/vimwiki_markdown/wiki_body.rb +1 -1
- data/spec/lib/vimwiki_markdown/vimwiki_link_spec.rb +60 -29
- data/spec/lib/vimwiki_markdown/wiki_body_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5a405825bd200606206847893bfe9bf8c923ce22c93cb9e63338e604b8dd0ab
|
4
|
+
data.tar.gz: 4688061eb966a4d76d84f12fbb6100a252dc7f7b7ef24d6c444d95c5a658c8c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d596d8fdc9e3f88a66fe70e46e2e7a6e60caa06aec14fd2268fcaacc47190cfd385dca3187428342822af91ab7b410bd55012054eb40b188f62ae579a4161dd
|
7
|
+
data.tar.gz: ee2fdbfab074ebc339496a61d70751839899780e9bb9cb66596da7a6b118c04193c2c9c461523651dd6c86b435efd21549485486f2857a9220dac4b4f52ce8fb
|
data/README.md
CHANGED
@@ -56,14 +56,21 @@ of the site (e.g. `./` or `../../` etc)
|
|
56
56
|
You can also have a `%date%` marker in your template file
|
57
57
|
It will get rewritten with todays date in the format 29 March 2019
|
58
58
|
|
59
|
+
#### Support for :local and :file links
|
60
|
+
|
61
|
+
We have partial support for the `:local` and `:file` link types for vimwiki.
|
62
|
+
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:
|
63
|
+
|
64
|
+
* `[link text](local:bar.txt)` when output to HTML becomes <a href="../bar.txt">link text</a>
|
65
|
+
* `[link text](file:bar.txt)` when output to HTML becomes <a href="/absolute/path/to/file">link text</a>
|
66
|
+
|
59
67
|
#### Optional %nohtml
|
60
68
|
|
61
69
|
If you place the text %nohtml anywhere in a wiki page, it will not be processed into html
|
62
70
|
|
63
71
|
## Contributing
|
64
72
|
|
65
|
-
Pull requests are very welcome
|
66
|
-
more interesting vimwiki links (e.g. :local etc.)
|
73
|
+
Pull requests are very welcome
|
67
74
|
|
68
75
|
1. Fork it ( https://github.com/patrickdavey/vimwiki_markdown/fork )
|
69
76
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
data/changelog.md
CHANGED
@@ -11,15 +11,16 @@ module VimwikiMarkdown
|
|
11
11
|
class VimwikiLink
|
12
12
|
MARKDOWN_LINK_REGEX = /\[(?<title>.*)\]\((?<uri>(?:(?!#).)*)(?<fragment>(?:#)?.*)\)/
|
13
13
|
|
14
|
-
attr_reader :title, :uri, :fragment, :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
19
|
@fragment = markdown_link.match(MARKDOWN_LINK_REGEX)[:fragment]
|
20
20
|
@markdown_extension = markdown_extension
|
21
21
|
@root_path = root_path
|
22
22
|
@source_markdown_directory = Pathname.new(source_markdown_filepath).dirname
|
23
|
+
@output_dir = output_dir
|
23
24
|
rewrite_local_links!
|
24
25
|
end
|
25
26
|
|
@@ -35,9 +36,32 @@ module VimwikiMarkdown
|
|
35
36
|
path = Pathname.new(uri)
|
36
37
|
@uri = "#{path.dirname + path.basename(markdown_extension).to_s.parameterize}.html"
|
37
38
|
@fragment = fragment.parameterize.prepend("#") unless fragment.empty?
|
39
|
+
elsif /^file:/.match?(uri)
|
40
|
+
# begins with file: -> force absolute path if file exists
|
41
|
+
@uri = "#{source_markdown_directory + uri}" if uri_relative_path_exists?
|
42
|
+
elsif /^local:/.match?(uri)
|
43
|
+
# begins with local: -> force relative path if file exists
|
44
|
+
source = Pathname.new(source_markdown_directory)
|
45
|
+
output = Pathname.new(output_dir)
|
46
|
+
@uri = "#{source.relative_path_from(output) + uri}" if uri_relative_path_exists?
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
50
|
+
def uri_relative_path_exists?
|
51
|
+
# remove file: or local: prefix
|
52
|
+
tmp = uri.sub(/^file:|^local:/, "") if uri.present?
|
53
|
+
path, title = tmp.split(/\.?\s+\"/) # handle image title
|
54
|
+
path = Pathname.new(path)
|
55
|
+
path = path.realpath.relative_path_from(source_markdown_directory) if path.absolute?
|
56
|
+
|
57
|
+
if File.exist?(source_markdown_directory + path)
|
58
|
+
title = "\"#{title}" unless title.nil? || title.empty?
|
59
|
+
@uri = "#{path.to_s.gsub(/\ /, '%20')} #{title}".strip
|
60
|
+
return true
|
61
|
+
end
|
62
|
+
false
|
63
|
+
end
|
64
|
+
|
41
65
|
def vimwiki_markdown_file_exists?
|
42
66
|
File.exist?((source_markdown_directory + uri).sub_ext(markdown_extension)) ||
|
43
67
|
absolute_path_to_markdown_file_exists?
|
@@ -63,7 +63,7 @@ class VimwikiMarkdown::WikiBody
|
|
63
63
|
|
64
64
|
def convert_markdown_local_links!
|
65
65
|
@markdown_body = @markdown_body.gsub(/\[.*?\]\(.*?\)/) do |match|
|
66
|
-
VimwikiMarkdown::VimwikiLink.new(match, options.input_file, options.extension, options.root_path).to_s
|
66
|
+
VimwikiMarkdown::VimwikiLink.new(match, options.input_file, options.extension, options.root_path, options.output_dir).to_s
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -1,29 +1,33 @@
|
|
1
|
-
require
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
it "should not alter fragments which are part of a url" do
|
16
|
-
markdown_link = "[test](http://foo#Bar)"
|
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" }
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
it "should not alter fragment-only links" do
|
26
|
+
markdown_link = "[test](#GTD)"
|
24
27
|
|
25
|
-
|
26
|
-
|
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
|
27
31
|
end
|
28
32
|
|
29
33
|
context "with an existing markdown file matching name" do
|
@@ -32,10 +36,12 @@ module VimwikiMarkdown
|
|
32
36
|
let(:temp_wiki_dir) { Pathname.new(Dir.mktmpdir("temp_wiki_")) }
|
33
37
|
let(:markdown_link) { "[test](#{existing_file})" }
|
34
38
|
let(:source_filepath) { temp_wiki_dir + "index.md" }
|
39
|
+
let(:output_dir) { temp_wiki_dir + "temp_output_dir" }
|
35
40
|
|
36
41
|
before(:each) do
|
37
42
|
# here we create a stub test filename in the directory,
|
38
43
|
FileUtils.mkdir_p((temp_wiki_dir + existing_file).dirname)
|
44
|
+
FileUtils.mkdir_p(output_dir)
|
39
45
|
FileUtils.touch(temp_wiki_dir + existing_file)
|
40
46
|
end
|
41
47
|
|
@@ -44,21 +50,21 @@ module VimwikiMarkdown
|
|
44
50
|
end
|
45
51
|
|
46
52
|
it "must convert same-directory markdown links correctly" do
|
47
|
-
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
53
|
+
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
|
48
54
|
expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
|
49
55
|
end
|
50
56
|
|
51
57
|
it "must convert same-directory markdown links with no extension correctly" do
|
52
|
-
markdown_link =
|
58
|
+
markdown_link = "[test](#{existing_file_no_extension})"
|
53
59
|
|
54
|
-
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
60
|
+
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
|
55
61
|
expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
|
56
62
|
end
|
57
63
|
|
58
64
|
it "must convert same-directory markdown links with url fragments correctly" do
|
59
65
|
markdown_link = "[test](#{existing_file_no_extension}#Wiki Heading)"
|
60
66
|
|
61
|
-
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
67
|
+
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
|
62
68
|
expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html#wiki-heading)")
|
63
69
|
end
|
64
70
|
|
@@ -66,16 +72,15 @@ module VimwikiMarkdown
|
|
66
72
|
let(:existing_file) { "subdirectory/test.md" }
|
67
73
|
|
68
74
|
it "must convert markdown links correctly" do
|
69
|
-
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
75
|
+
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
|
70
76
|
expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
|
71
77
|
end
|
72
78
|
|
73
79
|
it "must convert directory links correctly" do
|
74
|
-
markdown_link =
|
75
|
-
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
80
|
+
markdown_link = "[subdirectory](subdirectory/)"
|
81
|
+
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path, output_dir)
|
76
82
|
expect(link.to_s).to eq("[subdirectory](subdirectory/)")
|
77
83
|
end
|
78
|
-
|
79
84
|
end
|
80
85
|
|
81
86
|
context "../ style links" do
|
@@ -83,7 +88,7 @@ module VimwikiMarkdown
|
|
83
88
|
let(:source_filepath) { temp_wiki_dir + "subdirectory/index.md" }
|
84
89
|
|
85
90
|
it "must convert sub-directory markdown links correctly" do
|
86
|
-
link = VimwikiLink.new("[test](../test)", source_filepath, markdown_extension, root_path)
|
91
|
+
link = VimwikiLink.new("[test](../test)", source_filepath, markdown_extension, root_path, output_dir)
|
87
92
|
expect(link.to_s).to eq("[test](../test.html)")
|
88
93
|
end
|
89
94
|
end
|
@@ -94,12 +99,12 @@ module VimwikiMarkdown
|
|
94
99
|
let(:root_path) { "../"}
|
95
100
|
|
96
101
|
it "must convert absolute paths correctly" do
|
97
|
-
link = VimwikiLink.new("[test](/test.md)", source_filepath, markdown_extension, root_path)
|
102
|
+
link = VimwikiLink.new("[test](/test.md)", source_filepath, markdown_extension, root_path, output_dir)
|
98
103
|
expect(link.to_s).to eq("[test](/test.html)")
|
99
104
|
end
|
100
105
|
|
101
106
|
it "must convert absolute paths without extension correctly" do
|
102
|
-
link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, root_path)
|
107
|
+
link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, root_path, output_dir)
|
103
108
|
expect(link.to_s).to eq("[test](/test.html)")
|
104
109
|
end
|
105
110
|
|
@@ -107,11 +112,37 @@ module VimwikiMarkdown
|
|
107
112
|
let(:source_filepath) { temp_wiki_dir + "index.md" }
|
108
113
|
|
109
114
|
it "must convert absolute paths correctly" do
|
110
|
-
link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, ".")
|
115
|
+
link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, ".", output_dir)
|
111
116
|
expect(link.to_s).to eq("[test](/test.html)")
|
112
117
|
end
|
113
118
|
end
|
114
119
|
end
|
120
|
+
|
121
|
+
context "links with local: files" do
|
122
|
+
let(:sample_png) { "foo.png" }
|
123
|
+
|
124
|
+
before do
|
125
|
+
FileUtils.touch(temp_wiki_dir + sample_png)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "must convert local paths correctly" do
|
129
|
+
link = VimwikiLink.new("[test](local:#{sample_png})", source_filepath, markdown_extension, root_path, output_dir)
|
130
|
+
expect(link.to_s).to eq("[test](../#{sample_png})")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "links with file: files" do
|
135
|
+
let(:sample_png) { "foo.png" }
|
136
|
+
|
137
|
+
before do
|
138
|
+
FileUtils.touch(temp_wiki_dir + sample_png)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "must convert local paths correctly" do
|
142
|
+
link = VimwikiLink.new("[test](file:#{sample_png})", source_filepath, markdown_extension, root_path, output_dir)
|
143
|
+
expect(link.to_s).to eq("[test](#{temp_wiki_dir + sample_png})")
|
144
|
+
end
|
145
|
+
end
|
115
146
|
end
|
116
147
|
end
|
117
148
|
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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vimwiki_markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Davey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|