vimwiki_markdown 0.4.3 → 0.4.4
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/changelog.md +3 -0
- data/lib/vimwiki_markdown/version.rb +1 -1
- data/lib/vimwiki_markdown/vimwiki_link.rb +5 -3
- data/spec/lib/vimwiki_markdown/vimwiki_link_spec.rb +30 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdd35443aa295839dff9ecc54fcaaf48616e7fa53b5733be67edb2fee17b9320
|
4
|
+
data.tar.gz: 711548c56d682b546f93e8e22d80f8dc948947bf3f9eee2bff4caeafdd475943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77964b75a2cedd98f97af51d7f738730c6740f3d3b634b4efea9a26ff438c7cd94f5fca1034ea4a0eca7a76355453d0992984693a08ce3f1da3b3f5d546496ad
|
7
|
+
data.tar.gz: 7cd72fdeaee7b2ee7718955b2b628ab8358a9b4eb3de2cadac63b952e93a13d605a8a0de3eb9064a2e821b92ea2c89bd8d319127356dad6e3548ba1c2243383e
|
data/changelog.md
CHANGED
@@ -9,13 +9,14 @@
|
|
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
|
15
15
|
|
16
16
|
def initialize(markdown_link, source_markdown_filepath, markdown_extension, root_path)
|
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
|
@@ -24,7 +25,7 @@ module VimwikiMarkdown
|
|
24
25
|
|
25
26
|
|
26
27
|
def to_s
|
27
|
-
"[#{title}](#{uri})"
|
28
|
+
"[#{title}](#{uri}#{fragment})"
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
@@ -33,6 +34,7 @@ module VimwikiMarkdown
|
|
33
34
|
if vimwiki_markdown_file_exists?
|
34
35
|
path = Pathname.new(uri)
|
35
36
|
@uri = "#{path.dirname + path.basename(markdown_extension).to_s.parameterize}.html"
|
37
|
+
@fragment = fragment.parameterize.prepend("#") unless fragment.empty?
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
@@ -9,8 +9,21 @@ module VimwikiMarkdown
|
|
9
9
|
|
10
10
|
it "should leave external links alone" do
|
11
11
|
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
12
|
-
expect(link.
|
13
|
-
|
12
|
+
expect(link.to_s).to eq(markdown_link)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should not alter fragments which are part of a url" do
|
16
|
+
markdown_link = "[test](http://foo#Bar)"
|
17
|
+
|
18
|
+
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
19
|
+
expect(link.to_s).to eq("[test](http://foo#Bar)")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not alter fragment-only links" do
|
23
|
+
markdown_link = "[test](#GTD)"
|
24
|
+
|
25
|
+
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
26
|
+
expect(link.to_s).to eq("[test](#GTD)")
|
14
27
|
end
|
15
28
|
|
16
29
|
context "with an existing markdown file matching name" do
|
@@ -32,16 +45,21 @@ module VimwikiMarkdown
|
|
32
45
|
|
33
46
|
it "must convert same-directory markdown links correctly" do
|
34
47
|
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
35
|
-
expect(link.
|
36
|
-
expect(link.uri).to eq("#{existing_file_no_extension}.html")
|
48
|
+
expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
|
37
49
|
end
|
38
50
|
|
39
51
|
it "must convert same-directory markdown links with no extension correctly" do
|
40
52
|
markdown_link = "[test](#{existing_file_no_extension})"
|
41
53
|
|
42
54
|
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
43
|
-
expect(link.
|
44
|
-
|
55
|
+
expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "must convert same-directory markdown links with url fragments correctly" do
|
59
|
+
markdown_link = "[test](#{existing_file_no_extension}#Wiki Heading)"
|
60
|
+
|
61
|
+
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
62
|
+
expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html#wiki-heading)")
|
45
63
|
end
|
46
64
|
|
47
65
|
context "subdirectory linked files" do
|
@@ -49,15 +67,13 @@ module VimwikiMarkdown
|
|
49
67
|
|
50
68
|
it "must convert markdown links correctly" do
|
51
69
|
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
52
|
-
expect(link.
|
53
|
-
expect(link.uri).to eq("#{existing_file_no_extension}.html")
|
70
|
+
expect(link.to_s).to eq("[test](#{existing_file_no_extension}.html)")
|
54
71
|
end
|
55
72
|
|
56
73
|
it "must convert directory links correctly" do
|
57
74
|
markdown_link = "[subdirectory](subdirectory/)"
|
58
75
|
link = VimwikiLink.new(markdown_link, source_filepath, markdown_extension, root_path)
|
59
|
-
expect(link.
|
60
|
-
expect(link.uri).to eq("subdirectory/")
|
76
|
+
expect(link.to_s).to eq("[subdirectory](subdirectory/)")
|
61
77
|
end
|
62
78
|
|
63
79
|
end
|
@@ -68,8 +84,7 @@ module VimwikiMarkdown
|
|
68
84
|
|
69
85
|
it "must convert sub-directory markdown links correctly" do
|
70
86
|
link = VimwikiLink.new("[test](../test)", source_filepath, markdown_extension, root_path)
|
71
|
-
expect(link.
|
72
|
-
expect(link.uri).to eq("../test.html")
|
87
|
+
expect(link.to_s).to eq("[test](../test.html)")
|
73
88
|
end
|
74
89
|
end
|
75
90
|
|
@@ -80,12 +95,12 @@ module VimwikiMarkdown
|
|
80
95
|
|
81
96
|
it "must convert absolute paths correctly" do
|
82
97
|
link = VimwikiLink.new("[test](/test.md)", source_filepath, markdown_extension, root_path)
|
83
|
-
expect(link.
|
98
|
+
expect(link.to_s).to eq("[test](/test.html)")
|
84
99
|
end
|
85
100
|
|
86
101
|
it "must convert absolute paths without extension correctly" do
|
87
102
|
link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, root_path)
|
88
|
-
expect(link.
|
103
|
+
expect(link.to_s).to eq("[test](/test.html)")
|
89
104
|
end
|
90
105
|
|
91
106
|
context "from the root directory" do
|
@@ -93,7 +108,7 @@ module VimwikiMarkdown
|
|
93
108
|
|
94
109
|
it "must convert absolute paths correctly" do
|
95
110
|
link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, ".")
|
96
|
-
expect(link.
|
111
|
+
expect(link.to_s).to eq("[test](/test.html)")
|
97
112
|
end
|
98
113
|
end
|
99
114
|
end
|