vimwiki_markdown 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -6
- data/changelog.md +7 -0
- data/lib/vimwiki_markdown/options.rb +6 -5
- data/lib/vimwiki_markdown/version.rb +1 -1
- data/lib/vimwiki_markdown/vimwiki_link.rb +52 -0
- data/lib/vimwiki_markdown/wiki_body.rb +27 -4
- data/lib/vimwiki_markdown.rb +1 -0
- data/spec/lib/vimwiki_markdown/options_spec.rb +1 -1
- data/spec/lib/vimwiki_markdown/vimwiki_link_spec.rb +94 -0
- data/spec/lib/vimwiki_markdown/wiki_body_spec.rb +17 -6
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 726b831c9bb819ebbe7bd054e85d47926d008142
|
4
|
+
data.tar.gz: 2fc210b9ee34a717e9ea98b51122f646e1e8629f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa137e60a6d1e2e53ee2f0a46a55b14de20971ddb29d31eafe182adb3b9dd4a228596fb8210d9b2f3ce2f56e8b9d81db14220f15c2d3407074cb013151ff37c8
|
7
|
+
data.tar.gz: d71c4e2e0ff8e45d2dac61f6c3ebd1de3bfe4e784880113becaeb13ec06302a9db09ef5eb0265ff097478ead5378c8c31434707b692cc169e11d1fe1cda25aa2
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ It is currently a work in progress (but working for me ;)
|
|
8
8
|
|
9
9
|
## Requirements
|
10
10
|
|
11
|
-
Ruby installed on your computer
|
11
|
+
Ruby installed on your computer & up to date version of vimwiki
|
12
12
|
|
13
13
|
https://www.ruby-lang.org/en/installation/
|
14
14
|
|
@@ -16,11 +16,6 @@ Install the vimwiki_markdown gem
|
|
16
16
|
|
17
17
|
$ gem install vimwiki_markdown
|
18
18
|
|
19
|
-
Note, the current version of vimwiki does not allow binaries to be called
|
20
|
-
for the generation of html. This was added on the master branch in [this commit](https://github.com/vimwiki/vimwiki/commit/c1a5bb51adc8cacaa70e2804106817b68295f932)
|
21
|
-
|
22
|
-
Currently you will need to make sure you are running the dev branch of vimwiki, or add that commit in yourself
|
23
|
-
|
24
19
|
## Setup
|
25
20
|
|
26
21
|
Ensure that your vimiwiki directive in your .vimrc is setup for markdown. For
|
@@ -64,6 +59,9 @@ A sample tpl file is available here https://raw.githubusercontent.com/patrickdav
|
|
64
59
|
|
65
60
|
## Contributing
|
66
61
|
|
62
|
+
Pull requests are very welcome, especially if you want to implement some of the
|
63
|
+
more interesting vimwiki links (e.g. :local etc.)
|
64
|
+
|
67
65
|
1. Fork it ( https://github.com/patrickdavey/vimwiki_markdown/fork )
|
68
66
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
67
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/changelog.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.2.0 [March 6th 2016]
|
2
|
+
* Adds the ability for `[[source|title]]` style links to be parsed correctly
|
3
|
+
* Allows links with subdirectories `[[path/in/a/subdir/file]]` links to work
|
4
|
+
* Also allows vimwiki links formatted with markdown syntax to work, this
|
5
|
+
feature is currently implemented on the dev branch. This means you can
|
6
|
+
link to [my markdownfile](blah.md) and it'll be parsed correctly
|
7
|
+
|
1
8
|
## 0.1.3 [August 11th 2015]
|
2
9
|
* Adding the TableOfContents filter so that bookmarks are created.
|
3
10
|
|
@@ -5,13 +5,13 @@ module VimwikiMarkdown
|
|
5
5
|
DEFAULTS = ["1", #force - 1/0
|
6
6
|
"markdown",
|
7
7
|
"md",
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
8
|
+
"~/vimwiki/site_html/",
|
9
|
+
"~/vimwiki/index.md",
|
10
|
+
"~/vimwiki/site_html/style.css",
|
11
|
+
"~/vimwiki/templates/",
|
12
12
|
"default",
|
13
13
|
".tpl",
|
14
|
-
"-"]
|
14
|
+
"-"].freeze
|
15
15
|
|
16
16
|
FORCE = 0
|
17
17
|
SYNTAX = 1
|
@@ -53,6 +53,7 @@ module VimwikiMarkdown
|
|
53
53
|
@template_default = arguments[TEMPLATE_DEFAULT]
|
54
54
|
@template_ext = arguments[TEMPLATE_EXT]
|
55
55
|
@root_path = arguments[ROOT_PATH]
|
56
|
+
@root_path = "." if @root_path == "-"
|
56
57
|
raise "Must be markdown" unless syntax == 'markdown'
|
57
58
|
end
|
58
59
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# This class takes in a string of a markdown link and spits out
|
2
|
+
# a correctly formed markdown link, with absolute and relative
|
3
|
+
# links to markdown files correctly altered.
|
4
|
+
#
|
5
|
+
# The main thing we're working around is that markdown files can
|
6
|
+
# be linked to with (or without) an extension. That and we're also
|
7
|
+
# rewiring the filenames to be parameterized
|
8
|
+
|
9
|
+
|
10
|
+
module VimwikiMarkdown
|
11
|
+
class VimwikiLink
|
12
|
+
MARKDOWN_LINK_REGEX = /\[(?<title>.*)\]\((?<uri>.*)\)/
|
13
|
+
|
14
|
+
attr_reader :title, :uri, :source_markdown_directory, :markdown_extension, :root_path
|
15
|
+
|
16
|
+
def initialize(markdown_link, source_markdown_filepath, markdown_extension, root_path)
|
17
|
+
@title = markdown_link.match(MARKDOWN_LINK_REGEX)[:title]
|
18
|
+
@uri = markdown_link.match(MARKDOWN_LINK_REGEX)[:uri]
|
19
|
+
@markdown_extension = markdown_extension
|
20
|
+
@root_path = root_path
|
21
|
+
@source_markdown_directory = Pathname.new(source_markdown_filepath).dirname
|
22
|
+
rewrite_local_links!
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
"[#{title}](#{uri})"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def rewrite_local_links!
|
33
|
+
if vimwiki_markdown_file_exists?
|
34
|
+
path = Pathname.new(uri)
|
35
|
+
@uri = "#{path.dirname + path.basename(markdown_extension).to_s.parameterize}.html"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def vimwiki_markdown_file_exists?
|
40
|
+
File.exist?(source_markdown_directory + uri) ||
|
41
|
+
File.exist?(source_markdown_directory + "#{uri}.#{markdown_extension}") ||
|
42
|
+
absolute_path_exists?
|
43
|
+
end
|
44
|
+
|
45
|
+
def absolute_path_exists?
|
46
|
+
path = Pathname(uri)
|
47
|
+
path.absolute? && (
|
48
|
+
File.exist?(source_markdown_directory + root_path + path.to_s.sub(/^\//,"")) ||
|
49
|
+
File.exist?(source_markdown_directory + root_path + path.to_s.sub(/^\//,"").sub(/$/, ".#{markdown_extension}")))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
2
|
require 'github/markup'
|
3
3
|
require 'html/pipeline'
|
4
|
+
require 'pathname'
|
5
|
+
require "vimwiki_markdown/vimwiki_link"
|
4
6
|
|
5
7
|
class VimwikiMarkdown::WikiBody
|
6
8
|
|
@@ -31,11 +33,32 @@ class VimwikiMarkdown::WikiBody
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def fixlinks
|
34
|
-
|
35
|
-
|
36
|
+
convert_wiki_style_links_with_title_bar!
|
37
|
+
convert_wiki_style_links!
|
38
|
+
convert_markdown_local_links!
|
39
|
+
end
|
40
|
+
|
41
|
+
def convert_wiki_style_links_with_title_bar!
|
42
|
+
wiki_bar = /\[\[(?<source>.*)\|(?<title>.*)\]\]/
|
43
|
+
@markdown_body.gsub!(wiki_bar) do
|
44
|
+
source = Regexp.last_match[:source]
|
45
|
+
title = Regexp.last_match[:title]
|
46
|
+
"[#{title}](#{source})"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def convert_wiki_style_links!
|
36
51
|
@markdown_body.gsub!(/\[\[(.*?)\]\]/) do
|
37
|
-
|
38
|
-
"[#{
|
52
|
+
link= Regexp.last_match[1]
|
53
|
+
"[#{link}](#{link})"
|
39
54
|
end
|
40
55
|
end
|
56
|
+
|
57
|
+
def convert_markdown_local_links!
|
58
|
+
@markdown_body.gsub!(/\[.*\]\(.*\)/) do |match|
|
59
|
+
VimwikiMarkdown::VimwikiLink.new(match, options.input_file, options.extension, options.root_path).to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
41
64
|
end
|
data/lib/vimwiki_markdown.rb
CHANGED
@@ -13,7 +13,7 @@ module VimwikiMarkdown
|
|
13
13
|
its(:force) { should be(true) }
|
14
14
|
its(:syntax) { should eq('markdown') }
|
15
15
|
its(:output_fullpath) { should eq("#{subject.output_dir}#{subject.title.parameterize}.html") }
|
16
|
-
its(:template_filename) { should eq('
|
16
|
+
its(:template_filename) { should eq('~/vimwiki/templates/default.tpl') }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module VimwikiMarkdown
|
4
|
+
describe VimwikiLink do
|
5
|
+
let(:markdown_link) { "[title](http://www.google.com)" }
|
6
|
+
let(:source_filepath) { "unimportant" }
|
7
|
+
let(:markdown_extension) { "md" }
|
8
|
+
let(:root_path) { "-" }
|
9
|
+
|
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")
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with an existing markdown file matching name" do
|
17
|
+
let(:existing_file) { "test.#{markdown_extension}" }
|
18
|
+
let(:existing_file_no_extension) { existing_file.gsub(/\.#{markdown_extension}$/,"") }
|
19
|
+
let(:temp_wiki_dir) { Pathname.new(Dir.mktmpdir("temp_wiki_")) }
|
20
|
+
let(:markdown_link) { "[test](#{existing_file})" }
|
21
|
+
let(:source_filepath) { temp_wiki_dir + "index.md" }
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
# here we create a stub test filename in the directory,
|
25
|
+
FileUtils.mkdir_p((temp_wiki_dir + existing_file).dirname)
|
26
|
+
FileUtils.touch(temp_wiki_dir + existing_file)
|
27
|
+
end
|
28
|
+
|
29
|
+
after(:each) do
|
30
|
+
FileUtils.rm_r(temp_wiki_dir)
|
31
|
+
end
|
32
|
+
|
33
|
+
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")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "must convert same-directory markdown links with no extension correctly" do
|
40
|
+
markdown_link = "[test](#{existing_file_no_extension})"
|
41
|
+
|
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")
|
45
|
+
end
|
46
|
+
|
47
|
+
context "subdirectory linked files" do
|
48
|
+
let(:existing_file) { "subdirectory/test.md" }
|
49
|
+
|
50
|
+
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")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "../ style links" do
|
58
|
+
let(:existing_file) { "test.md" }
|
59
|
+
let(:source_filepath) { temp_wiki_dir + "subdirectory/index.md" }
|
60
|
+
|
61
|
+
it "must convert sub-directory markdown links correctly" do
|
62
|
+
link = VimwikiLink.new("[test](../test)", source_filepath, markdown_extension, root_path)
|
63
|
+
expect(link.title).to eq("test")
|
64
|
+
expect(link.uri).to eq("../test.html")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "aboslutely linked files" do
|
69
|
+
let(:existing_file) { "test.md" }
|
70
|
+
let(:source_filepath) { temp_wiki_dir + "subdirectory/index.md" }
|
71
|
+
let(:root_path) { "../"}
|
72
|
+
|
73
|
+
it "must convert absolute paths correctly" do
|
74
|
+
link = VimwikiLink.new("[test](/test.md)", source_filepath, markdown_extension, root_path)
|
75
|
+
expect(link.uri).to eq("/test.html")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "must convert absolute paths without extension correctly" do
|
79
|
+
link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, root_path)
|
80
|
+
expect(link.uri).to eq("/test.html")
|
81
|
+
end
|
82
|
+
|
83
|
+
context "from the root directory" do
|
84
|
+
let(:source_filepath) { temp_wiki_dir + "index.md" }
|
85
|
+
|
86
|
+
it "must convert absolute paths correctly" do
|
87
|
+
link = VimwikiLink.new("[test](/test)", source_filepath, markdown_extension, ".")
|
88
|
+
expect(link.uri).to eq("/test.html")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -6,20 +6,31 @@ require 'rspec-html-matchers'
|
|
6
6
|
module VimwikiMarkdown
|
7
7
|
describe WikiBody do
|
8
8
|
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
before do
|
12
|
-
allow(Options).to receive(:arguments).and_return(Options::DEFAULTS)
|
13
|
-
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return(wiki_index_markdown)
|
14
|
-
end
|
9
|
+
let(:wiki_body) { WikiBody.new(double(:options, input_file: 'blah', extension: 'md', root_path: '-')) }
|
10
|
+
let(:markdown_file_content) { wiki_index_markdown }
|
15
11
|
|
16
12
|
it "must convert wiki links" do
|
13
|
+
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return(markdown_file_content)
|
14
|
+
allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
|
17
15
|
expect(wiki_body.to_s).to match(/<a href="books.html">Books<\/a>/)
|
18
16
|
end
|
19
17
|
|
18
|
+
it "must convert wiki links with separate titles correctly" do
|
19
|
+
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("[[http://www.google.com|google]]")
|
20
|
+
expect(wiki_body.to_s).to match(/<a href="http:\/\/www.google.com">google<\/a>/)
|
21
|
+
end
|
22
|
+
|
20
23
|
it "must not put a break tag in a blockquote" do
|
24
|
+
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return(markdown_file_content)
|
25
|
+
allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
|
21
26
|
expect(wiki_body.to_s).not_to match(/blockquote<br>/)
|
22
27
|
end
|
23
28
|
|
29
|
+
it "must leave normal content alone" do
|
30
|
+
allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
|
31
|
+
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return("hello")
|
32
|
+
expect(wiki_body.to_s).to match(/hello/)
|
33
|
+
end
|
24
34
|
end
|
35
|
+
|
25
36
|
end
|
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.2.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:
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -216,9 +216,11 @@ files:
|
|
216
216
|
- lib/vimwiki_markdown/options.rb
|
217
217
|
- lib/vimwiki_markdown/template.rb
|
218
218
|
- lib/vimwiki_markdown/version.rb
|
219
|
+
- lib/vimwiki_markdown/vimwiki_link.rb
|
219
220
|
- lib/vimwiki_markdown/wiki_body.rb
|
220
221
|
- spec/lib/vimwiki_markdown/options_spec.rb
|
221
222
|
- spec/lib/vimwiki_markdown/template_spec.rb
|
223
|
+
- spec/lib/vimwiki_markdown/vimwiki_link_spec.rb
|
222
224
|
- spec/lib/vimwiki_markdown/wiki_body_spec.rb
|
223
225
|
- spec/spec_helper.rb
|
224
226
|
- vimwiki_markdown.gemspec
|
@@ -242,12 +244,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
244
|
version: '0'
|
243
245
|
requirements: []
|
244
246
|
rubyforge_project:
|
245
|
-
rubygems_version: 2.4.
|
247
|
+
rubygems_version: 2.4.8
|
246
248
|
signing_key:
|
247
249
|
specification_version: 4
|
248
250
|
summary: Converts a github flavoured markdown vimwiki file into html.
|
249
251
|
test_files:
|
250
252
|
- spec/lib/vimwiki_markdown/options_spec.rb
|
251
253
|
- spec/lib/vimwiki_markdown/template_spec.rb
|
254
|
+
- spec/lib/vimwiki_markdown/vimwiki_link_spec.rb
|
252
255
|
- spec/lib/vimwiki_markdown/wiki_body_spec.rb
|
253
256
|
- spec/spec_helper.rb
|