amp 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.hgignore +3 -0
- data/AUTHORS +1 -1
- data/Manifest.txt +99 -38
- data/README.md +3 -3
- data/Rakefile +53 -18
- data/SCHEDULE.markdown +5 -1
- data/TODO.markdown +120 -149
- data/ampfile.rb +3 -1
- data/bin/amp +4 -1
- data/ext/amp/bz2/extconf.rb +1 -1
- data/ext/amp/mercurial_patch/extconf.rb +1 -1
- data/ext/amp/mercurial_patch/mpatch.c +4 -3
- data/ext/amp/priority_queue/extconf.rb +1 -1
- data/ext/amp/support/extconf.rb +1 -1
- data/ext/amp/support/support.c +1 -1
- data/lib/amp.rb +125 -67
- data/lib/amp/commands/command.rb +12 -10
- data/lib/amp/commands/command_support.rb +8 -1
- data/lib/amp/commands/commands/help.rb +2 -20
- data/lib/amp/commands/commands/init.rb +14 -2
- data/lib/amp/commands/commands/templates.rb +6 -4
- data/lib/amp/commands/commands/version.rb +15 -1
- data/lib/amp/commands/commands/workflow.rb +3 -3
- data/lib/amp/commands/commands/workflows/git/add.rb +3 -3
- data/lib/amp/commands/commands/workflows/git/copy.rb +1 -1
- data/lib/amp/commands/commands/workflows/git/rm.rb +4 -2
- data/lib/amp/commands/commands/workflows/hg/add.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/addremove.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/annotate.rb +8 -2
- data/lib/amp/commands/commands/workflows/hg/bisect.rb +253 -0
- data/lib/amp/commands/commands/workflows/hg/branch.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/branches.rb +3 -3
- data/lib/amp/commands/commands/workflows/hg/bundle.rb +3 -3
- data/lib/amp/commands/commands/workflows/hg/clone.rb +4 -5
- data/lib/amp/commands/commands/workflows/hg/commit.rb +37 -1
- data/lib/amp/commands/commands/workflows/hg/copy.rb +2 -1
- data/lib/amp/commands/commands/workflows/hg/debug/index.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/diff.rb +3 -8
- data/lib/amp/commands/commands/workflows/hg/forget.rb +5 -4
- data/lib/amp/commands/commands/workflows/hg/identify.rb +6 -6
- data/lib/amp/commands/commands/workflows/hg/import.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/incoming.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/log.rb +5 -4
- data/lib/amp/commands/commands/workflows/hg/merge.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/move.rb +5 -3
- data/lib/amp/commands/commands/workflows/hg/outgoing.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/push.rb +6 -7
- data/lib/amp/commands/commands/workflows/hg/remove.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/resolve.rb +6 -23
- data/lib/amp/commands/commands/workflows/hg/root.rb +1 -2
- data/lib/amp/commands/commands/workflows/hg/status.rb +21 -12
- data/lib/amp/commands/commands/workflows/hg/tag.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/untrack.rb +12 -0
- data/lib/amp/commands/commands/workflows/hg/verify.rb +13 -3
- data/lib/amp/commands/commands/workflows/hg/what_changed.rb +18 -0
- data/lib/amp/commands/dispatch.rb +12 -13
- data/lib/amp/dependencies/amp_support.rb +1 -1
- data/lib/amp/dependencies/amp_support/ruby_amp_support.rb +1 -0
- data/lib/amp/dependencies/maruku.rb +136 -0
- data/lib/amp/dependencies/maruku/attributes.rb +227 -0
- data/lib/amp/dependencies/maruku/defaults.rb +71 -0
- data/lib/amp/dependencies/maruku/errors_management.rb +92 -0
- data/lib/amp/dependencies/maruku/helpers.rb +260 -0
- data/lib/amp/dependencies/maruku/input/charsource.rb +326 -0
- data/lib/amp/dependencies/maruku/input/extensions.rb +69 -0
- data/lib/amp/dependencies/maruku/input/html_helper.rb +189 -0
- data/lib/amp/dependencies/maruku/input/linesource.rb +111 -0
- data/lib/amp/dependencies/maruku/input/parse_block.rb +615 -0
- data/lib/amp/dependencies/maruku/input/parse_doc.rb +234 -0
- data/lib/amp/dependencies/maruku/input/parse_span_better.rb +746 -0
- data/lib/amp/dependencies/maruku/input/rubypants.rb +225 -0
- data/lib/amp/dependencies/maruku/input/type_detection.rb +147 -0
- data/lib/amp/dependencies/maruku/input_textile2/t2_parser.rb +163 -0
- data/lib/amp/dependencies/maruku/maruku.rb +33 -0
- data/lib/amp/dependencies/maruku/output/to_ansi.rb +223 -0
- data/lib/amp/dependencies/maruku/output/to_html.rb +991 -0
- data/lib/amp/dependencies/maruku/output/to_markdown.rb +164 -0
- data/lib/amp/dependencies/maruku/output/to_s.rb +56 -0
- data/lib/amp/dependencies/maruku/string_utils.rb +191 -0
- data/lib/amp/dependencies/maruku/structures.rb +167 -0
- data/lib/amp/dependencies/maruku/structures_inspect.rb +87 -0
- data/lib/amp/dependencies/maruku/structures_iterators.rb +61 -0
- data/lib/amp/dependencies/maruku/textile2.rb +1 -0
- data/lib/amp/dependencies/maruku/toc.rb +199 -0
- data/lib/amp/dependencies/maruku/usage/example1.rb +33 -0
- data/lib/amp/dependencies/maruku/version.rb +40 -0
- data/lib/amp/dependencies/priority_queue.rb +2 -1
- data/lib/amp/dependencies/python_config.rb +2 -1
- data/lib/amp/graphs/ancestor.rb +2 -1
- data/lib/amp/graphs/copies.rb +236 -233
- data/lib/amp/help/entries/__default__.erb +31 -0
- data/lib/amp/help/entries/commands.erb +6 -0
- data/lib/amp/help/entries/mdtest.md +35 -0
- data/lib/amp/help/entries/silly +3 -0
- data/lib/amp/help/help.rb +288 -0
- data/lib/amp/profiling_hacks.rb +5 -3
- data/lib/amp/repository/abstract/abstract_changeset.rb +97 -0
- data/lib/amp/repository/abstract/abstract_local_repo.rb +181 -0
- data/lib/amp/repository/abstract/abstract_staging_area.rb +180 -0
- data/lib/amp/repository/abstract/abstract_versioned_file.rb +100 -0
- data/lib/amp/repository/abstract/common_methods/changeset.rb +75 -0
- data/lib/amp/repository/abstract/common_methods/local_repo.rb +277 -0
- data/lib/amp/repository/abstract/common_methods/staging_area.rb +233 -0
- data/lib/amp/repository/abstract/common_methods/versioned_file.rb +71 -0
- data/lib/amp/repository/generic_repo_picker.rb +78 -0
- data/lib/amp/repository/git/repo_format/changeset.rb +336 -0
- data/lib/amp/repository/git/repo_format/staging_area.rb +192 -0
- data/lib/amp/repository/git/repo_format/versioned_file.rb +119 -0
- data/lib/amp/repository/git/repositories/local_repository.rb +164 -0
- data/lib/amp/repository/git/repository.rb +41 -0
- data/lib/amp/repository/mercurial/encoding/mercurial_diff.rb +382 -0
- data/lib/amp/repository/mercurial/encoding/mercurial_patch.rb +1 -0
- data/lib/amp/repository/mercurial/encoding/patch.rb +294 -0
- data/lib/amp/repository/mercurial/encoding/pure_ruby/ruby_mercurial_patch.rb +124 -0
- data/lib/amp/repository/mercurial/merging/merge_ui.rb +327 -0
- data/lib/amp/repository/mercurial/merging/simple_merge.rb +452 -0
- data/lib/amp/repository/mercurial/repo_format/branch_manager.rb +266 -0
- data/lib/amp/repository/mercurial/repo_format/changeset.rb +768 -0
- data/lib/amp/repository/mercurial/repo_format/dir_state.rb +716 -0
- data/lib/amp/repository/mercurial/repo_format/journal.rb +218 -0
- data/lib/amp/repository/mercurial/repo_format/lock.rb +210 -0
- data/lib/amp/repository/mercurial/repo_format/merge_state.rb +228 -0
- data/lib/amp/repository/mercurial/repo_format/staging_area.rb +367 -0
- data/lib/amp/repository/mercurial/repo_format/store.rb +487 -0
- data/lib/amp/repository/mercurial/repo_format/tag_manager.rb +322 -0
- data/lib/amp/repository/mercurial/repo_format/updatable.rb +543 -0
- data/lib/amp/repository/mercurial/repo_format/updater.rb +848 -0
- data/lib/amp/repository/mercurial/repo_format/verification.rb +433 -0
- data/lib/amp/repository/mercurial/repositories/bundle_repository.rb +216 -0
- data/lib/amp/repository/mercurial/repositories/http_repository.rb +386 -0
- data/lib/amp/repository/mercurial/repositories/local_repository.rb +2034 -0
- data/lib/amp/repository/mercurial/repository.rb +119 -0
- data/lib/amp/repository/mercurial/revlogs/bundle_revlogs.rb +249 -0
- data/lib/amp/repository/mercurial/revlogs/changegroup.rb +217 -0
- data/lib/amp/repository/mercurial/revlogs/changelog.rb +339 -0
- data/lib/amp/repository/mercurial/revlogs/file_log.rb +152 -0
- data/lib/amp/repository/mercurial/revlogs/index.rb +500 -0
- data/lib/amp/repository/mercurial/revlogs/manifest.rb +201 -0
- data/lib/amp/repository/mercurial/revlogs/node.rb +20 -0
- data/lib/amp/repository/mercurial/revlogs/revlog.rb +1026 -0
- data/lib/amp/repository/mercurial/revlogs/revlog_support.rb +129 -0
- data/lib/amp/repository/mercurial/revlogs/versioned_file.rb +597 -0
- data/lib/amp/repository/repository.rb +11 -88
- data/lib/amp/server/extension/amp_extension.rb +3 -3
- data/lib/amp/server/fancy_http_server.rb +1 -1
- data/lib/amp/server/fancy_views/_browser.haml +1 -1
- data/lib/amp/server/fancy_views/_diff_file.haml +1 -8
- data/lib/amp/server/fancy_views/changeset.haml +2 -2
- data/lib/amp/server/fancy_views/file.haml +1 -1
- data/lib/amp/server/fancy_views/file_diff.haml +1 -1
- data/lib/amp/support/amp_ui.rb +13 -29
- data/lib/amp/support/generator.rb +1 -1
- data/lib/amp/support/loaders.rb +1 -2
- data/lib/amp/support/logger.rb +10 -16
- data/lib/amp/support/match.rb +18 -4
- data/lib/amp/support/mercurial/ignore.rb +151 -0
- data/lib/amp/support/openers.rb +8 -3
- data/lib/amp/support/support.rb +91 -46
- data/lib/amp/templates/{blank.commit.erb → mercurial/blank.commit.erb} +0 -0
- data/lib/amp/templates/{blank.log.erb → mercurial/blank.log.erb} +0 -0
- data/lib/amp/templates/{default.commit.erb → mercurial/default.commit.erb} +0 -0
- data/lib/amp/templates/{default.log.erb → mercurial/default.log.erb} +0 -0
- data/lib/amp/templates/template.rb +18 -18
- data/man/amp.1 +51 -0
- data/site/src/about/commands.haml +1 -1
- data/site/src/css/amp.css +1 -1
- data/site/src/index.haml +3 -3
- data/tasks/man.rake +39 -0
- data/tasks/stats.rake +1 -10
- data/tasks/yard.rake +1 -50
- data/test/dirstate_tests/test_dir_state.rb +10 -8
- data/test/functional_tests/annotate.out +31 -0
- data/test/functional_tests/test_functional.rb +155 -63
- data/test/localrepo_tests/ampfile.rb +12 -0
- data/test/localrepo_tests/test_local_repo.rb +56 -57
- data/test/manifest_tests/test_manifest.rb +3 -5
- data/test/merge_tests/test_merge.rb +3 -3
- data/test/revlog_tests/test_revlog.rb +14 -6
- data/test/store_tests/test_fncache_store.rb +19 -19
- data/test/test_19_compatibility.rb +46 -0
- data/test/test_base85.rb +2 -2
- data/test/test_bdiff.rb +2 -2
- data/test/test_changegroup.rb +59 -0
- data/test/test_commands.rb +2 -2
- data/test/test_difflib.rb +2 -2
- data/test/test_generator.rb +34 -0
- data/test/test_ignore.rb +203 -0
- data/test/test_journal.rb +18 -13
- data/test/test_match.rb +2 -2
- data/test/test_mdiff.rb +3 -3
- data/test/test_mpatch.rb +3 -3
- data/test/test_multi_io.rb +40 -0
- data/test/test_support.rb +18 -2
- data/test/test_templates.rb +38 -0
- data/test/test_ui.rb +79 -0
- data/test/testutilities.rb +56 -0
- metadata +168 -49
- data/ext/amp/bz2/mkmf.log +0 -38
- data/lib/amp/encoding/mercurial_diff.rb +0 -378
- data/lib/amp/encoding/mercurial_patch.rb +0 -1
- data/lib/amp/encoding/patch.rb +0 -292
- data/lib/amp/encoding/pure_ruby/ruby_mercurial_patch.rb +0 -123
- data/lib/amp/merges/merge_state.rb +0 -164
- data/lib/amp/merges/merge_ui.rb +0 -322
- data/lib/amp/merges/simple_merge.rb +0 -450
- data/lib/amp/repository/branch_manager.rb +0 -234
- data/lib/amp/repository/dir_state.rb +0 -950
- data/lib/amp/repository/journal.rb +0 -203
- data/lib/amp/repository/lock.rb +0 -207
- data/lib/amp/repository/repositories/bundle_repository.rb +0 -214
- data/lib/amp/repository/repositories/http_repository.rb +0 -377
- data/lib/amp/repository/repositories/local_repository.rb +0 -2661
- data/lib/amp/repository/store.rb +0 -485
- data/lib/amp/repository/tag_manager.rb +0 -319
- data/lib/amp/repository/updatable.rb +0 -532
- data/lib/amp/repository/verification.rb +0 -431
- data/lib/amp/repository/versioned_file.rb +0 -475
- data/lib/amp/revlogs/bundle_revlogs.rb +0 -246
- data/lib/amp/revlogs/changegroup.rb +0 -217
- data/lib/amp/revlogs/changelog.rb +0 -338
- data/lib/amp/revlogs/changeset.rb +0 -521
- data/lib/amp/revlogs/file_log.rb +0 -165
- data/lib/amp/revlogs/index.rb +0 -493
- data/lib/amp/revlogs/manifest.rb +0 -195
- data/lib/amp/revlogs/node.rb +0 -18
- data/lib/amp/revlogs/revlog.rb +0 -1045
- data/lib/amp/revlogs/revlog_support.rb +0 -126
- data/lib/amp/support/ignore.rb +0 -144
- data/site/Rakefile +0 -38
- data/test/test_amp.rb +0 -9
- data/test/test_helper.rb +0 -15
@@ -0,0 +1,71 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
module MaRuKu
|
23
|
+
|
24
|
+
Globals = {
|
25
|
+
:unsafe_features => false,
|
26
|
+
:on_error => :warning,
|
27
|
+
|
28
|
+
|
29
|
+
:use_numbered_headers => false,
|
30
|
+
|
31
|
+
:maruku_signature => false,
|
32
|
+
:code_background_color => '#fef',
|
33
|
+
:code_show_spaces => false,
|
34
|
+
|
35
|
+
:filter_html => false,
|
36
|
+
|
37
|
+
:html_math_output_mathml => true, # also set :html_math_engine
|
38
|
+
:html_math_engine => 'none', #ritex, itex2mml
|
39
|
+
|
40
|
+
:html_math_output_png => false,
|
41
|
+
:html_png_engine => 'none',
|
42
|
+
:html_png_dir => 'pngs',
|
43
|
+
:html_png_url => 'pngs/',
|
44
|
+
:html_png_resolution => 200,
|
45
|
+
|
46
|
+
:html_use_syntax => false,
|
47
|
+
|
48
|
+
:latex_use_listings => false,
|
49
|
+
:latex_cjk => false,
|
50
|
+
:latex_cache_file => "blahtex_cache.pstore", # cache file for blahtex filter
|
51
|
+
|
52
|
+
:debug_keep_ials => false,
|
53
|
+
:doc_prefix => ''
|
54
|
+
}
|
55
|
+
|
56
|
+
class MDElement
|
57
|
+
def get_setting(sym)
|
58
|
+
if self.attributes.has_key?(sym) then
|
59
|
+
return self.attributes[sym]
|
60
|
+
elsif self.doc && self.doc.attributes.has_key?(sym) then
|
61
|
+
return self.doc.attributes[sym]
|
62
|
+
elsif MaRuKu::Globals.has_key?(sym)
|
63
|
+
return MaRuKu::Globals[sym]
|
64
|
+
else
|
65
|
+
$stderr.puts "Bug: no default for #{sym.inspect}"
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
#m Any method that detects formatting error calls the
|
24
|
+
#m maruku_error() method.
|
25
|
+
#m if @meta[:on_error] ==
|
26
|
+
#m
|
27
|
+
#m - :warning write on the standard err (or @error_stream if defined),
|
28
|
+
#m then do your best.
|
29
|
+
#m - :ignore be shy and try to continue
|
30
|
+
#m - :raise raises a MarukuException
|
31
|
+
#m
|
32
|
+
#m default is :raise
|
33
|
+
|
34
|
+
module MaRuKu
|
35
|
+
|
36
|
+
class Exception < RuntimeError
|
37
|
+
end
|
38
|
+
|
39
|
+
module Errors
|
40
|
+
|
41
|
+
def maruku_error(s,src=nil,con=nil)
|
42
|
+
policy = get_setting(:on_error)
|
43
|
+
|
44
|
+
case policy
|
45
|
+
when :ignore
|
46
|
+
when :raise
|
47
|
+
raise_error create_frame(describe_error(s,src,con))
|
48
|
+
when :warning
|
49
|
+
tell_user create_frame(describe_error(s,src,con))
|
50
|
+
else
|
51
|
+
raise "BugBug: policy = #{policy.inspect}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def maruku_recover(s,src=nil,con=nil)
|
56
|
+
tell_user create_frame(describe_error(s,src,con))
|
57
|
+
end
|
58
|
+
|
59
|
+
alias error maruku_error
|
60
|
+
|
61
|
+
def raise_error(s)
|
62
|
+
raise MaRuKu::Exception, s, caller
|
63
|
+
end
|
64
|
+
|
65
|
+
def tell_user(s)
|
66
|
+
error_stream = self.attributes[:error_stream] || $stderr
|
67
|
+
error_stream << s
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_frame(s)
|
71
|
+
n = 75
|
72
|
+
"\n" +
|
73
|
+
" "+"_"*n + "\n"+
|
74
|
+
"| Maruku tells you:\n" +
|
75
|
+
"+" + ("-"*n) +"\n"+
|
76
|
+
add_tabs(s,1,'| ') + "\n" +
|
77
|
+
"+" + ("-"*n) + "\n" +
|
78
|
+
add_tabs(caller[0, 5].join("\n"),1,'!') + "\n" +
|
79
|
+
"\\" + ("_"*n) + "\n"
|
80
|
+
end
|
81
|
+
|
82
|
+
def describe_error(s,src,con)
|
83
|
+
t = s
|
84
|
+
src && (t += "\n#{src.describe}\n")
|
85
|
+
con && (t += "\n#{con.describe}\n")
|
86
|
+
t
|
87
|
+
end
|
88
|
+
|
89
|
+
end # Errors
|
90
|
+
end # MaRuKu
|
91
|
+
|
92
|
+
|
@@ -0,0 +1,260 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
# A series of helper functions for creating elements: they hide the
|
25
|
+
# particular internal representation.
|
26
|
+
#
|
27
|
+
# Please, always use these instead of creating MDElement.
|
28
|
+
#
|
29
|
+
|
30
|
+
module MaRuKu
|
31
|
+
module Helpers
|
32
|
+
|
33
|
+
# if the first is a md_ial, it is used as such
|
34
|
+
def md_el(node_type, children=[], meta={}, al=nil)
|
35
|
+
if (e=children.first).kind_of?(MDElement) and
|
36
|
+
e.node_type == :ial then
|
37
|
+
if al
|
38
|
+
al += e.ial
|
39
|
+
else
|
40
|
+
al = e.ial
|
41
|
+
end
|
42
|
+
children.shift
|
43
|
+
end
|
44
|
+
e = MDElement.new(node_type, children, meta, al)
|
45
|
+
e.doc = @doc
|
46
|
+
return e
|
47
|
+
end
|
48
|
+
|
49
|
+
def md_header(level, children, al=nil)
|
50
|
+
md_el(:header, children, {:level => level}, al)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Inline code
|
54
|
+
def md_code(code, al=nil)
|
55
|
+
md_el(:inline_code, [], {:raw_code => code}, al)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Code block
|
59
|
+
def md_codeblock(source, al=nil)
|
60
|
+
md_el(:code, [], {:raw_code => source}, al)
|
61
|
+
end
|
62
|
+
|
63
|
+
def md_quote(children, al=nil)
|
64
|
+
md_el(:quote, children, {}, al)
|
65
|
+
end
|
66
|
+
|
67
|
+
def md_li(children, want_my_par, al=nil)
|
68
|
+
md_el(:li, children, {:want_my_paragraph=>want_my_par}, al)
|
69
|
+
end
|
70
|
+
|
71
|
+
def md_footnote(footnote_id, children, al=nil)
|
72
|
+
md_el(:footnote, children, {:footnote_id=>footnote_id}, al)
|
73
|
+
end
|
74
|
+
|
75
|
+
def md_abbr_def(abbr, text, al=nil)
|
76
|
+
md_el(:abbr_def, [], {:abbr=>abbr, :text=>text}, al)
|
77
|
+
end
|
78
|
+
|
79
|
+
def md_abbr(abbr, title)
|
80
|
+
md_el(:abbr, [abbr], {:title=>title})
|
81
|
+
end
|
82
|
+
|
83
|
+
def md_html(raw_html, al=nil)
|
84
|
+
e = md_el(:raw_html, [], {:raw_html=>raw_html})
|
85
|
+
begin
|
86
|
+
# remove newlines and whitespace at begin
|
87
|
+
# end end of string, or else REXML gets confused
|
88
|
+
raw_html = raw_html.gsub(/\A\s*</,'<').
|
89
|
+
gsub(/>[\s\n]*\Z/,'>')
|
90
|
+
|
91
|
+
raw_html = "<marukuwrap>#{raw_html}</marukuwrap>"
|
92
|
+
e.instance_variable_set :@parsed_html,
|
93
|
+
REXML::Document.new(raw_html)
|
94
|
+
rescue REXML::ParseException => ex
|
95
|
+
e.instance_variable_set :@parsed_html, nil
|
96
|
+
maruku_recover "REXML cannot parse this block of HTML/XML:\n"+
|
97
|
+
add_tabs(raw_html,1,'|') + "\n"+ex.inspect
|
98
|
+
# " #{raw_html.inspect}\n\n"+ex.inspect
|
99
|
+
end
|
100
|
+
e
|
101
|
+
end
|
102
|
+
|
103
|
+
def md_link(children, ref_id, al=nil)
|
104
|
+
md_el(:link, children, {:ref_id=>ref_id.downcase}, al)
|
105
|
+
end
|
106
|
+
|
107
|
+
def md_im_link(children, url, title=nil, al=nil)
|
108
|
+
md_el(:im_link, children, {:url=>url,:title=>title}, al)
|
109
|
+
end
|
110
|
+
|
111
|
+
def md_image(children, ref_id, al=nil)
|
112
|
+
md_el(:image, children, {:ref_id=>ref_id}, al)
|
113
|
+
end
|
114
|
+
|
115
|
+
def md_im_image(children, url, title=nil, al=nil)
|
116
|
+
md_el(:im_image, children, {:url=>url,:title=>title},al)
|
117
|
+
end
|
118
|
+
|
119
|
+
def md_em(children, al=nil)
|
120
|
+
md_el(:emphasis, [children].flatten, {}, al)
|
121
|
+
end
|
122
|
+
|
123
|
+
def md_br()
|
124
|
+
md_el(:linebreak, [], {}, nil)
|
125
|
+
end
|
126
|
+
|
127
|
+
def md_hrule()
|
128
|
+
md_el(:hrule, [], {}, nil)
|
129
|
+
end
|
130
|
+
|
131
|
+
def md_strong(children, al=nil)
|
132
|
+
md_el(:strong, [children].flatten, {}, al)
|
133
|
+
end
|
134
|
+
|
135
|
+
def md_emstrong(children, al=nil)
|
136
|
+
md_strong(md_em(children), al)
|
137
|
+
end
|
138
|
+
|
139
|
+
# <http://www.example.com/>
|
140
|
+
def md_url(url, al=nil)
|
141
|
+
md_el(:immediate_link, [], {:url=>url}, al)
|
142
|
+
end
|
143
|
+
|
144
|
+
# <andrea@rubyforge.org>
|
145
|
+
# <mailto:andrea@rubyforge.org>
|
146
|
+
def md_email(email, al=nil)
|
147
|
+
md_el(:email_address, [], {:email=>email}, al)
|
148
|
+
end
|
149
|
+
|
150
|
+
def md_entity(entity_name, al=nil)
|
151
|
+
md_el(:entity, [], {:entity_name=>entity_name}, al)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Markdown extra
|
155
|
+
def md_foot_ref(ref_id, al=nil)
|
156
|
+
md_el(:footnote_reference, [], {:footnote_id=>ref_id}, al)
|
157
|
+
end
|
158
|
+
|
159
|
+
def md_par(children, al=nil)
|
160
|
+
md_el(:paragraph, children, meta={}, al)
|
161
|
+
end
|
162
|
+
|
163
|
+
# [1]: http://url [properties]
|
164
|
+
def md_ref_def(ref_id, url, title=nil, meta={}, al=nil)
|
165
|
+
meta[:url] = url
|
166
|
+
meta[:ref_id] = ref_id
|
167
|
+
meta[:title] = title if title
|
168
|
+
md_el(:ref_definition, [], meta, al)
|
169
|
+
end
|
170
|
+
|
171
|
+
# inline attribute list
|
172
|
+
def md_ial(al)
|
173
|
+
al = Maruku::AttributeList.new(al) if
|
174
|
+
not al.kind_of?Maruku::AttributeList
|
175
|
+
md_el(:ial, [], {:ial=>al})
|
176
|
+
end
|
177
|
+
|
178
|
+
# Attribute list definition
|
179
|
+
def md_ald(id, al)
|
180
|
+
md_el(:ald, [], {:ald_id=>id,:ald=>al})
|
181
|
+
end
|
182
|
+
|
183
|
+
# Server directive <?target code... ?>
|
184
|
+
def md_xml_instr(target, code)
|
185
|
+
md_el(:xml_instr, [], {:target=>target, :code=>code})
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
module MaRuKu
|
192
|
+
|
193
|
+
class MDElement
|
194
|
+
# outputs abbreviated form (this should be eval()uable to get the document)
|
195
|
+
def inspect2
|
196
|
+
s =
|
197
|
+
case @node_type
|
198
|
+
when :paragraph
|
199
|
+
"md_par(%s)" % children_inspect
|
200
|
+
when :footnote_reference
|
201
|
+
"md_foot_ref(%s)" % self.footnote_id.inspect
|
202
|
+
when :entity
|
203
|
+
"md_entity(%s)" % self.entity_name.inspect
|
204
|
+
when :email_address
|
205
|
+
"md_email(%s)" % self.email.inspect
|
206
|
+
when :inline_code
|
207
|
+
"md_code(%s)" % self.raw_code.inspect
|
208
|
+
when :raw_html
|
209
|
+
"md_html(%s)" % self.raw_html.inspect
|
210
|
+
when :emphasis
|
211
|
+
"md_em(%s)" % children_inspect
|
212
|
+
when :strong
|
213
|
+
"md_strong(%s)" % children_inspect
|
214
|
+
when :immediate_link
|
215
|
+
"md_url(%s)" % self.url.inspect
|
216
|
+
when :image
|
217
|
+
"md_image(%s, %s)" % [
|
218
|
+
children_inspect,
|
219
|
+
self.ref_id.inspect]
|
220
|
+
when :im_image
|
221
|
+
"md_im_image(%s, %s, %s)" % [
|
222
|
+
children_inspect,
|
223
|
+
self.url.inspect,
|
224
|
+
self.title.inspect]
|
225
|
+
when :link
|
226
|
+
"md_link(%s,%s)" % [
|
227
|
+
children_inspect, self.ref_id.inspect]
|
228
|
+
when :im_link
|
229
|
+
"md_im_link(%s, %s, %s)" % [
|
230
|
+
children_inspect,
|
231
|
+
self.url.inspect,
|
232
|
+
self.title.inspect,
|
233
|
+
]
|
234
|
+
when :ref_definition
|
235
|
+
"md_ref_def(%s, %s, %s)" % [
|
236
|
+
self.ref_id.inspect,
|
237
|
+
self.url.inspect,
|
238
|
+
self.title.inspect
|
239
|
+
]
|
240
|
+
when :ial
|
241
|
+
"md_ial(%s)" % self.ial.inspect
|
242
|
+
else
|
243
|
+
return nil
|
244
|
+
end
|
245
|
+
if @al and not @al.empty? then
|
246
|
+
s = s.chop + ", #{@al.inspect})"
|
247
|
+
end
|
248
|
+
s
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
@@ -0,0 +1,326 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
module MaRuKu; module In; module Markdown; module SpanLevelParser
|
23
|
+
|
24
|
+
# a string scanner coded by me
|
25
|
+
class CharSourceManual; end
|
26
|
+
|
27
|
+
# a wrapper around StringScanner
|
28
|
+
class CharSourceStrscan; end
|
29
|
+
|
30
|
+
# A debug scanner that checks the correctness of both
|
31
|
+
# by comparing their output
|
32
|
+
class CharSourceDebug; end
|
33
|
+
|
34
|
+
# Choose!
|
35
|
+
|
36
|
+
CharSource = CharSourceManual # faster! 58ms vs. 65ms
|
37
|
+
#CharSource = CharSourceStrscan
|
38
|
+
#CharSource = CharSourceDebug
|
39
|
+
|
40
|
+
|
41
|
+
class CharSourceManual
|
42
|
+
include MaRuKu::Strings
|
43
|
+
|
44
|
+
def initialize(s, parent=nil)
|
45
|
+
raise "Passed #{s.class}" if not s.kind_of? String
|
46
|
+
@buffer = s
|
47
|
+
@buffer_index = 0
|
48
|
+
@parent = parent
|
49
|
+
end
|
50
|
+
|
51
|
+
# Return current char as a FixNum (or nil).
|
52
|
+
def cur_char; @buffer[@buffer_index] end
|
53
|
+
|
54
|
+
# Return the next n chars as a String.
|
55
|
+
def cur_chars(n); @buffer[@buffer_index,n] end
|
56
|
+
|
57
|
+
# Return the char after current char as a FixNum (or nil).
|
58
|
+
def next_char; @buffer[@buffer_index+1] end
|
59
|
+
|
60
|
+
def shift_char
|
61
|
+
c = @buffer[@buffer_index]
|
62
|
+
@buffer_index+=1
|
63
|
+
c
|
64
|
+
end
|
65
|
+
|
66
|
+
def ignore_char
|
67
|
+
@buffer_index+=1
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def ignore_chars(n)
|
72
|
+
@buffer_index+=n
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def current_remaining_buffer
|
77
|
+
@buffer[@buffer_index, @buffer.size-@buffer_index]
|
78
|
+
end
|
79
|
+
|
80
|
+
def cur_chars_are(string)
|
81
|
+
# There is a bug here
|
82
|
+
if false
|
83
|
+
r2 = /^.{#{@buffer_index}}#{Regexp.escape string}/m
|
84
|
+
@buffer =~ r2
|
85
|
+
else
|
86
|
+
cur_chars(string.size) == string
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def next_matches(r)
|
91
|
+
r2 = /^.{#{@buffer_index}}#{r}/m
|
92
|
+
md = r2.match @buffer
|
93
|
+
return !!md
|
94
|
+
end
|
95
|
+
|
96
|
+
def read_regexp3(r)
|
97
|
+
r2 = /^.{#{@buffer_index}}#{r}/m
|
98
|
+
m = r2.match @buffer
|
99
|
+
if m
|
100
|
+
consumed = m.to_s.size - @buffer_index
|
101
|
+
# puts "Consumed #{consumed} chars (entire is #{m.to_s.inspect})"
|
102
|
+
ignore_chars consumed
|
103
|
+
else
|
104
|
+
# puts "Could not read regexp #{r2.inspect} from buffer "+
|
105
|
+
# " index=#{@buffer_index}"
|
106
|
+
# puts "Cur chars = #{cur_chars(20).inspect}"
|
107
|
+
# puts "Matches? = #{cur_chars(20) =~ r}"
|
108
|
+
end
|
109
|
+
m
|
110
|
+
end
|
111
|
+
|
112
|
+
def read_regexp(r)
|
113
|
+
r2 = /^#{r}/
|
114
|
+
rest = current_remaining_buffer
|
115
|
+
m = r2.match(rest)
|
116
|
+
if m
|
117
|
+
@buffer_index += m.to_s.size
|
118
|
+
# puts "#{r} matched #{rest.inspect}: #{m.to_s.inspect}"
|
119
|
+
end
|
120
|
+
return m
|
121
|
+
end
|
122
|
+
|
123
|
+
def consume_whitespace
|
124
|
+
while c = cur_char
|
125
|
+
if (c == ?\s || c == ?\t)
|
126
|
+
# puts "ignoring #{c}"
|
127
|
+
ignore_char
|
128
|
+
else
|
129
|
+
# puts "#{c} is not ws: "<<c
|
130
|
+
break
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def read_text_chars(out)
|
136
|
+
s = @buffer.size; c=nil
|
137
|
+
while @buffer_index < s && (c=@buffer[@buffer_index]) &&
|
138
|
+
((c>=?a && c<=?z) || (c>=?A && c<=?Z))
|
139
|
+
out << c
|
140
|
+
@buffer_index += 1
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def describe
|
145
|
+
s = describe_pos(@buffer, @buffer_index)
|
146
|
+
if @parent
|
147
|
+
s += "\n\n" + @parent.describe
|
148
|
+
end
|
149
|
+
s
|
150
|
+
end
|
151
|
+
include SpanLevelParser
|
152
|
+
end
|
153
|
+
|
154
|
+
def describe_pos(buffer, buffer_index)
|
155
|
+
len = 75
|
156
|
+
num_before = [len/2, buffer_index].min
|
157
|
+
num_after = [len/2, buffer.size-buffer_index].min
|
158
|
+
num_before_max = buffer_index
|
159
|
+
num_after_max = buffer.size-buffer_index
|
160
|
+
|
161
|
+
# puts "num #{num_before} #{num_after}"
|
162
|
+
num_before = [num_before_max, len-num_after].min
|
163
|
+
num_after = [num_after_max, len-num_before].min
|
164
|
+
# puts "num #{num_before} #{num_after}"
|
165
|
+
|
166
|
+
index_start = [buffer_index - num_before, 0].max
|
167
|
+
index_end = [buffer_index + num_after, buffer.size].min
|
168
|
+
|
169
|
+
size = index_end- index_start
|
170
|
+
|
171
|
+
# puts "- #{index_start} #{size}"
|
172
|
+
|
173
|
+
str = buffer[index_start, size]
|
174
|
+
str.gsub!("\n",'N')
|
175
|
+
str.gsub!("\t",'T')
|
176
|
+
|
177
|
+
if index_end == buffer.size
|
178
|
+
str += "EOF"
|
179
|
+
end
|
180
|
+
|
181
|
+
pre_s = buffer_index-index_start
|
182
|
+
pre_s = [pre_s, 0].max
|
183
|
+
pre_s2 = [len-pre_s,0].max
|
184
|
+
# puts "pre_S = #{pre_s}"
|
185
|
+
pre =" "*(pre_s)
|
186
|
+
|
187
|
+
"-"*len+"\n"+
|
188
|
+
str + "\n" +
|
189
|
+
"-"*pre_s + "|" + "-"*(pre_s2)+"\n"+
|
190
|
+
# pre + "|\n"+
|
191
|
+
pre + "+--- Byte #{buffer_index}\n"+
|
192
|
+
|
193
|
+
"Shown bytes [#{index_start} to #{size}] of #{buffer.size}:\n"+
|
194
|
+
add_tabs(buffer,1,">")
|
195
|
+
|
196
|
+
# "CharSource: At character #{@buffer_index} of block "+
|
197
|
+
# " beginning with:\n #{@buffer[0,50].inspect} ...\n"+
|
198
|
+
# " before: \n ... #{cur_chars(50).inspect} ... "
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
require 'strscan'
|
203
|
+
|
204
|
+
class CharSourceStrscan
|
205
|
+
include SpanLevelParser
|
206
|
+
include MaRuKu::Strings
|
207
|
+
|
208
|
+
def initialize(s, parent=nil)
|
209
|
+
@s = StringScanner.new(s)
|
210
|
+
@parent = parent
|
211
|
+
end
|
212
|
+
|
213
|
+
# Return current char as a FixNum (or nil).
|
214
|
+
def cur_char
|
215
|
+
@s.peek(1)[0]
|
216
|
+
end
|
217
|
+
|
218
|
+
# Return the next n chars as a String.
|
219
|
+
def cur_chars(n);
|
220
|
+
@s.peek(n)
|
221
|
+
end
|
222
|
+
|
223
|
+
# Return the char after current char as a FixNum (or nil).
|
224
|
+
def next_char;
|
225
|
+
@s.peek(2)[1]
|
226
|
+
end
|
227
|
+
|
228
|
+
def shift_char
|
229
|
+
(@s.get_byte)[0]
|
230
|
+
end
|
231
|
+
|
232
|
+
def ignore_char
|
233
|
+
@s.get_byte
|
234
|
+
nil
|
235
|
+
end
|
236
|
+
|
237
|
+
def ignore_chars(n)
|
238
|
+
n.times do @s.get_byte end
|
239
|
+
nil
|
240
|
+
end
|
241
|
+
|
242
|
+
def current_remaining_buffer
|
243
|
+
@s.rest #nil #@buffer[@buffer_index, @buffer.size-@buffer_index]
|
244
|
+
end
|
245
|
+
|
246
|
+
def cur_chars_are(string)
|
247
|
+
cur_chars(string.size) == string
|
248
|
+
end
|
249
|
+
|
250
|
+
def next_matches(r)
|
251
|
+
len = @s.match?(r)
|
252
|
+
return !!len
|
253
|
+
end
|
254
|
+
|
255
|
+
def read_regexp(r)
|
256
|
+
string = @s.scan(r)
|
257
|
+
if string
|
258
|
+
return r.match(string)
|
259
|
+
else
|
260
|
+
return nil
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def consume_whitespace
|
265
|
+
@s.scan(/\s+/)
|
266
|
+
nil
|
267
|
+
end
|
268
|
+
|
269
|
+
def describe
|
270
|
+
describe_pos(@s.string, @s.pos)
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
class CharSourceDebug
|
277
|
+
def initialize(s, parent)
|
278
|
+
@a = CharSourceManual.new(s, parent)
|
279
|
+
@b = CharSourceStrscan.new(s, parent)
|
280
|
+
end
|
281
|
+
|
282
|
+
def method_missing(methodname, *args)
|
283
|
+
a_bef = @a.describe
|
284
|
+
b_bef = @b.describe
|
285
|
+
|
286
|
+
a = @a.send(methodname, *args)
|
287
|
+
b = @b.send(methodname, *args)
|
288
|
+
|
289
|
+
# if methodname == :describe
|
290
|
+
# return a
|
291
|
+
# end
|
292
|
+
|
293
|
+
if a.kind_of? MatchData
|
294
|
+
if a.to_a != b.to_a
|
295
|
+
puts "called: #{methodname}(#{args})"
|
296
|
+
puts "Matchdata:\na = #{a.to_a.inspect}\nb = #{b.to_a.inspect}"
|
297
|
+
puts "AFTER: "+@a.describe
|
298
|
+
puts "AFTER: "+@b.describe
|
299
|
+
puts "BEFORE: "+a_bef
|
300
|
+
puts "BEFORE: "+b_bef
|
301
|
+
puts caller.join("\n")
|
302
|
+
exit
|
303
|
+
end
|
304
|
+
else
|
305
|
+
if a!=b
|
306
|
+
puts "called: #{methodname}(#{args})"
|
307
|
+
puts "Attenzione!\na = #{a.inspect}\nb = #{b.inspect}"
|
308
|
+
puts ""+@a.describe
|
309
|
+
puts ""+@b.describe
|
310
|
+
puts caller.join("\n")
|
311
|
+
exit
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
if @a.cur_char != @b.cur_char
|
316
|
+
puts "Fuori sincronia dopo #{methodname}(#{args})"
|
317
|
+
puts ""+@a.describe
|
318
|
+
puts ""+@b.describe
|
319
|
+
exit
|
320
|
+
end
|
321
|
+
|
322
|
+
return a
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
end end end end
|