vimwiki_markdown 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9350bfdab384da03bd60949b18575b0d29b69df197e73370e5e20d5124a2105e
4
- data.tar.gz: acf9164c1ff195e280364de0e3a341c618a7d892989a6d7702e6a7eab57bdd20
3
+ metadata.gz: bdd35443aa295839dff9ecc54fcaaf48616e7fa53b5733be67edb2fee17b9320
4
+ data.tar.gz: 711548c56d682b546f93e8e22d80f8dc948947bf3f9eee2bff4caeafdd475943
5
5
  SHA512:
6
- metadata.gz: 25a3d1674dd3b8511ccc76e0be69b77e08a7aa87a311895019e0cb5649d65e37e4ef12423521318a4e35d6415e9bd205c9836f0b26233eab8a360b112cd85d2a
7
- data.tar.gz: bdb112d177af8f0d5f039b847e9e94bd5d274aaf075b8a037ac7326f392c8393a4aac3fd6da18819c760066c447670d826b091b9c33d791b9f14e286a1994f3a
6
+ metadata.gz: 77964b75a2cedd98f97af51d7f738730c6740f3d3b634b4efea9a26ff438c7cd94f5fca1034ea4a0eca7a76355453d0992984693a08ce3f1da3b3f5d546496ad
7
+ data.tar.gz: 7cd72fdeaee7b2ee7718955b2b628ab8358a9b4eb3de2cadac63b952e93a13d605a8a0de3eb9064a2e821b92ea2c89bd8d319127356dad6e3548ba1c2243383e
@@ -1,3 +1,6 @@
1
+ ## 0.4.4 [June 16 2019]
2
+ Allow fragments if they are for local vimwiki links only
3
+
1
4
  ## 0.4.3 [June 16 2019]
2
5
  temporarily revoke fragments until we're not altering old links
3
6
 
@@ -1,3 +1,3 @@
1
1
  module VimwikiMarkdown
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -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.title).to eq("title")
13
- expect(link.uri).to eq("http://www.google.com")
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.title).to eq("test")
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.title).to eq("test")
44
- expect(link.uri).to eq("#{existing_file_no_extension}.html")
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.title).to eq("test")
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.title).to eq("subdirectory")
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.title).to eq("test")
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.uri).to eq("/test.html")
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.uri).to eq("/test.html")
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.uri).to eq("/test.html")
111
+ expect(link.to_s).to eq("[test](/test.html)")
97
112
  end
98
113
  end
99
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Davey