aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2013-04-05 15:02:20 +0300
committerMarin Ivanov <[email protected]>2013-04-05 15:02:20 +0300
commitb1561cfc87fd3c7c8db5208501aaec28f90243d4 (patch)
tree8b1e97c5295caefc88e26c10c42696dcdadac92b
parentd96bbb2f64217db0cae1a815da028890c14dad15 (diff)
Hello world.
-rw-r--r--LICENSE22
-rw-r--r--README.md8
-rw-r--r--wikilinks.rb68
3 files changed, 97 insertions, 1 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..5ca7e5b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Marin Ivanov (http://metala.org/)
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
index 2195942..a7dbc20 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,10 @@
jekyll-wikilinks-plugin
=======================
-A plugin for Jekyll to process Wikipedia-like links in Maruku markdown \ No newline at end of file
+A plugin for Jekyll to process Wikipedia style links in Maruku markdown. It supports the short `[[name]]` link syntax and also `[[name|Title]]`, where `name` is eiter a name of a page or of a post and `Title` is optional text that the link will show. If short syntax is used, the text for the link will be either the title of the page/post or the name of the page/post.
+
+Install
+-------
+
+Plugin should be placed in `_plugins` directory of the jekyll site root.
+
diff --git a/wikilinks.rb b/wikilinks.rb
new file mode 100644
index 0000000..eb95730
--- /dev/null
+++ b/wikilinks.rb
@@ -0,0 +1,68 @@
+module Jekyll
+ module Wikilinks
+ class Wikilink
+ def self.parse(text)
+ inner = text[2..-3]
+ name, title = inner.split('|', 2)
+ self.new(name, title)
+ end
+
+ attr_accessor :name, :title
+ attr_reader :match
+
+ def initialize(name, title)
+ @name = name.strip
+ @title = title
+ end
+
+ def title
+ if @title.nil?
+ if not @match.nil? && @match.data.has?('title')
+ @match.data['title']
+ else
+ @name
+ end
+ else
+ @title
+ end
+ end
+
+ def url
+ @match.url
+ end
+
+ def has_match?
+ not @match.nil?
+ end
+
+ def match_post(posts)
+ @match = posts.find { |p| p.slug.downcase == @name.downcase }
+ end
+
+ def match_page(pages)
+ @match = pages.find { |p| p.basename.downcase == @name.downcase }
+ end
+
+ def markdown
+ @match.nil? ? "\\[\\[#{title}\\]\\]" : "[#{title}](#{url})"
+ end
+ end
+ end
+
+ module Convertible
+ alias old_transform transform
+
+ def transform
+ if converter.instance_of? MarkdownConverter
+ pat = /\[\[(.+?)\]\]/
+ @content = @content.gsub(pat) do |m|
+ wl = Wikilinks::Wikilink.parse(m)
+ wl.match_page(site.pages)
+ wl.match_post(site.posts) unless wl.has_match?
+ wl.markdown
+ end
+ end
+ old_transform
+ end
+ end
+end