wikiwah 0.0.1 → 0.0.2
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.
- data/lib/wikiwah/converter.rb +71 -0
- data/lib/wikiwah/flow.rb +1 -1
- data/lib/wikiwah/subst.rb +1 -1
- data/lib/wikiwah/tilt_integration.rb +20 -0
- data/lib/wikiwah/version.rb +2 -2
- data/lib/wikiwah.rb +5 -66
- data/test/wikiwah/flow_tests.rb +1 -1
- data/test/wikiwah/subst_tests.rb +1 -1
- data/test/wikiwah_tests.rb +1 -5
- metadata +7 -5
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'wikiwah/flow'
|
2
|
+
require 'wikiwah/subst'
|
3
|
+
|
4
|
+
module WikiWah
|
5
|
+
|
6
|
+
class Converter
|
7
|
+
|
8
|
+
attr_writer :link_translator
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@link_translator = proc do |link| link end
|
12
|
+
init_transformer
|
13
|
+
end
|
14
|
+
|
15
|
+
# Convert WikiWah text to HTML.
|
16
|
+
def convert(text)
|
17
|
+
Flow.convert(text) do |paragraph|
|
18
|
+
@transformer.transform(paragraph)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def translate_link(link)
|
25
|
+
@link_translator.call(link)
|
26
|
+
end
|
27
|
+
|
28
|
+
def init_transformer
|
29
|
+
@transformer = WikiWah::Subst.new
|
30
|
+
@transformer.add_transformation(/""(.+)""/) do |match|
|
31
|
+
# Double-double-quoted
|
32
|
+
CGI.escapeHTML(match[1])
|
33
|
+
end
|
34
|
+
@transformer.add_transformation(/\\(.)/) do |match|
|
35
|
+
# Backslash-quoted
|
36
|
+
match[1]
|
37
|
+
end
|
38
|
+
@transformer.add_transformation(/\<(.+?)\>/m) do |match|
|
39
|
+
# In-line HTML
|
40
|
+
match[0]
|
41
|
+
end
|
42
|
+
@transformer.add_transformation(/\{(.+?)\}(@(\S*[\w\/]))?/m) do |match|
|
43
|
+
# Distinuished link
|
44
|
+
label = @transformer.transform(match[1])
|
45
|
+
location = translate_link(match[3] || match[1])
|
46
|
+
if location
|
47
|
+
"<a href='#{location}'>#{label}</a>"
|
48
|
+
else
|
49
|
+
"{#{label}}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
@transformer.add_transformation(/\b[a-z]+:[\w\/]\S*[\w\/]/) do |match|
|
53
|
+
# URL
|
54
|
+
"<a href='#{match[0]}'>#{match[0]}</a>"
|
55
|
+
end
|
56
|
+
@transformer.add_transformation(%r[(^|\W)([*+_/])([*+_/]*\w.*?\w[*+_/]*)\2(?!\w)]) do |match|
|
57
|
+
# Bold/italic/etc.
|
58
|
+
tag = case match[2]
|
59
|
+
when '*'; 'strong'
|
60
|
+
when '+'; 'tt'
|
61
|
+
when '/'; 'em'
|
62
|
+
when '_'; 'u'
|
63
|
+
end
|
64
|
+
content = @transformer.transform(match[3])
|
65
|
+
(match[1] + '<' + tag + '>' + content + '</' + tag + '>')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/lib/wikiwah/flow.rb
CHANGED
data/lib/wikiwah/subst.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "tilt"
|
2
|
+
require "wikiwah"
|
3
|
+
|
4
|
+
module WikiWah
|
5
|
+
|
6
|
+
class Template < Tilt::Template
|
7
|
+
|
8
|
+
def prepare
|
9
|
+
@output = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def evaluate(scope, locals, &block)
|
13
|
+
@output ||= WikiWah.convert(data)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
Tilt.register 'wah', WikiWah::Template
|
data/lib/wikiwah/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
module WikiWah
|
2
|
+
VERSION = "0.0.2".freeze
|
3
3
|
end
|
data/lib/wikiwah.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require 'wikiwah/
|
2
|
-
require 'wikiwah/subst'
|
1
|
+
require 'wikiwah/converter'
|
3
2
|
require 'wikiwah/version'
|
4
3
|
|
5
4
|
# A formatter for turning Wiki-esque text into HTML.
|
@@ -32,72 +31,12 @@ require 'wikiwah/version'
|
|
32
31
|
# - "{LABEL}@LOCATION" creates a link to LOCATION, with the specified
|
33
32
|
# LABEL.
|
34
33
|
#
|
35
|
-
|
34
|
+
module WikiWah
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
def initialize
|
40
|
-
@link_translator = proc do |link| link end
|
41
|
-
init_transformer
|
42
|
-
end
|
43
|
-
|
44
|
-
# Convert WikiWah text to HTML.
|
45
|
-
def to_html(text)
|
46
|
-
Flow.convert(text) do |paragraph|
|
47
|
-
@transformer.transform(paragraph)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.to_html(text)
|
52
|
-
self.new.to_html(text)
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def translate_link(link)
|
58
|
-
@link_translator.call(link)
|
59
|
-
end
|
60
|
-
|
61
|
-
def init_transformer
|
62
|
-
@transformer = WikiWah::Subst.new
|
63
|
-
@transformer.add_transformation(/""(.+)""/) do |match|
|
64
|
-
# Double-double-quoted
|
65
|
-
CGI.escapeHTML(match[1])
|
66
|
-
end
|
67
|
-
@transformer.add_transformation(/\\(.)/) do |match|
|
68
|
-
# Backslash-quoted
|
69
|
-
match[1]
|
70
|
-
end
|
71
|
-
@transformer.add_transformation(/\<(.+?)\>/m) do |match|
|
72
|
-
# In-line HTML
|
73
|
-
match[0]
|
74
|
-
end
|
75
|
-
@transformer.add_transformation(/\{(.+?)\}(@(\S*[\w\/]))?/m) do |match|
|
76
|
-
# Distinuished link
|
77
|
-
label = @transformer.transform(match[1])
|
78
|
-
location = translate_link(match[3] || match[1])
|
79
|
-
if location
|
80
|
-
"<a href='#{location}'>#{label}</a>"
|
81
|
-
else
|
82
|
-
"{#{label}}"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
@transformer.add_transformation(/\b[a-z]+:[\w\/]\S*[\w\/]/) do |match|
|
86
|
-
# URL
|
87
|
-
"<a href='#{match[0]}'>#{match[0]}</a>"
|
88
|
-
end
|
89
|
-
@transformer.add_transformation(%r[(^|\W)([*+_/])([*+_/]*\w.*?\w[*+_/]*)\2(?!\w)]) do |match|
|
90
|
-
# Bold/italic/etc.
|
91
|
-
tag = case match[2]
|
92
|
-
when '*'; 'strong'
|
93
|
-
when '+'; 'tt'
|
94
|
-
when '/'; 'em'
|
95
|
-
when '_'; 'u'
|
96
|
-
end
|
97
|
-
content = @transformer.transform(match[3])
|
98
|
-
(match[1] + '<' + tag + '>' + content + '</' + tag + '>')
|
99
|
-
end
|
36
|
+
def self.convert(text)
|
37
|
+
Converter.new.convert(text)
|
100
38
|
end
|
101
39
|
|
102
40
|
end
|
103
41
|
|
42
|
+
Wikiwah = WikiWah
|
data/test/wikiwah/flow_tests.rb
CHANGED
data/test/wikiwah/subst_tests.rb
CHANGED
data/test/wikiwah_tests.rb
CHANGED
@@ -5,12 +5,8 @@ require 'test/unit'
|
|
5
5
|
|
6
6
|
class WikiWahTests < Test::Unit::TestCase
|
7
7
|
|
8
|
-
def setup
|
9
|
-
@wikiwah = WikiWah.new
|
10
|
-
end
|
11
|
-
|
12
8
|
def assert_wikiwah(expected, input)
|
13
|
-
assert_equal(expected,
|
9
|
+
assert_equal(expected, Wikiwah.convert(input))
|
14
10
|
end
|
15
11
|
|
16
12
|
def test_empty
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikiwah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mike Williams
|
@@ -15,12 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-28 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
22
22
|
description: |
|
23
|
-
|
23
|
+
WikiWah is a text-to-HTML converter, along the lines of Markdown.
|
24
24
|
|
25
25
|
This isn't the markup language you're looking for.
|
26
26
|
It offers no improvements on Markdown, Textile, etc.
|
@@ -34,10 +34,12 @@ extensions: []
|
|
34
34
|
extra_rdoc_files: []
|
35
35
|
|
36
36
|
files:
|
37
|
+
- lib/wikiwah/converter.rb
|
37
38
|
- lib/wikiwah/flow.rb
|
38
39
|
- lib/wikiwah/flow.rb~
|
39
40
|
- lib/wikiwah/subst.rb
|
40
41
|
- lib/wikiwah/subst.rb~
|
42
|
+
- lib/wikiwah/tilt_integration.rb
|
41
43
|
- lib/wikiwah/version.rb
|
42
44
|
- lib/wikiwah/version.rb~
|
43
45
|
- lib/wikiwah.rb
|