Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

filter/wiki: add

  • Loading branch information...
commit fbaaff10883c176f010533b2a236ca164800e7f5 1 parent 71f674a
z1y icy authored
2  Rules
@@ -25,6 +25,7 @@ end
25 25 compile '/changes/' do
26 26 filter :erb
27 27 filter :kramdown
  28 + filter :wiki
28 29 layout 'default'
29 30 end
30 31
@@ -33,6 +34,7 @@ compile '*' do
33 34 # don’t filter binary items
34 35 else
35 36 filter :kramdown
  37 + filter :wiki
36 38 layout 'default'
37 39 end
38 40 end
1  content/index.html
@@ -19,7 +19,6 @@
19 19 người Việt Nam khác đang dùng [ArchLinux] [], trang web này cùng với tài liệu
20 20 và các kênh liên lạc của nó sẽ giúp ích cho bạn!
21 21
22   -
23 22 [list]: http://groups.google.com/group/archlinuxvn/
24 23 [irc]: /vn/irc/
25 24 [github]: http://github.com/archlinuxvn/
34 lib/filters/wiki_filter.rb
... ... @@ -0,0 +1,34 @@
  1 +########################################################################
  2 +# WARNING: normal authors are not allowed to change this file. #
  3 +# all changes will be simply ignored by server #
  4 +########################################################################
  5 +
  6 +# @purpose: A post-processed filter to provide wiki-style when writing
  7 +# article. This filter should be executed after any other
  8 +# filter.
  9 +# @author : Anh K. Huynh
  10 +#
  11 +# @desc : Replaces [[id<title>]] by a link. The <title> is optional.
  12 +# The `id` may be absolute or relative to `/doc/`. For example
  13 +# /vn/author-guide/ : absolute
  14 +# git/gitconfig : it's /doc/git/gitconfig/
  15 +# The colon (:) can be used instead of a slash (/)
  16 +#
  17 +# @return : HTML output
  18 +#
  19 +class WikiFilter < Nanoc::Filter
  20 + identifier :wiki
  21 + type :text => :text
  22 +
  23 + def run(content, params={})
  24 + content.gsub(%r{\[\[([^\[\][:space:]]+)( .*)?\]\]}) do |m|
  25 + path, title = $1, $2
  26 + path.gsub!(":", "/")
  27 + path = "#{path.chomp('/')}/"
  28 + path = "/doc/#{path}" unless path[0] == "/"
  29 + title = path.split("/").last if title.nil?
  30 + title.strip!
  31 + "<a href=\"%s\">%s</a>" % [path, title]
  32 + end
  33 + end
  34 +end

0 comments on commit fbaaff1

Please sign in to comment.
Something went wrong with that request. Please try again.