trac-wiki 0.1.3 → 0.1.5
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/Rakefile +6 -0
- data/bin/trac-wiki.rb +8 -0
- data/lib/trac-wiki/parser.rb +48 -41
- data/lib/trac-wiki/version.rb +1 -1
- data/test/parser_test.rb +31 -17
- metadata +5 -4
data/Rakefile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
task :default => :test
|
2
2
|
|
3
|
+
|
3
4
|
desc 'Run tests with bacon'
|
4
5
|
task :test => FileList['test/*_test.rb'] do |t|
|
5
6
|
sh "bacon -q -Ilib:test #{t.prerequisites.join(' ')}"
|
6
7
|
end
|
8
|
+
|
9
|
+
desc $stderr.puts("Goodbye, World!")
|
10
|
+
task :test2 => FileList['test/*_test.rb'] do |t|
|
11
|
+
sh "bacon -q -Ilib:test #{t.prerequisites.join(' ')}"
|
12
|
+
end
|
data/bin/trac-wiki.rb
ADDED
data/lib/trac-wiki/parser.rb
CHANGED
@@ -43,11 +43,6 @@ module TracWiki
|
|
43
43
|
# Examples: http https ftp ftps
|
44
44
|
attr_accessor :allowed_schemes
|
45
45
|
|
46
|
-
# Non-standard wiki text extensions enabled?
|
47
|
-
# E.g. underlined, deleted text etc
|
48
|
-
attr_writer :extensions
|
49
|
-
def extensions?; @extensions; end
|
50
|
-
|
51
46
|
# Disable url escaping for local links
|
52
47
|
# Escaping: [[/Test]] --> %2FTest
|
53
48
|
# No escaping: [[/Test]] --> Test
|
@@ -59,11 +54,14 @@ module TracWiki
|
|
59
54
|
attr_writer :no_link
|
60
55
|
def no_link?; @no_link; end
|
61
56
|
|
57
|
+
attr_writer :math
|
58
|
+
def math?; @math; end
|
59
|
+
|
62
60
|
# Create a new Parser instance.
|
63
61
|
def initialize(text, options = {})
|
64
62
|
@allowed_schemes = %w(http https ftp ftps)
|
65
63
|
@text = text
|
66
|
-
@
|
64
|
+
@no_escape = nil
|
67
65
|
options.each_pair {|k,v| send("#{k}=", v) }
|
68
66
|
end
|
69
67
|
|
@@ -73,7 +71,7 @@ module TracWiki
|
|
73
71
|
#
|
74
72
|
# Example:
|
75
73
|
#
|
76
|
-
# parser =
|
74
|
+
# parser = Parser.new("**Hello //World//**")
|
77
75
|
# parser.to_html
|
78
76
|
# #=> "<p><strong>Hello <em>World</em></strong></p>"
|
79
77
|
def to_html
|
@@ -239,8 +237,12 @@ module TracWiki
|
|
239
237
|
return ' ' + a.map{|k,v| "#{k}=\"#{v}\"" }.sort.join(' ')
|
240
238
|
end
|
241
239
|
|
242
|
-
def make_headline(level, text)
|
243
|
-
"<h#{level}>" << escape_html(text) << "</h#{level}>"
|
240
|
+
def make_headline(level, text, aname)
|
241
|
+
ret = "<h#{level}>" << escape_html(text) << "</h#{level}>"
|
242
|
+
if aname
|
243
|
+
ret = "<a name=\"#{ escape_html(aname) }\"/>" + ret
|
244
|
+
end
|
245
|
+
ret
|
244
246
|
end
|
245
247
|
|
246
248
|
def make_explicit_link(link)
|
@@ -319,11 +321,14 @@ module TracWiki
|
|
319
321
|
end
|
320
322
|
|
321
323
|
def parse_inline_tag(str)
|
322
|
-
case
|
323
|
-
when /\A\{\{\{(.*?\}*)\}\}\}/ # inline pre (tt)
|
324
|
+
case
|
325
|
+
when str =~ /\A\{\{\{(.*?\}*)\}\}\}/ # inline pre (tt)
|
324
326
|
@out << '<tt>' << escape_html($1) << '</tt>'
|
325
|
-
when /\A`(.*?)`/ # inline pre (tt)
|
327
|
+
when str =~ /\A`(.*?)`/ # inline pre (tt)
|
326
328
|
@out << '<tt>' << escape_html($1) << '</tt>'
|
329
|
+
|
330
|
+
when math? && str =~ /\A\$(.+?)\$/ # inline math (tt)
|
331
|
+
@out << '\( ' << escape_html($1) << ' \)'
|
327
332
|
# when /\A\[\[Image\(([^|].*?)(\|(.*?))?\)\]\]/ # image
|
328
333
|
# @out << make_image($1, $3)
|
329
334
|
|
@@ -334,35 +339,31 @@ module TracWiki
|
|
334
339
|
# @out << escape_html($&)
|
335
340
|
# end # link
|
336
341
|
|
337
|
-
when /\A([:alpha:]|[:digit:])+/
|
342
|
+
when str =~ /\A([:alpha:]|[:digit:])+/
|
338
343
|
@out << $& # word
|
339
|
-
when /\A\s+/
|
344
|
+
when str =~ /\A\s+/
|
340
345
|
@out << ' ' if @out[-1] != ?\s # spaces
|
341
|
-
when /\A'''''/
|
346
|
+
when str =~ /\A'''''/
|
342
347
|
toggle_tag 'strongem', $& # bolditallic
|
343
|
-
when /\A
|
348
|
+
when str =~ /\A\*\*/ || str =~ /\A'''/
|
344
349
|
toggle_tag 'strong', $& # bold
|
345
|
-
when /\A''
|
350
|
+
when str =~ /\A''/ || str =~ /\A\/\//
|
346
351
|
toggle_tag 'em', $& # italic
|
347
|
-
when /\A
|
352
|
+
when str =~ /\A\\\\/ || str =~ /\A\[\[br\]\]/i
|
348
353
|
@out << '<br/>' # newline
|
349
|
-
when /\A__/
|
354
|
+
when str =~ /\A__/
|
350
355
|
toggle_tag 'u', $& # underline
|
351
|
-
when /\A~~/
|
356
|
+
when str =~ /\A~~/
|
352
357
|
toggle_tag 'del', $& # delete
|
353
358
|
# when /\A\+\+/
|
354
359
|
# toggle_tag 'ins', $& # insert
|
355
|
-
when /\A\^/
|
360
|
+
when str =~ /\A\^/
|
356
361
|
toggle_tag 'sup', $& # ^{}
|
357
|
-
when /\A,,/
|
362
|
+
when str =~ /\A,,/
|
358
363
|
toggle_tag 'sub', $& # _{}
|
359
|
-
when /\A
|
360
|
-
@out << '®' # (R)
|
361
|
-
when /\A\(C\)/i
|
362
|
-
@out << '©' # (C)
|
363
|
-
when /\A!([^\s])/
|
364
|
+
when str =~ /\A!([^\s])/
|
364
365
|
@out << escape_html($1) # !neco
|
365
|
-
when /./
|
366
|
+
when str =~ /./
|
366
367
|
@out << escape_html($&) # ordinal char
|
367
368
|
end
|
368
369
|
return $'
|
@@ -472,27 +473,33 @@ module TracWiki
|
|
472
473
|
|
473
474
|
def parse_block(str)
|
474
475
|
until str.empty?
|
475
|
-
case
|
476
|
-
|
476
|
+
case
|
477
477
|
# pre {{{ ... }}}
|
478
|
-
when /\A
|
478
|
+
when math? && str =~ /\A\$\$(.*?)\$\$/
|
479
|
+
end_paragraph
|
480
|
+
nowikiblock = make_nowikiblock($1)
|
481
|
+
@out << "$$" << escape_html(nowikiblock) << "$$\n"
|
482
|
+
when str =~ /\A\{\{\{\r?\n(.*?)\r?\n\}\}\}/m
|
479
483
|
end_paragraph
|
480
484
|
nowikiblock = make_nowikiblock($1)
|
481
485
|
@out << '<pre>' << escape_html(nowikiblock) << '</pre>'
|
482
486
|
|
483
487
|
# horizontal rule
|
484
|
-
when /\A\s*-{4,}\s*$/
|
488
|
+
when str =~ /\A\s*-{4,}\s*$/
|
485
489
|
end_paragraph
|
486
490
|
@out << '<hr/>'
|
487
491
|
|
488
492
|
# heading == Wiki Ruless ==
|
489
|
-
|
490
|
-
|
493
|
+
# heading == Wiki Ruless == #tag
|
494
|
+
when str =~ /\A\s*(={1,6})\s*(.*?)\s*=*\s*(#(\S*))?\s*$(\r?\n)?/
|
491
495
|
level = $1.size
|
492
|
-
|
496
|
+
title= $2
|
497
|
+
aname= $4
|
498
|
+
end_paragraph
|
499
|
+
@out << make_headline(level, title, aname)
|
493
500
|
|
494
501
|
# table row
|
495
|
-
when /\A[ \t]*\|\|(.*)$(\r?\n)?/
|
502
|
+
when str =~ /\A[ \t]*\|\|(.*)$(\r?\n)?/
|
496
503
|
if !@stack.include?('table')
|
497
504
|
end_paragraph
|
498
505
|
start_tag('table')
|
@@ -500,9 +507,9 @@ module TracWiki
|
|
500
507
|
parse_table_row($1)
|
501
508
|
|
502
509
|
# empty line
|
503
|
-
when /\A\s*$(\r?\n)?/
|
510
|
+
when str =~ /\A\s*$(\r?\n)?/
|
504
511
|
end_paragraph
|
505
|
-
when /\A([:\w\s]+)::(\s+|\r?\n)/
|
512
|
+
when str =~ /\A([:\w\s]+)::(\s+|\r?\n)/
|
506
513
|
term = $1
|
507
514
|
start_tag('dl')
|
508
515
|
start_tag('dt')
|
@@ -511,10 +518,10 @@ module TracWiki
|
|
511
518
|
start_tag('dd')
|
512
519
|
|
513
520
|
# li
|
514
|
-
when /\A(\s*)([*-]|[aAIi\d]\.)\s+(.*?)$(\r?\n)?/
|
521
|
+
when str =~ /\A(\s*)([*-]|[aAIi\d]\.)\s+(.*?)$(\r?\n)?/
|
515
522
|
parse_li_line($1.size, $2, $3)
|
516
523
|
|
517
|
-
when /\A(>[>\s]*)(.*?)$(\r?\n)?/
|
524
|
+
when str =~ /\A(>[>\s]*)(.*?)$(\r?\n)?/
|
518
525
|
# citation
|
519
526
|
level, quote = $1.count('>'), $2
|
520
527
|
|
@@ -524,7 +531,7 @@ module TracWiki
|
|
524
531
|
|
525
532
|
|
526
533
|
# ordinary line
|
527
|
-
when /\A(\s*)(\S+.*?)$(\r?\n)?/
|
534
|
+
when str =~ /\A(\s*)(\S+.*?)$(\r?\n)?/
|
528
535
|
spc_size, text = $1.size, $2
|
529
536
|
text.rstrip!
|
530
537
|
|
data/lib/trac-wiki/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -4,10 +4,6 @@ class Bacon::Context
|
|
4
4
|
def tc(html, wiki, options = {})
|
5
5
|
TracWiki.render(wiki, options).should.equal html
|
6
6
|
end
|
7
|
-
|
8
|
-
def tce(html, wiki)
|
9
|
-
tc(html, wiki, :extensions => true)
|
10
|
-
end
|
11
7
|
end
|
12
8
|
|
13
9
|
describe TracWiki::Parser do
|
@@ -123,11 +119,27 @@ describe TracWiki::Parser do
|
|
123
119
|
tc "<p><em>This is <strong>also</strong> good.</em></p>\n", "''This is **also** good.''"
|
124
120
|
end
|
125
121
|
|
122
|
+
it 'should parse math' do
|
123
|
+
tc "<p>\\( the \\)</p>\n", '$the$', math: true
|
124
|
+
tc "<p>test \\( the \\) west</p>\n", 'test $the$ west', math: true
|
125
|
+
tc "<p>test \\( e^{i\\pi} \\) test</p>\n", 'test $e^{i\pi}$ test', math: true
|
126
|
+
tc "<p>test $ e<sup>{i\\pi} test</sup></p>\n", 'test $ e^{i\pi} test', math: true
|
127
|
+
tc "<p>$the$</p>\n", '$the$', math: false
|
128
|
+
|
129
|
+
tc "<p>ahoj</p>\n$$e^{i\\pi}$$\n<p>nazdar</p>\n", "ahoj\n$$e^{i\\pi}$$\nnazdar", math: true
|
130
|
+
tc "<p>ahoj $$e<sup>{i\\pi}$$ nazdar</sup></p>\n", "ahoj\n$$e^{i\\pi}$$\nnazdar", math: false
|
131
|
+
end
|
126
132
|
it 'should parse headings' do
|
127
133
|
# Only three differed sized levels of heading are required.
|
128
134
|
tc "<h1>Heading 1</h1>", "= Heading 1 ="
|
129
135
|
tc "<h2>Heading 2</h2>", "== Heading 2 =="
|
130
136
|
tc "<h3>Heading 3</h3>", "=== Heading 3 ==="
|
137
|
+
tc "<a name=\"HE3\"/><h3>Heading 3</h3>", "=== Heading 3 === #HE3"
|
138
|
+
tc "<a name=\"Heading-3\"/><h3>Heading 3</h3>", "=== Heading 3 === #Heading-3"
|
139
|
+
tc "<a name=\"Heading/3\"/><h3>Heading 3</h3>", "=== Heading 3 === #Heading/3"
|
140
|
+
tc "<a name=\"Heading/3\"/><h3>Heading 3</h3>", "=== Heading 3 === #Heading/3 "
|
141
|
+
tc "<a name=\"Heading<3>\"/><h3>Heading 3</h3>", "=== Heading 3 === #Heading<3>"
|
142
|
+
tc "<a name=\"Heading'"3"'\"/><h3>Heading 3</h3>", "=== Heading 3 === #Heading'\"3\"'"
|
131
143
|
# WARNING: Optional feature, not specified in
|
132
144
|
tc "<h4>Heading 4</h4>", "==== Heading 4 ===="
|
133
145
|
tc "<h5>Heading 5</h5>", "===== Heading 5 ====="
|
@@ -748,23 +760,25 @@ describe TracWiki::Parser do
|
|
748
760
|
"**bold and\n||table||\nend**")
|
749
761
|
end
|
750
762
|
|
751
|
-
it 'should support
|
752
|
-
|
753
|
-
|
763
|
+
it 'should support font styles below' do
|
764
|
+
tc("<p>This is <u>underlined</u></p>\n",
|
765
|
+
"This is __underlined__")
|
754
766
|
|
755
|
-
|
756
|
-
|
767
|
+
tc("<p>This is <del>deleted</del></p>\n",
|
768
|
+
"This is ~~deleted~~")
|
757
769
|
|
758
|
-
|
759
|
-
|
770
|
+
tc("<p>This is <sup>super</sup></p>\n",
|
771
|
+
"This is ^super^")
|
760
772
|
|
761
|
-
|
762
|
-
|
773
|
+
tc("<p>This is <sub>sub</sub></p>\n",
|
774
|
+
"This is ,,sub,,")
|
775
|
+
end
|
763
776
|
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
777
|
+
it 'should not support signs' do
|
778
|
+
TracWiki.render("(R)").should.not.equal "<p>®</p>\n"
|
779
|
+
TracWiki.render("(r)").should.not.equal "<p>®</p>\n"
|
780
|
+
TracWiki.render("(C)").should.not.equal "<p>©</p>\n"
|
781
|
+
TracWiki.render("(c)").should.not.equal "<p>©</p>\n"
|
768
782
|
end
|
769
783
|
|
770
784
|
it 'should support no_escape' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trac-wiki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bacon
|
@@ -47,7 +47,8 @@ description: TracWiki markup language render (http://trac.edgewall.org/wiki/Wiki
|
|
47
47
|
).
|
48
48
|
email:
|
49
49
|
- vitas@matfyz.cz
|
50
|
-
executables:
|
50
|
+
executables:
|
51
|
+
- trac-wiki.rb
|
51
52
|
extensions: []
|
52
53
|
extra_rdoc_files:
|
53
54
|
- README
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- Gemfile
|
56
57
|
- README
|
57
58
|
- Rakefile
|
59
|
+
- bin/trac-wiki.rb
|
58
60
|
- lib/trac-wiki.rb
|
59
61
|
- lib/trac-wiki/parser.rb
|
60
62
|
- lib/trac-wiki/version.rb
|
@@ -85,4 +87,3 @@ signing_key:
|
|
85
87
|
specification_version: 3
|
86
88
|
summary: Trac Wiki markup language
|
87
89
|
test_files: []
|
88
|
-
has_rdoc:
|