rdoc 3.12.2 → 4.0.0.preview2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rdoc might be problematic. Click here for more details.
- checksums.yaml +6 -6
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.autotest +3 -2
- data/DEVELOPERS.rdoc +53 -0
- data/History.rdoc +159 -25
- data/LEGAL.rdoc +12 -0
- data/Manifest.txt +56 -3
- data/README.rdoc +87 -19
- data/Rakefile +11 -2
- data/TODO.rdoc +20 -13
- data/bin/rdoc +4 -0
- data/lib/gauntlet_rdoc.rb +1 -1
- data/lib/rdoc.rb +32 -71
- data/lib/rdoc/any_method.rb +75 -21
- data/lib/rdoc/attr.rb +49 -10
- data/lib/rdoc/class_module.rb +182 -32
- data/lib/rdoc/code_object.rb +54 -12
- data/lib/rdoc/comment.rb +8 -1
- data/lib/rdoc/constant.rb +100 -6
- data/lib/rdoc/context.rb +93 -41
- data/lib/rdoc/context/section.rb +143 -28
- data/lib/rdoc/cross_reference.rb +58 -50
- data/lib/rdoc/encoding.rb +34 -29
- data/lib/rdoc/erb_partial.rb +18 -0
- data/lib/rdoc/extend.rb +117 -0
- data/lib/rdoc/generator.rb +11 -6
- data/lib/rdoc/generator/darkfish.rb +250 -62
- data/lib/rdoc/generator/json_index.rb +20 -12
- data/lib/rdoc/generator/markup.rb +10 -12
- data/lib/rdoc/generator/ri.rb +7 -60
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
- data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
- data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
- data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
- data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
- data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
- data/lib/rdoc/include.rb +12 -3
- data/lib/rdoc/markdown.kpeg +1186 -0
- data/lib/rdoc/markdown.rb +16336 -0
- data/lib/rdoc/markdown/entities.rb +2128 -0
- data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
- data/lib/rdoc/markdown/literals_1_8.rb +454 -0
- data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
- data/lib/rdoc/markdown/literals_1_9.rb +417 -0
- data/lib/rdoc/markup.rb +69 -10
- data/lib/rdoc/markup/attr_changer.rb +2 -5
- data/lib/rdoc/markup/attribute_manager.rb +23 -14
- data/lib/rdoc/markup/attributes.rb +70 -0
- data/lib/rdoc/markup/block_quote.rb +14 -0
- data/lib/rdoc/markup/document.rb +20 -4
- data/lib/rdoc/markup/formatter.rb +17 -6
- data/lib/rdoc/markup/formatter_test_case.rb +93 -24
- data/lib/rdoc/markup/hard_break.rb +31 -0
- data/lib/rdoc/markup/heading.rb +1 -1
- data/lib/rdoc/markup/indented_paragraph.rb +14 -0
- data/lib/rdoc/markup/list.rb +23 -4
- data/lib/rdoc/markup/list_item.rb +17 -4
- data/lib/rdoc/markup/paragraph.rb +14 -0
- data/lib/rdoc/markup/parser.rb +107 -60
- data/lib/rdoc/markup/raw.rb +4 -4
- data/lib/rdoc/markup/special.rb +3 -3
- data/lib/rdoc/markup/to_ansi.rb +7 -1
- data/lib/rdoc/markup/to_html.rb +42 -14
- data/lib/rdoc/markup/to_html_crossref.rb +10 -9
- data/lib/rdoc/markup/to_html_snippet.rb +20 -4
- data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
- data/lib/rdoc/markup/to_label.rb +20 -1
- data/lib/rdoc/markup/to_markdown.rb +134 -0
- data/lib/rdoc/markup/to_rdoc.rb +36 -5
- data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
- data/lib/rdoc/markup/to_tt_only.rb +11 -2
- data/lib/rdoc/markup/verbatim.rb +19 -0
- data/lib/rdoc/method_attr.rb +33 -19
- data/lib/rdoc/normal_class.rb +26 -7
- data/lib/rdoc/normal_module.rb +10 -5
- data/lib/rdoc/options.rb +95 -21
- data/lib/rdoc/parser.rb +6 -2
- data/lib/rdoc/parser/c.rb +212 -97
- data/lib/rdoc/parser/markdown.rb +23 -0
- data/lib/rdoc/parser/ruby.rb +115 -35
- data/lib/rdoc/parser/ruby_tools.rb +8 -3
- data/lib/rdoc/rd.rb +8 -4
- data/lib/rdoc/rd/block_parser.rb +1 -1
- data/lib/rdoc/rd/block_parser.ry +1 -1
- data/lib/rdoc/rdoc.rb +45 -21
- data/lib/rdoc/ri/driver.rb +322 -76
- data/lib/rdoc/ri/paths.rb +90 -31
- data/lib/rdoc/ri/store.rb +2 -353
- data/lib/rdoc/ruby_lex.rb +5 -21
- data/lib/rdoc/ruby_token.rb +2 -3
- data/lib/rdoc/rubygems_hook.rb +21 -9
- data/lib/rdoc/servlet.rb +302 -0
- data/lib/rdoc/stats.rb +28 -20
- data/lib/rdoc/store.rb +881 -0
- data/lib/rdoc/task.rb +2 -1
- data/lib/rdoc/test_case.rb +103 -1
- data/lib/rdoc/text.rb +5 -4
- data/lib/rdoc/tom_doc.rb +17 -16
- data/lib/rdoc/top_level.rb +43 -285
- data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
- data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
- data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
- data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
- data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
- data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
- data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
- data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
- data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
- data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
- data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
- data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
- data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
- data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
- data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
- data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
- data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
- data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
- data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
- data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
- data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
- data/test/test_attribute_manager.rb +7 -4
- data/test/test_rdoc_any_method.rb +84 -13
- data/test/test_rdoc_attr.rb +59 -9
- data/test/test_rdoc_class_module.rb +670 -73
- data/test/test_rdoc_code_object.rb +21 -1
- data/test/test_rdoc_comment.rb +1 -1
- data/test/test_rdoc_constant.rb +132 -0
- data/test/test_rdoc_context.rb +84 -18
- data/test/test_rdoc_context_section.rb +99 -15
- data/test/test_rdoc_cross_reference.rb +1 -1
- data/test/test_rdoc_encoding.rb +17 -1
- data/test/test_rdoc_extend.rb +94 -0
- data/test/test_rdoc_generator_darkfish.rb +45 -19
- data/test/test_rdoc_generator_json_index.rb +27 -7
- data/test/test_rdoc_generator_markup.rb +3 -3
- data/test/test_rdoc_generator_ri.rb +11 -9
- data/test/test_rdoc_include.rb +12 -0
- data/test/test_rdoc_markdown.rb +977 -0
- data/test/test_rdoc_markdown_test.rb +1891 -0
- data/test/test_rdoc_markup.rb +1 -1
- data/test/test_rdoc_markup_attribute_manager.rb +2 -2
- data/test/test_rdoc_markup_attributes.rb +39 -0
- data/test/test_rdoc_markup_document.rb +16 -1
- data/test/test_rdoc_markup_formatter.rb +7 -4
- data/test/test_rdoc_markup_hard_break.rb +31 -0
- data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
- data/test/test_rdoc_markup_paragraph.rb +15 -1
- data/test/test_rdoc_markup_parser.rb +152 -89
- data/test/test_rdoc_markup_to_ansi.rb +23 -2
- data/test/test_rdoc_markup_to_bs.rb +24 -0
- data/test/test_rdoc_markup_to_html.rb +50 -19
- data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
- data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
- data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
- data/test/test_rdoc_markup_to_label.rb +63 -1
- data/test/test_rdoc_markup_to_markdown.rb +352 -0
- data/test/test_rdoc_markup_to_rdoc.rb +22 -2
- data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
- data/test/test_rdoc_markup_to_tt_only.rb +20 -0
- data/test/test_rdoc_markup_verbatim.rb +13 -0
- data/test/test_rdoc_method_attr.rb +5 -0
- data/test/test_rdoc_normal_class.rb +24 -5
- data/test/test_rdoc_normal_module.rb +1 -1
- data/test/test_rdoc_options.rb +21 -6
- data/test/test_rdoc_parser.rb +24 -0
- data/test/test_rdoc_parser_c.rb +151 -26
- data/test/test_rdoc_parser_markdown.rb +55 -0
- data/test/test_rdoc_parser_rd.rb +2 -2
- data/test/test_rdoc_parser_ruby.rb +468 -109
- data/test/test_rdoc_parser_simple.rb +2 -2
- data/test/test_rdoc_rd_block_parser.rb +0 -4
- data/test/test_rdoc_rdoc.rb +110 -22
- data/test/test_rdoc_ri_driver.rb +415 -80
- data/test/test_rdoc_ri_paths.rb +122 -13
- data/test/test_rdoc_ruby_lex.rb +5 -61
- data/test/test_rdoc_ruby_token.rb +19 -0
- data/test/test_rdoc_rubygems_hook.rb +64 -43
- data/test/test_rdoc_servlet.rb +429 -0
- data/test/test_rdoc_stats.rb +83 -24
- data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
- data/test/test_rdoc_task.rb +2 -2
- data/test/test_rdoc_text.rb +37 -11
- data/test/test_rdoc_tom_doc.rb +59 -62
- data/test/test_rdoc_top_level.rb +71 -113
- data/test/xref_test_case.rb +7 -9
- metadata +122 -39
- metadata.gz.sig +0 -0
- data/CVE-2013-0256.rdoc +0 -49
- data/lib/rdoc/markup/attribute.rb +0 -51
@@ -0,0 +1,18 @@
|
|
1
|
+
<body>
|
2
|
+
<nav id="metadata">
|
3
|
+
<%= render '_sidebar_navigation.rhtml' %>
|
4
|
+
|
5
|
+
<%= render '_sidebar_search.rhtml' %>
|
6
|
+
|
7
|
+
<div id="project-metadata">
|
8
|
+
<%= render '_sidebar_pages.rhtml' %>
|
9
|
+
<%= render '_sidebar_classes.rhtml' %>
|
10
|
+
</div>
|
11
|
+
</nav>
|
12
|
+
|
13
|
+
<div id="documentation" class="description">
|
14
|
+
<h1>Not Found</h1>
|
15
|
+
|
16
|
+
<p>The page <kbd><%=h path %></kbd> was not found
|
17
|
+
</div>
|
18
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<body>
|
2
|
+
<nav id="metadata">
|
3
|
+
<%= render '_sidebar_search.rhtml' %>
|
4
|
+
|
5
|
+
<%= render '_sidebar_installed.rhtml' %>
|
6
|
+
</nav>
|
7
|
+
|
8
|
+
<div id="documentation" class="description">
|
9
|
+
<h1>Local RDoc Documentation</h1>
|
10
|
+
|
11
|
+
<p>Here you can browse local documentation from the ruby standard library and
|
12
|
+
your installed gems.
|
13
|
+
|
14
|
+
<% gems = installed.select { |_, _, _, type,| type == :gem } %>
|
15
|
+
<% missing = gems.reject { |_, _, exists,| exists } %>
|
16
|
+
<% unless missing.empty? then %>
|
17
|
+
<h2>Missing Gem Documentation</h2>
|
18
|
+
|
19
|
+
<p>You are missing documentation for some of your installed gems.
|
20
|
+
You can install missing documentation for gems by running
|
21
|
+
<kbd>gem rdoc --all</kbd>. After installing the missing documentation you
|
22
|
+
only need to reload this page. The newly created documentation will
|
23
|
+
automatically appear.
|
24
|
+
|
25
|
+
<p>You can also install documentation for a specific gem by running one of
|
26
|
+
the following commands.
|
27
|
+
|
28
|
+
<ul>
|
29
|
+
<% names = missing.map { |name,| name.sub(/-([^-]*)$/, '') }.uniq %>
|
30
|
+
<% names.each do |name| %>
|
31
|
+
<li><kbd>gem rdoc <%=h name %></kbd>
|
32
|
+
<% end %>
|
33
|
+
</ul>
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
</div>
|
37
|
+
|
@@ -30,8 +30,8 @@
|
|
30
30
|
<li class="<%= klass.type %>">
|
31
31
|
<a href="<%= klass.path %>"><%= klass.full_name %></a>
|
32
32
|
<% table = []
|
33
|
-
table.
|
34
|
-
table.
|
33
|
+
table.concat klass.parse(klass.comment).table_of_contents
|
34
|
+
table.concat klass.section_contents
|
35
35
|
|
36
36
|
unless table.empty? then %>
|
37
37
|
<img class="toc-toggle" src="images/transparent.png" alt="" title="toggle headings">
|
@@ -47,7 +47,7 @@
|
|
47
47
|
|
48
48
|
<h2 id="methods">Methods</h2>
|
49
49
|
<ul>
|
50
|
-
<%
|
50
|
+
<% @store.all_classes_and_modules.map do |mod|
|
51
51
|
mod.method_list
|
52
52
|
end.flatten.sort.each do |method| %>
|
53
53
|
<li class="method"><a href="<%= method.path %>"><%= method.pretty_name %> — <%= method.parent.full_name %></a>
|
data/lib/rdoc/include.rb
CHANGED
@@ -76,7 +76,7 @@ class RDoc::Include < RDoc::CodeObject
|
|
76
76
|
# search the current context
|
77
77
|
return @name unless parent
|
78
78
|
full_name = parent.child_name(@name)
|
79
|
-
@module =
|
79
|
+
@module = @store.modules_hash[full_name]
|
80
80
|
return @module if @module
|
81
81
|
return @name if @name =~ /^::/
|
82
82
|
|
@@ -86,7 +86,7 @@ class RDoc::Include < RDoc::CodeObject
|
|
86
86
|
inc = i.module
|
87
87
|
next if String === inc
|
88
88
|
full_name = inc.child_name(@name)
|
89
|
-
@module =
|
89
|
+
@module = @store.modules_hash[full_name]
|
90
90
|
return @module if @module
|
91
91
|
end
|
92
92
|
|
@@ -94,7 +94,7 @@ class RDoc::Include < RDoc::CodeObject
|
|
94
94
|
up = parent.parent
|
95
95
|
while up
|
96
96
|
full_name = up.child_name(@name)
|
97
|
-
@module =
|
97
|
+
@module = @store.modules_hash[full_name]
|
98
98
|
return @module if @module
|
99
99
|
up = up.parent
|
100
100
|
end
|
@@ -102,6 +102,15 @@ class RDoc::Include < RDoc::CodeObject
|
|
102
102
|
@name
|
103
103
|
end
|
104
104
|
|
105
|
+
##
|
106
|
+
# Sets the store for this class or module and its contained code objects.
|
107
|
+
|
108
|
+
def store= store
|
109
|
+
super
|
110
|
+
|
111
|
+
@file = @store.add_file @file.full_name if @file
|
112
|
+
end
|
113
|
+
|
105
114
|
def to_s # :nodoc:
|
106
115
|
"include #@name in: #{parent}"
|
107
116
|
end
|
@@ -0,0 +1,1186 @@
|
|
1
|
+
%% name = RDoc::Markdown
|
2
|
+
|
3
|
+
%% header {
|
4
|
+
# coding: UTF-8
|
5
|
+
# :markup: markdown
|
6
|
+
|
7
|
+
##
|
8
|
+
# RDoc::Markdown as described by the [markdown syntax][syntax].
|
9
|
+
#
|
10
|
+
# To choose Markdown as your only default format see
|
11
|
+
# RDoc::Options@Saved+Options for instructions on setting up a `.doc_options`
|
12
|
+
# file to store your project default.
|
13
|
+
#
|
14
|
+
# ## Extensions
|
15
|
+
#
|
16
|
+
# The following markdown extensions are supported by the parser, but not all
|
17
|
+
# are used in RDoc output by default.
|
18
|
+
#
|
19
|
+
# ### RDoc
|
20
|
+
#
|
21
|
+
# The RDoc Markdown parser has the following built-in behaviors that cannot be
|
22
|
+
# disabled.
|
23
|
+
#
|
24
|
+
# Underscores embedded in words are never interpreted as emphasis. (While the
|
25
|
+
# [markdown dingus][dingus] emphasizes in-word underscores, neither the
|
26
|
+
# Markdown syntax nor MarkdownTest mention this behavior.)
|
27
|
+
#
|
28
|
+
# For HTML output, RDoc always auto-links bare URLs.
|
29
|
+
#
|
30
|
+
# ### Break on Newline
|
31
|
+
#
|
32
|
+
# The break_on_newline extension converts all newlines into hard line breaks
|
33
|
+
# as in [Github Flavored Markdown][GFM]. This extension is disabled by
|
34
|
+
# default.
|
35
|
+
#
|
36
|
+
# ### CSS
|
37
|
+
#
|
38
|
+
# The #css extension enables CSS blocks to be included in the output, but they
|
39
|
+
# are not used for any built-in RDoc output format. This extension is disabled
|
40
|
+
# by default.
|
41
|
+
#
|
42
|
+
# Example:
|
43
|
+
#
|
44
|
+
# <style type="text/css">
|
45
|
+
# h1 { font-size: 3em }
|
46
|
+
# </style>
|
47
|
+
#
|
48
|
+
# ### Definition Lists
|
49
|
+
#
|
50
|
+
# The definition_lists extension allows definition lists using the [PHP
|
51
|
+
# Markdown Extra syntax][PHPE], but only one label and definition are supported
|
52
|
+
# at this time. This extension is enabled by default.
|
53
|
+
#
|
54
|
+
# Example:
|
55
|
+
#
|
56
|
+
# ```
|
57
|
+
# cat
|
58
|
+
# : A small furry mammal
|
59
|
+
# that seems to sleep a lot
|
60
|
+
#
|
61
|
+
# ant
|
62
|
+
# : A little insect that is known
|
63
|
+
# to enjoy picnics
|
64
|
+
#
|
65
|
+
# ```
|
66
|
+
#
|
67
|
+
# Produces:
|
68
|
+
#
|
69
|
+
# cat
|
70
|
+
# : A small furry mammal
|
71
|
+
# that seems to sleep a lot
|
72
|
+
#
|
73
|
+
# ant
|
74
|
+
# : A little insect that is known
|
75
|
+
# to enjoy picnics
|
76
|
+
#
|
77
|
+
# ### Github
|
78
|
+
#
|
79
|
+
# The #github extension enables a partial set of [Github Flavored Markdown]
|
80
|
+
# [GFM]. This extension is enabled by default.
|
81
|
+
#
|
82
|
+
# Supported github extensions include:
|
83
|
+
#
|
84
|
+
# #### Fenced code blocks
|
85
|
+
#
|
86
|
+
# Use ` ``` ` around a block of code instead of indenting it four spaces.
|
87
|
+
#
|
88
|
+
# #### Syntax highlighting
|
89
|
+
#
|
90
|
+
# Use ` ``` ruby ` as the start of a code fence to add syntax highlighting.
|
91
|
+
# (Currently only `ruby` syntax is supported).
|
92
|
+
#
|
93
|
+
# ### HTML
|
94
|
+
#
|
95
|
+
# Enables raw HTML to be included in the output. This extension is enabled by
|
96
|
+
# default.
|
97
|
+
#
|
98
|
+
# Example:
|
99
|
+
#
|
100
|
+
# <table>
|
101
|
+
# ...
|
102
|
+
# </table>
|
103
|
+
#
|
104
|
+
# ### Notes
|
105
|
+
#
|
106
|
+
# The #notes extension enables footnote support. This extension is enabled by
|
107
|
+
# default.
|
108
|
+
#
|
109
|
+
# Example:
|
110
|
+
#
|
111
|
+
# Here is some text[^1] including an inline footnote ^[for short footnotes]
|
112
|
+
#
|
113
|
+
# ...
|
114
|
+
#
|
115
|
+
# [^1]: With the footnote text down at the bottom
|
116
|
+
#
|
117
|
+
# Produces:
|
118
|
+
#
|
119
|
+
# Here is some text[^1] including an inline footnote ^[for short footnotes]
|
120
|
+
#
|
121
|
+
# [^1]: With the footnote text down at the bottom
|
122
|
+
#
|
123
|
+
# ## Limitations
|
124
|
+
#
|
125
|
+
# * Link titles are not used
|
126
|
+
# * Image links are not generated correctly
|
127
|
+
# * Footnotes are collapsed into a single paragraph
|
128
|
+
#
|
129
|
+
# ## Author
|
130
|
+
#
|
131
|
+
# This markdown parser is a port to kpeg from [peg-markdown][pegmarkdown] by
|
132
|
+
# John MacFarlane.
|
133
|
+
#
|
134
|
+
# It is used under the MIT license:
|
135
|
+
#
|
136
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
137
|
+
# of this software and associated documentation files (the "Software"), to deal
|
138
|
+
# in the Software without restriction, including without limitation the rights
|
139
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
140
|
+
# copies of the Software, and to permit persons to whom the Software is
|
141
|
+
# furnished to do so, subject to the following conditions:
|
142
|
+
#
|
143
|
+
# The above copyright notice and this permission notice shall be included in
|
144
|
+
# all copies or substantial portions of the Software.
|
145
|
+
#
|
146
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
147
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
148
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
149
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
150
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
151
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
152
|
+
# THE SOFTWARE.
|
153
|
+
#
|
154
|
+
# The port to kpeg was performed by Eric Hodel and Evan Phoenix
|
155
|
+
#
|
156
|
+
# [dingus]: http://daringfireball.net/projects/markdown/dingus
|
157
|
+
# [GFM]: http://github.github.com/github-flavored-markdown/
|
158
|
+
# [pegmarkdown]: https://github.com/jgm/peg-markdown
|
159
|
+
# [PHPE]: http://michelf.com/projects/php-markdown/extra/#def-list
|
160
|
+
# [syntax]: http://daringfireball.net/projects/markdown/syntax
|
161
|
+
#--
|
162
|
+
# Last updated to jgm/peg-markdown commit 8f8fc22ef0
|
163
|
+
|
164
|
+
}
|
165
|
+
|
166
|
+
%% {
|
167
|
+
|
168
|
+
require 'rubygems'
|
169
|
+
require 'rdoc'
|
170
|
+
require 'rdoc/markup/to_joined_paragraph'
|
171
|
+
require 'rdoc/markdown/entities'
|
172
|
+
|
173
|
+
if RUBY_VERSION > '1.9' then
|
174
|
+
require 'rdoc/markdown/literals_1_9'
|
175
|
+
else
|
176
|
+
require 'rdoc/markdown/literals_1_8'
|
177
|
+
end
|
178
|
+
|
179
|
+
##
|
180
|
+
# Supported extensions
|
181
|
+
|
182
|
+
EXTENSIONS = []
|
183
|
+
|
184
|
+
##
|
185
|
+
# Extensions enabled by default
|
186
|
+
|
187
|
+
DEFAULT_EXTENSIONS = [
|
188
|
+
:definition_lists,
|
189
|
+
:github,
|
190
|
+
:html,
|
191
|
+
:notes,
|
192
|
+
]
|
193
|
+
|
194
|
+
# :section: Extensions
|
195
|
+
|
196
|
+
##
|
197
|
+
# Creates extension methods for the `name` extension to enable and disable
|
198
|
+
# the extension and to query if they are active.
|
199
|
+
|
200
|
+
def self.extension name
|
201
|
+
EXTENSIONS << name
|
202
|
+
|
203
|
+
eval <<-RUBY
|
204
|
+
def #{name}?
|
205
|
+
extension? __method__
|
206
|
+
end
|
207
|
+
|
208
|
+
def #{name}= enable
|
209
|
+
extension __method__, enable
|
210
|
+
end
|
211
|
+
RUBY
|
212
|
+
end
|
213
|
+
|
214
|
+
##
|
215
|
+
# Converts all newlines into hard breaks
|
216
|
+
|
217
|
+
extension :break_on_newline
|
218
|
+
|
219
|
+
##
|
220
|
+
# Allow style blocks
|
221
|
+
|
222
|
+
extension :css
|
223
|
+
|
224
|
+
##
|
225
|
+
# Allow PHP Markdown Extras style definition lists
|
226
|
+
|
227
|
+
extension :definition_lists
|
228
|
+
|
229
|
+
##
|
230
|
+
# Allow Github Flavored Markdown
|
231
|
+
|
232
|
+
extension :github
|
233
|
+
|
234
|
+
##
|
235
|
+
# Allow HTML
|
236
|
+
|
237
|
+
extension :html
|
238
|
+
|
239
|
+
##
|
240
|
+
# Enables the notes extension
|
241
|
+
|
242
|
+
extension :notes
|
243
|
+
|
244
|
+
# :section:
|
245
|
+
|
246
|
+
##
|
247
|
+
# Parses the `markdown` document into an RDoc::Document using the default
|
248
|
+
# extensions.
|
249
|
+
|
250
|
+
def self.parse markdown
|
251
|
+
parser = new
|
252
|
+
|
253
|
+
parser.parse markdown
|
254
|
+
end
|
255
|
+
|
256
|
+
# TODO remove when kpeg 0.10 is released
|
257
|
+
alias orig_initialize initialize # :nodoc:
|
258
|
+
|
259
|
+
##
|
260
|
+
# Creates a new markdown parser that enables the given +extensions+.
|
261
|
+
|
262
|
+
def initialize extensions = DEFAULT_EXTENSIONS, debug = false
|
263
|
+
@debug = debug
|
264
|
+
@formatter = RDoc::Markup::ToJoinedParagraph.new
|
265
|
+
@extensions = extensions
|
266
|
+
|
267
|
+
@references = nil
|
268
|
+
@unlinked_references = nil
|
269
|
+
|
270
|
+
@footnotes = nil
|
271
|
+
@note_order = nil
|
272
|
+
end
|
273
|
+
|
274
|
+
##
|
275
|
+
# Wraps `text` in emphasis for rdoc inline formatting
|
276
|
+
|
277
|
+
def emphasis text
|
278
|
+
if text =~ /\A[a-z\d.\/]+\z/i then
|
279
|
+
"_#{text}_"
|
280
|
+
else
|
281
|
+
"<em>#{text}</em>"
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
##
|
286
|
+
# :category: Extensions
|
287
|
+
#
|
288
|
+
# Is the extension `name` enabled?
|
289
|
+
|
290
|
+
def extension? name
|
291
|
+
name = name.to_s.delete('?').intern
|
292
|
+
|
293
|
+
@extensions.include? name
|
294
|
+
end
|
295
|
+
|
296
|
+
##
|
297
|
+
# :category: Extensions
|
298
|
+
#
|
299
|
+
# Enables or disables the extension with `name`
|
300
|
+
|
301
|
+
def extension name, enable
|
302
|
+
name = name.to_s.delete('=').intern
|
303
|
+
|
304
|
+
if enable then
|
305
|
+
@extensions |= [name]
|
306
|
+
else
|
307
|
+
@extensions -= [name]
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
##
|
312
|
+
# Parses `text` in a clone of this parser. This is used for handling nested
|
313
|
+
# lists the same way as markdown_parser.
|
314
|
+
|
315
|
+
def inner_parse text # :nodoc:
|
316
|
+
parser = clone
|
317
|
+
|
318
|
+
parser.setup_parser text, @debug
|
319
|
+
|
320
|
+
parser.peg_parse
|
321
|
+
|
322
|
+
doc = parser.result
|
323
|
+
|
324
|
+
doc.accept @formatter
|
325
|
+
|
326
|
+
doc.parts
|
327
|
+
end
|
328
|
+
|
329
|
+
##
|
330
|
+
# Finds a link reference for `label` and creates a new link to it with
|
331
|
+
# `content` as the link text. If `label` was not encountered in the
|
332
|
+
# reference-gathering parser pass the label and content are reconstructed
|
333
|
+
# with the linking `text` (usually whitespace).
|
334
|
+
|
335
|
+
def link_to content, label = content, text = nil
|
336
|
+
raise 'enable notes extension' if
|
337
|
+
content.start_with? '^' and label.equal? content
|
338
|
+
|
339
|
+
if ref = @references[label] then
|
340
|
+
"{#{content}}[#{ref}]"
|
341
|
+
elsif label.equal? content then
|
342
|
+
"[#{content}]#{text}"
|
343
|
+
else
|
344
|
+
"[#{content}]#{text}[#{label}]"
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
##
|
349
|
+
# Creates an RDoc::Markup::ListItem by parsing the `unparsed` content from
|
350
|
+
# the first parsing pass.
|
351
|
+
|
352
|
+
def list_item_from unparsed
|
353
|
+
parsed = inner_parse unparsed.join
|
354
|
+
RDoc::Markup::ListItem.new nil, *parsed
|
355
|
+
end
|
356
|
+
|
357
|
+
##
|
358
|
+
# Stores `label` as a note and fills in previously unknown note references.
|
359
|
+
|
360
|
+
def note label
|
361
|
+
#foottext = "rdoc-label:foottext-#{label}:footmark-#{label}"
|
362
|
+
|
363
|
+
#ref.replace foottext if ref = @unlinked_notes.delete(label)
|
364
|
+
|
365
|
+
@notes[label] = foottext
|
366
|
+
|
367
|
+
#"{^1}[rdoc-label:footmark-#{label}:foottext-#{label}] "
|
368
|
+
end
|
369
|
+
|
370
|
+
##
|
371
|
+
# Creates a new link for the footnote `reference` and adds the reference to
|
372
|
+
# the note order list for proper display at the end of the document.
|
373
|
+
|
374
|
+
def note_for ref
|
375
|
+
@note_order << ref
|
376
|
+
|
377
|
+
label = @note_order.length
|
378
|
+
|
379
|
+
"{*#{label}}[rdoc-label:foottext-#{label}:footmark-#{label}]"
|
380
|
+
end
|
381
|
+
|
382
|
+
##
|
383
|
+
# The internal kpeg parse method
|
384
|
+
|
385
|
+
alias peg_parse parse # :nodoc:
|
386
|
+
|
387
|
+
##
|
388
|
+
# Creates an RDoc::Markup::Paragraph from `parts` and including
|
389
|
+
# extension-specific behavior
|
390
|
+
|
391
|
+
def paragraph parts
|
392
|
+
parts = parts.map do |part|
|
393
|
+
if "\n" == part then
|
394
|
+
RDoc::Markup::HardBreak.new
|
395
|
+
else
|
396
|
+
part
|
397
|
+
end
|
398
|
+
end if break_on_newline?
|
399
|
+
|
400
|
+
RDoc::Markup::Paragraph.new(*parts)
|
401
|
+
end
|
402
|
+
|
403
|
+
##
|
404
|
+
# Parses `markdown` into an RDoc::Document
|
405
|
+
|
406
|
+
def parse markdown
|
407
|
+
@references = {}
|
408
|
+
@unlinked_references = {}
|
409
|
+
|
410
|
+
markdown += "\n\n"
|
411
|
+
|
412
|
+
setup_parser markdown, @debug
|
413
|
+
peg_parse 'References'
|
414
|
+
|
415
|
+
if notes? then
|
416
|
+
@footnotes = {}
|
417
|
+
|
418
|
+
setup_parser markdown, @debug
|
419
|
+
peg_parse 'Notes'
|
420
|
+
|
421
|
+
# using note_order on the first pass would be a bug
|
422
|
+
@note_order = []
|
423
|
+
end
|
424
|
+
|
425
|
+
setup_parser markdown, @debug
|
426
|
+
peg_parse
|
427
|
+
|
428
|
+
doc = result
|
429
|
+
|
430
|
+
if notes? and not @footnotes.empty? then
|
431
|
+
doc << RDoc::Markup::Rule.new(1)
|
432
|
+
|
433
|
+
@note_order.each_with_index do |ref, index|
|
434
|
+
label = index + 1
|
435
|
+
note = @footnotes[ref]
|
436
|
+
|
437
|
+
link = "{^#{label}}[rdoc-label:footmark-#{label}:foottext-#{label}] "
|
438
|
+
note.parts.unshift link
|
439
|
+
|
440
|
+
doc << note
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
doc.accept @formatter
|
445
|
+
|
446
|
+
doc
|
447
|
+
end
|
448
|
+
|
449
|
+
##
|
450
|
+
# Stores `label` as a reference to `link` and fills in previously unknown
|
451
|
+
# link references.
|
452
|
+
|
453
|
+
def reference label, link
|
454
|
+
if ref = @unlinked_references.delete(label) then
|
455
|
+
ref.replace link
|
456
|
+
end
|
457
|
+
|
458
|
+
@references[label] = link
|
459
|
+
end
|
460
|
+
|
461
|
+
##
|
462
|
+
# Wraps `text` in strong markup for rdoc inline formatting
|
463
|
+
|
464
|
+
def strong text
|
465
|
+
if text =~ /\A[a-z\d.\/-]+\z/i then
|
466
|
+
"*#{text}*"
|
467
|
+
else
|
468
|
+
"<b>#{text}</b>"
|
469
|
+
end
|
470
|
+
end
|
471
|
+
}
|
472
|
+
|
473
|
+
root = Doc
|
474
|
+
|
475
|
+
Doc = BOM? Block*:a { RDoc::Markup::Document.new(*a.compact) }
|
476
|
+
|
477
|
+
Block = BlankLine*
|
478
|
+
( BlockQuote
|
479
|
+
| Verbatim
|
480
|
+
| CodeFence
|
481
|
+
| Note
|
482
|
+
| Reference
|
483
|
+
| HorizontalRule
|
484
|
+
| Heading
|
485
|
+
| OrderedList
|
486
|
+
| BulletList
|
487
|
+
| DefinitionList
|
488
|
+
| HtmlBlock
|
489
|
+
| StyleBlock
|
490
|
+
| Para
|
491
|
+
| Plain )
|
492
|
+
|
493
|
+
Para = NonindentSpace Inlines:a BlankLine+
|
494
|
+
{ paragraph a }
|
495
|
+
|
496
|
+
Plain = Inlines:a
|
497
|
+
{ paragraph a }
|
498
|
+
|
499
|
+
AtxInline = !Newline !(Sp? "#"* Sp Newline) Inline
|
500
|
+
|
501
|
+
AtxStart = < ( "######" | "#####" | "####" | "###" | "##" | "#" ) >
|
502
|
+
{ text.length }
|
503
|
+
|
504
|
+
AtxHeading = AtxStart:s Sp? AtxInline+:a (Sp? "#"* Sp)? Newline
|
505
|
+
{ RDoc::Markup::Heading.new(s, a.join) }
|
506
|
+
|
507
|
+
SetextHeading = SetextHeading1 | SetextHeading2
|
508
|
+
|
509
|
+
SetextBottom1 = "===" "="* Newline
|
510
|
+
|
511
|
+
SetextBottom2 = "---" "-"* Newline
|
512
|
+
|
513
|
+
SetextHeading1 = &(RawLine SetextBottom1)
|
514
|
+
StartList:a ( !Endline Inline:b { a << b } )+ Sp? Newline
|
515
|
+
SetextBottom1
|
516
|
+
{ RDoc::Markup::Heading.new(1, a.join) }
|
517
|
+
|
518
|
+
SetextHeading2 = &(RawLine SetextBottom2)
|
519
|
+
StartList:a ( !Endline Inline:b { a << b })+ Sp? Newline
|
520
|
+
SetextBottom2
|
521
|
+
{ RDoc::Markup::Heading.new(2, a.join) }
|
522
|
+
|
523
|
+
Heading = SetextHeading | AtxHeading
|
524
|
+
|
525
|
+
BlockQuote = BlockQuoteRaw:a
|
526
|
+
{ RDoc::Markup::BlockQuote.new(*a) }
|
527
|
+
|
528
|
+
BlockQuoteRaw = StartList:a
|
529
|
+
(( ">" " "? Line:l { a << l } )
|
530
|
+
( !">" !BlankLine Line:c { a << c } )*
|
531
|
+
( BlankLine:n { a << n } )*
|
532
|
+
)+
|
533
|
+
{ inner_parse a.join }
|
534
|
+
|
535
|
+
NonblankIndentedLine = !BlankLine IndentedLine
|
536
|
+
|
537
|
+
VerbatimChunk = BlankLine*:a
|
538
|
+
NonblankIndentedLine+:b
|
539
|
+
{ a.concat b }
|
540
|
+
|
541
|
+
Verbatim = VerbatimChunk+:a
|
542
|
+
{ RDoc::Markup::Verbatim.new(*a.flatten) }
|
543
|
+
|
544
|
+
HorizontalRule = NonindentSpace
|
545
|
+
( "*" Sp "*" Sp "*" (Sp "*")*
|
546
|
+
| "-" Sp "-" Sp "-" (Sp "-")*
|
547
|
+
| "_" Sp "_" Sp "_" (Sp "_")*)
|
548
|
+
Sp Newline BlankLine+
|
549
|
+
{ RDoc::Markup::Rule.new 1 }
|
550
|
+
|
551
|
+
Bullet = !HorizontalRule NonindentSpace ("+" | "*" | "-") Spacechar+
|
552
|
+
|
553
|
+
BulletList = &Bullet (ListTight | ListLoose):a
|
554
|
+
{ RDoc::Markup::List.new(:BULLET, *a) }
|
555
|
+
|
556
|
+
ListTight = ListItemTight+:a
|
557
|
+
BlankLine* !(Bullet | Enumerator)
|
558
|
+
{ a }
|
559
|
+
|
560
|
+
ListLoose = StartList:a
|
561
|
+
( ListItem:b BlankLine* { a << b } )+
|
562
|
+
{ a }
|
563
|
+
|
564
|
+
ListItem = ( Bullet | Enumerator )
|
565
|
+
StartList:a
|
566
|
+
ListBlock:b { a << b }
|
567
|
+
( ListContinuationBlock:c { a.push(*c) } )*
|
568
|
+
{ list_item_from a }
|
569
|
+
|
570
|
+
ListItemTight =
|
571
|
+
( Bullet | Enumerator )
|
572
|
+
ListBlock:a
|
573
|
+
( !BlankLine
|
574
|
+
ListContinuationBlock:b { a.push(*b) } )*
|
575
|
+
!ListContinuationBlock
|
576
|
+
{ list_item_from a }
|
577
|
+
|
578
|
+
ListBlock = !BlankLine Line:a
|
579
|
+
ListBlockLine*:c
|
580
|
+
{ [a, *c] }
|
581
|
+
|
582
|
+
ListContinuationBlock = StartList:a
|
583
|
+
( BlankLine*
|
584
|
+
{ a << "\n" } )
|
585
|
+
( Indent
|
586
|
+
ListBlock:b { a.concat b } )+
|
587
|
+
{ a }
|
588
|
+
|
589
|
+
Enumerator = NonindentSpace [0-9]+ "." Spacechar+
|
590
|
+
|
591
|
+
OrderedList = &Enumerator (ListTight | ListLoose):a
|
592
|
+
{ RDoc::Markup::List.new(:NUMBER, *a) }
|
593
|
+
|
594
|
+
ListBlockLine = !BlankLine
|
595
|
+
!( Indent? (Bullet | Enumerator) )
|
596
|
+
!HorizontalRule
|
597
|
+
OptionallyIndentedLine
|
598
|
+
|
599
|
+
# Parsers for different kinds of block-level HTML content.
|
600
|
+
# This is repetitive due to constraints of PEG grammar.
|
601
|
+
|
602
|
+
HtmlBlockOpenAddress = "<" Spnl ("address" | "ADDRESS") Spnl HtmlAttribute* ">"
|
603
|
+
HtmlBlockCloseAddress = "<" Spnl "/" ("address" | "ADDRESS") Spnl ">"
|
604
|
+
HtmlBlockAddress = HtmlBlockOpenAddress (HtmlBlockAddress | !HtmlBlockCloseAddress .)* HtmlBlockCloseAddress
|
605
|
+
|
606
|
+
HtmlBlockOpenBlockquote = "<" Spnl ("blockquote" | "BLOCKQUOTE") Spnl HtmlAttribute* ">"
|
607
|
+
HtmlBlockCloseBlockquote = "<" Spnl "/" ("blockquote" | "BLOCKQUOTE") Spnl ">"
|
608
|
+
HtmlBlockBlockquote = HtmlBlockOpenBlockquote (HtmlBlockBlockquote | !HtmlBlockCloseBlockquote .)* HtmlBlockCloseBlockquote
|
609
|
+
|
610
|
+
HtmlBlockOpenCenter = "<" Spnl ("center" | "CENTER") Spnl HtmlAttribute* ">"
|
611
|
+
HtmlBlockCloseCenter = "<" Spnl "/" ("center" | "CENTER") Spnl ">"
|
612
|
+
HtmlBlockCenter = HtmlBlockOpenCenter (HtmlBlockCenter | !HtmlBlockCloseCenter .)* HtmlBlockCloseCenter
|
613
|
+
|
614
|
+
HtmlBlockOpenDir = "<" Spnl ("dir" | "DIR") Spnl HtmlAttribute* ">"
|
615
|
+
HtmlBlockCloseDir = "<" Spnl "/" ("dir" | "DIR") Spnl ">"
|
616
|
+
HtmlBlockDir = HtmlBlockOpenDir (HtmlBlockDir | !HtmlBlockCloseDir .)* HtmlBlockCloseDir
|
617
|
+
|
618
|
+
HtmlBlockOpenDiv = "<" Spnl ("div" | "DIV") Spnl HtmlAttribute* ">"
|
619
|
+
HtmlBlockCloseDiv = "<" Spnl "/" ("div" | "DIV") Spnl ">"
|
620
|
+
HtmlBlockDiv = HtmlBlockOpenDiv (HtmlBlockDiv | !HtmlBlockCloseDiv .)* HtmlBlockCloseDiv
|
621
|
+
|
622
|
+
HtmlBlockOpenDl = "<" Spnl ("dl" | "DL") Spnl HtmlAttribute* ">"
|
623
|
+
HtmlBlockCloseDl = "<" Spnl "/" ("dl" | "DL") Spnl ">"
|
624
|
+
HtmlBlockDl = HtmlBlockOpenDl (HtmlBlockDl | !HtmlBlockCloseDl .)* HtmlBlockCloseDl
|
625
|
+
|
626
|
+
HtmlBlockOpenFieldset = "<" Spnl ("fieldset" | "FIELDSET") Spnl HtmlAttribute* ">"
|
627
|
+
HtmlBlockCloseFieldset = "<" Spnl "/" ("fieldset" | "FIELDSET") Spnl ">"
|
628
|
+
HtmlBlockFieldset = HtmlBlockOpenFieldset (HtmlBlockFieldset | !HtmlBlockCloseFieldset .)* HtmlBlockCloseFieldset
|
629
|
+
|
630
|
+
HtmlBlockOpenForm = "<" Spnl ("form" | "FORM") Spnl HtmlAttribute* ">"
|
631
|
+
HtmlBlockCloseForm = "<" Spnl "/" ("form" | "FORM") Spnl ">"
|
632
|
+
HtmlBlockForm = HtmlBlockOpenForm (HtmlBlockForm | !HtmlBlockCloseForm .)* HtmlBlockCloseForm
|
633
|
+
|
634
|
+
HtmlBlockOpenH1 = "<" Spnl ("h1" | "H1") Spnl HtmlAttribute* ">"
|
635
|
+
HtmlBlockCloseH1 = "<" Spnl "/" ("h1" | "H1") Spnl ">"
|
636
|
+
HtmlBlockH1 = HtmlBlockOpenH1 (HtmlBlockH1 | !HtmlBlockCloseH1 .)* HtmlBlockCloseH1
|
637
|
+
|
638
|
+
HtmlBlockOpenH2 = "<" Spnl ("h2" | "H2") Spnl HtmlAttribute* ">"
|
639
|
+
HtmlBlockCloseH2 = "<" Spnl "/" ("h2" | "H2") Spnl ">"
|
640
|
+
HtmlBlockH2 = HtmlBlockOpenH2 (HtmlBlockH2 | !HtmlBlockCloseH2 .)* HtmlBlockCloseH2
|
641
|
+
|
642
|
+
HtmlBlockOpenH3 = "<" Spnl ("h3" | "H3") Spnl HtmlAttribute* ">"
|
643
|
+
HtmlBlockCloseH3 = "<" Spnl "/" ("h3" | "H3") Spnl ">"
|
644
|
+
HtmlBlockH3 = HtmlBlockOpenH3 (HtmlBlockH3 | !HtmlBlockCloseH3 .)* HtmlBlockCloseH3
|
645
|
+
|
646
|
+
HtmlBlockOpenH4 = "<" Spnl ("h4" | "H4") Spnl HtmlAttribute* ">"
|
647
|
+
HtmlBlockCloseH4 = "<" Spnl "/" ("h4" | "H4") Spnl ">"
|
648
|
+
HtmlBlockH4 = HtmlBlockOpenH4 (HtmlBlockH4 | !HtmlBlockCloseH4 .)* HtmlBlockCloseH4
|
649
|
+
|
650
|
+
HtmlBlockOpenH5 = "<" Spnl ("h5" | "H5") Spnl HtmlAttribute* ">"
|
651
|
+
HtmlBlockCloseH5 = "<" Spnl "/" ("h5" | "H5") Spnl ">"
|
652
|
+
HtmlBlockH5 = HtmlBlockOpenH5 (HtmlBlockH5 | !HtmlBlockCloseH5 .)* HtmlBlockCloseH5
|
653
|
+
|
654
|
+
HtmlBlockOpenH6 = "<" Spnl ("h6" | "H6") Spnl HtmlAttribute* ">"
|
655
|
+
HtmlBlockCloseH6 = "<" Spnl "/" ("h6" | "H6") Spnl ">"
|
656
|
+
HtmlBlockH6 = HtmlBlockOpenH6 (HtmlBlockH6 | !HtmlBlockCloseH6 .)* HtmlBlockCloseH6
|
657
|
+
|
658
|
+
HtmlBlockOpenMenu = "<" Spnl ("menu" | "MENU") Spnl HtmlAttribute* ">"
|
659
|
+
HtmlBlockCloseMenu = "<" Spnl "/" ("menu" | "MENU") Spnl ">"
|
660
|
+
HtmlBlockMenu = HtmlBlockOpenMenu (HtmlBlockMenu | !HtmlBlockCloseMenu .)* HtmlBlockCloseMenu
|
661
|
+
|
662
|
+
HtmlBlockOpenNoframes = "<" Spnl ("noframes" | "NOFRAMES") Spnl HtmlAttribute* ">"
|
663
|
+
HtmlBlockCloseNoframes = "<" Spnl "/" ("noframes" | "NOFRAMES") Spnl ">"
|
664
|
+
HtmlBlockNoframes = HtmlBlockOpenNoframes (HtmlBlockNoframes | !HtmlBlockCloseNoframes .)* HtmlBlockCloseNoframes
|
665
|
+
|
666
|
+
HtmlBlockOpenNoscript = "<" Spnl ("noscript" | "NOSCRIPT") Spnl HtmlAttribute* ">"
|
667
|
+
HtmlBlockCloseNoscript = "<" Spnl "/" ("noscript" | "NOSCRIPT") Spnl ">"
|
668
|
+
HtmlBlockNoscript = HtmlBlockOpenNoscript (HtmlBlockNoscript | !HtmlBlockCloseNoscript .)* HtmlBlockCloseNoscript
|
669
|
+
|
670
|
+
HtmlBlockOpenOl = "<" Spnl ("ol" | "OL") Spnl HtmlAttribute* ">"
|
671
|
+
HtmlBlockCloseOl = "<" Spnl "/" ("ol" | "OL") Spnl ">"
|
672
|
+
HtmlBlockOl = HtmlBlockOpenOl (HtmlBlockOl | !HtmlBlockCloseOl .)* HtmlBlockCloseOl
|
673
|
+
|
674
|
+
HtmlBlockOpenP = "<" Spnl ("p" | "P") Spnl HtmlAttribute* ">"
|
675
|
+
HtmlBlockCloseP = "<" Spnl "/" ("p" | "P") Spnl ">"
|
676
|
+
HtmlBlockP = HtmlBlockOpenP (HtmlBlockP | !HtmlBlockCloseP .)* HtmlBlockCloseP
|
677
|
+
|
678
|
+
HtmlBlockOpenPre = "<" Spnl ("pre" | "PRE") Spnl HtmlAttribute* ">"
|
679
|
+
HtmlBlockClosePre = "<" Spnl "/" ("pre" | "PRE") Spnl ">"
|
680
|
+
HtmlBlockPre = HtmlBlockOpenPre (HtmlBlockPre | !HtmlBlockClosePre .)* HtmlBlockClosePre
|
681
|
+
|
682
|
+
HtmlBlockOpenTable = "<" Spnl ("table" | "TABLE") Spnl HtmlAttribute* ">"
|
683
|
+
HtmlBlockCloseTable = "<" Spnl "/" ("table" | "TABLE") Spnl ">"
|
684
|
+
HtmlBlockTable = HtmlBlockOpenTable (HtmlBlockTable | !HtmlBlockCloseTable .)* HtmlBlockCloseTable
|
685
|
+
|
686
|
+
HtmlBlockOpenUl = "<" Spnl ("ul" | "UL") Spnl HtmlAttribute* ">"
|
687
|
+
HtmlBlockCloseUl = "<" Spnl "/" ("ul" | "UL") Spnl ">"
|
688
|
+
HtmlBlockUl = HtmlBlockOpenUl (HtmlBlockUl | !HtmlBlockCloseUl .)* HtmlBlockCloseUl
|
689
|
+
|
690
|
+
HtmlBlockOpenDd = "<" Spnl ("dd" | "DD") Spnl HtmlAttribute* ">"
|
691
|
+
HtmlBlockCloseDd = "<" Spnl "/" ("dd" | "DD") Spnl ">"
|
692
|
+
HtmlBlockDd = HtmlBlockOpenDd (HtmlBlockDd | !HtmlBlockCloseDd .)* HtmlBlockCloseDd
|
693
|
+
|
694
|
+
HtmlBlockOpenDt = "<" Spnl ("dt" | "DT") Spnl HtmlAttribute* ">"
|
695
|
+
HtmlBlockCloseDt = "<" Spnl "/" ("dt" | "DT") Spnl ">"
|
696
|
+
HtmlBlockDt = HtmlBlockOpenDt (HtmlBlockDt | !HtmlBlockCloseDt .)* HtmlBlockCloseDt
|
697
|
+
|
698
|
+
HtmlBlockOpenFrameset = "<" Spnl ("frameset" | "FRAMESET") Spnl HtmlAttribute* ">"
|
699
|
+
HtmlBlockCloseFrameset = "<" Spnl "/" ("frameset" | "FRAMESET") Spnl ">"
|
700
|
+
HtmlBlockFrameset = HtmlBlockOpenFrameset (HtmlBlockFrameset | !HtmlBlockCloseFrameset .)* HtmlBlockCloseFrameset
|
701
|
+
|
702
|
+
HtmlBlockOpenLi = "<" Spnl ("li" | "LI") Spnl HtmlAttribute* ">"
|
703
|
+
HtmlBlockCloseLi = "<" Spnl "/" ("li" | "LI") Spnl ">"
|
704
|
+
HtmlBlockLi = HtmlBlockOpenLi (HtmlBlockLi | !HtmlBlockCloseLi .)* HtmlBlockCloseLi
|
705
|
+
|
706
|
+
HtmlBlockOpenTbody = "<" Spnl ("tbody" | "TBODY") Spnl HtmlAttribute* ">"
|
707
|
+
HtmlBlockCloseTbody = "<" Spnl "/" ("tbody" | "TBODY") Spnl ">"
|
708
|
+
HtmlBlockTbody = HtmlBlockOpenTbody (HtmlBlockTbody | !HtmlBlockCloseTbody .)* HtmlBlockCloseTbody
|
709
|
+
|
710
|
+
HtmlBlockOpenTd = "<" Spnl ("td" | "TD") Spnl HtmlAttribute* ">"
|
711
|
+
HtmlBlockCloseTd = "<" Spnl "/" ("td" | "TD") Spnl ">"
|
712
|
+
HtmlBlockTd = HtmlBlockOpenTd (HtmlBlockTd | !HtmlBlockCloseTd .)* HtmlBlockCloseTd
|
713
|
+
|
714
|
+
HtmlBlockOpenTfoot = "<" Spnl ("tfoot" | "TFOOT") Spnl HtmlAttribute* ">"
|
715
|
+
HtmlBlockCloseTfoot = "<" Spnl "/" ("tfoot" | "TFOOT") Spnl ">"
|
716
|
+
HtmlBlockTfoot = HtmlBlockOpenTfoot (HtmlBlockTfoot | !HtmlBlockCloseTfoot .)* HtmlBlockCloseTfoot
|
717
|
+
|
718
|
+
HtmlBlockOpenTh = "<" Spnl ("th" | "TH") Spnl HtmlAttribute* ">"
|
719
|
+
HtmlBlockCloseTh = "<" Spnl "/" ("th" | "TH") Spnl ">"
|
720
|
+
HtmlBlockTh = HtmlBlockOpenTh (HtmlBlockTh | !HtmlBlockCloseTh .)* HtmlBlockCloseTh
|
721
|
+
|
722
|
+
HtmlBlockOpenThead = "<" Spnl ("thead" | "THEAD") Spnl HtmlAttribute* ">"
|
723
|
+
HtmlBlockCloseThead = "<" Spnl "/" ("thead" | "THEAD") Spnl ">"
|
724
|
+
HtmlBlockThead = HtmlBlockOpenThead (HtmlBlockThead | !HtmlBlockCloseThead .)* HtmlBlockCloseThead
|
725
|
+
|
726
|
+
HtmlBlockOpenTr = "<" Spnl ("tr" | "TR") Spnl HtmlAttribute* ">"
|
727
|
+
HtmlBlockCloseTr = "<" Spnl "/" ("tr" | "TR") Spnl ">"
|
728
|
+
HtmlBlockTr = HtmlBlockOpenTr (HtmlBlockTr | !HtmlBlockCloseTr .)* HtmlBlockCloseTr
|
729
|
+
|
730
|
+
HtmlBlockOpenScript = "<" Spnl ("script" | "SCRIPT") Spnl HtmlAttribute* ">"
|
731
|
+
HtmlBlockCloseScript = "<" Spnl "/" ("script" | "SCRIPT") Spnl ">"
|
732
|
+
HtmlBlockScript = HtmlBlockOpenScript (!HtmlBlockCloseScript .)* HtmlBlockCloseScript
|
733
|
+
|
734
|
+
|
735
|
+
HtmlBlockInTags = HtmlBlockAddress
|
736
|
+
| HtmlBlockBlockquote
|
737
|
+
| HtmlBlockCenter
|
738
|
+
| HtmlBlockDir
|
739
|
+
| HtmlBlockDiv
|
740
|
+
| HtmlBlockDl
|
741
|
+
| HtmlBlockFieldset
|
742
|
+
| HtmlBlockForm
|
743
|
+
| HtmlBlockH1
|
744
|
+
| HtmlBlockH2
|
745
|
+
| HtmlBlockH3
|
746
|
+
| HtmlBlockH4
|
747
|
+
| HtmlBlockH5
|
748
|
+
| HtmlBlockH6
|
749
|
+
| HtmlBlockMenu
|
750
|
+
| HtmlBlockNoframes
|
751
|
+
| HtmlBlockNoscript
|
752
|
+
| HtmlBlockOl
|
753
|
+
| HtmlBlockP
|
754
|
+
| HtmlBlockPre
|
755
|
+
| HtmlBlockTable
|
756
|
+
| HtmlBlockUl
|
757
|
+
| HtmlBlockDd
|
758
|
+
| HtmlBlockDt
|
759
|
+
| HtmlBlockFrameset
|
760
|
+
| HtmlBlockLi
|
761
|
+
| HtmlBlockTbody
|
762
|
+
| HtmlBlockTd
|
763
|
+
| HtmlBlockTfoot
|
764
|
+
| HtmlBlockTh
|
765
|
+
| HtmlBlockThead
|
766
|
+
| HtmlBlockTr
|
767
|
+
| HtmlBlockScript
|
768
|
+
|
769
|
+
HtmlBlock = < ( HtmlBlockInTags | HtmlComment | HtmlBlockSelfClosing | HtmlUnclosed) >
|
770
|
+
BlankLine+
|
771
|
+
{ if html? then
|
772
|
+
RDoc::Markup::Raw.new text
|
773
|
+
end }
|
774
|
+
|
775
|
+
HtmlUnclosed = "<" Spnl HtmlUnclosedType Spnl HtmlAttribute* Spnl ">"
|
776
|
+
|
777
|
+
HtmlUnclosedType = "HR" | "hr"
|
778
|
+
|
779
|
+
HtmlBlockSelfClosing = "<" Spnl HtmlBlockType Spnl HtmlAttribute* "/" Spnl ">"
|
780
|
+
|
781
|
+
HtmlBlockType = "ADDRESS" |
|
782
|
+
"BLOCKQUOTE" |
|
783
|
+
"CENTER" |
|
784
|
+
"DD" |
|
785
|
+
"DIR" |
|
786
|
+
"DIV" |
|
787
|
+
"DL" |
|
788
|
+
"DT" |
|
789
|
+
"FIELDSET" |
|
790
|
+
"FORM" |
|
791
|
+
"FRAMESET" |
|
792
|
+
"H1" |
|
793
|
+
"H2" |
|
794
|
+
"H3" |
|
795
|
+
"H4" |
|
796
|
+
"H5" |
|
797
|
+
"H6" |
|
798
|
+
"HR" |
|
799
|
+
"ISINDEX" |
|
800
|
+
"LI" |
|
801
|
+
"MENU" |
|
802
|
+
"NOFRAMES" |
|
803
|
+
"NOSCRIPT" |
|
804
|
+
"OL" |
|
805
|
+
"P" |
|
806
|
+
"PRE" |
|
807
|
+
"SCRIPT" |
|
808
|
+
"TABLE" |
|
809
|
+
"TBODY" |
|
810
|
+
"TD" |
|
811
|
+
"TFOOT" |
|
812
|
+
"TH" |
|
813
|
+
"THEAD" |
|
814
|
+
"TR" |
|
815
|
+
"UL" |
|
816
|
+
"address" |
|
817
|
+
"blockquote" |
|
818
|
+
"center" |
|
819
|
+
"dd" |
|
820
|
+
"dir" |
|
821
|
+
"div" |
|
822
|
+
"dl" |
|
823
|
+
"dt" |
|
824
|
+
"fieldset" |
|
825
|
+
"form" |
|
826
|
+
"frameset" |
|
827
|
+
"h1" |
|
828
|
+
"h2" |
|
829
|
+
"h3" |
|
830
|
+
"h4" |
|
831
|
+
"h5" |
|
832
|
+
"h6" |
|
833
|
+
"hr" |
|
834
|
+
"isindex" |
|
835
|
+
"li" |
|
836
|
+
"menu" |
|
837
|
+
"noframes" |
|
838
|
+
"noscript" |
|
839
|
+
"ol" |
|
840
|
+
"p" |
|
841
|
+
"pre" |
|
842
|
+
"script" |
|
843
|
+
"table" |
|
844
|
+
"tbody" |
|
845
|
+
"td" |
|
846
|
+
"tfoot" |
|
847
|
+
"th" |
|
848
|
+
"thead" |
|
849
|
+
"tr" |
|
850
|
+
"ul"
|
851
|
+
|
852
|
+
StyleOpen = "<" Spnl ("style" | "STYLE") Spnl HtmlAttribute* ">"
|
853
|
+
StyleClose = "<" Spnl "/" ("style" | "STYLE") Spnl ">"
|
854
|
+
InStyleTags = StyleOpen (!StyleClose .)* StyleClose
|
855
|
+
StyleBlock = < InStyleTags >
|
856
|
+
BlankLine*
|
857
|
+
{ if css? then
|
858
|
+
RDoc::Markup::Raw.new text
|
859
|
+
end }
|
860
|
+
|
861
|
+
Inlines = ( !Endline Inline:i { i }
|
862
|
+
| Endline:c &Inline { c } )+:chunks Endline?
|
863
|
+
{ chunks }
|
864
|
+
|
865
|
+
Inline = Str
|
866
|
+
| Endline
|
867
|
+
| UlOrStarLine
|
868
|
+
| Space
|
869
|
+
| Strong
|
870
|
+
| Emph
|
871
|
+
| Image
|
872
|
+
| Link
|
873
|
+
| NoteReference
|
874
|
+
| InlineNote
|
875
|
+
| Code
|
876
|
+
| RawHtml
|
877
|
+
| Entity
|
878
|
+
| EscapedChar
|
879
|
+
| Symbol
|
880
|
+
|
881
|
+
Space = Spacechar+ { " " }
|
882
|
+
|
883
|
+
Str = StartList:a
|
884
|
+
< NormalChar+ > { a = text }
|
885
|
+
( StrChunk:c { a << c } )* { a }
|
886
|
+
|
887
|
+
StrChunk = < (NormalChar | "_"+ &Alphanumeric)+ > { text }
|
888
|
+
|
889
|
+
EscapedChar = "\\" !Newline < /[:\\`|*_{}\[\]()#+.!><-]/ > { text }
|
890
|
+
|
891
|
+
Entity = ( HexEntity | DecEntity | CharEntity ):a { a }
|
892
|
+
|
893
|
+
Endline = LineBreak | TerminalEndline | NormalEndline
|
894
|
+
|
895
|
+
NormalEndline = Sp Newline !BlankLine !">" !AtxStart
|
896
|
+
!(Line ("===" "="* | "---" "-"*) Newline)
|
897
|
+
{ "\n" }
|
898
|
+
|
899
|
+
TerminalEndline = Sp Newline Eof
|
900
|
+
|
901
|
+
LineBreak = " " NormalEndline { RDoc::Markup::HardBreak.new }
|
902
|
+
|
903
|
+
Symbol = < SpecialChar >
|
904
|
+
{ text }
|
905
|
+
|
906
|
+
# This keeps the parser from getting bogged down on long strings of '*' or '_',
|
907
|
+
# or strings of '*' or '_' with space on each side:
|
908
|
+
UlOrStarLine = (UlLine | StarLine):a { a }
|
909
|
+
StarLine = < "****" "*"* > { text } |
|
910
|
+
< Spacechar "*"+ &Spacechar > { text }
|
911
|
+
UlLine = < "____" "_"* > { text } |
|
912
|
+
< Spacechar "_"+ &Spacechar > { text }
|
913
|
+
|
914
|
+
Emph = EmphStar | EmphUl
|
915
|
+
|
916
|
+
OneStarOpen = !StarLine "*" !Spacechar !Newline
|
917
|
+
OneStarClose = !Spacechar !Newline Inline:a "*"
|
918
|
+
{ a }
|
919
|
+
|
920
|
+
EmphStar = OneStarOpen
|
921
|
+
StartList:a
|
922
|
+
( !OneStarClose Inline:l { a << l } )*
|
923
|
+
OneStarClose:l { a << l }
|
924
|
+
{ emphasis a.join }
|
925
|
+
|
926
|
+
OneUlOpen = !UlLine "_" !Spacechar !Newline
|
927
|
+
OneUlClose = !Spacechar !Newline Inline:a "_" # !Alphanumeric # TODO check
|
928
|
+
{ a }
|
929
|
+
|
930
|
+
EmphUl = OneUlOpen
|
931
|
+
StartList:a
|
932
|
+
( !OneUlClose Inline:l { a << l } )*
|
933
|
+
OneUlClose:l { a << l }
|
934
|
+
{ emphasis a.join }
|
935
|
+
|
936
|
+
Strong = StrongStar | StrongUl
|
937
|
+
|
938
|
+
TwoStarOpen = !StarLine "**" !Spacechar !Newline
|
939
|
+
TwoStarClose = !Spacechar !Newline Inline:a "**" { a }
|
940
|
+
|
941
|
+
StrongStar = TwoStarOpen
|
942
|
+
StartList:a
|
943
|
+
( !TwoStarClose Inline:l { a << l } )*
|
944
|
+
TwoStarClose:l { a << l }
|
945
|
+
{ strong a.join }
|
946
|
+
|
947
|
+
TwoUlOpen = !UlLine "__" !Spacechar !Newline
|
948
|
+
TwoUlClose = !Spacechar !Newline Inline:a "__" # !Alphanumeric # TODO check
|
949
|
+
{ a }
|
950
|
+
|
951
|
+
StrongUl = TwoUlOpen
|
952
|
+
StartList:a
|
953
|
+
( !TwoUlClose Inline:i { a << i } )*
|
954
|
+
TwoUlClose:l { a << l }
|
955
|
+
{ strong a.join }
|
956
|
+
|
957
|
+
# TODO image link support
|
958
|
+
Image = "!" ( ExplicitLink | ReferenceLink ):a
|
959
|
+
{ a }
|
960
|
+
|
961
|
+
Link = ExplicitLink | ReferenceLink | AutoLink
|
962
|
+
|
963
|
+
ReferenceLink = ReferenceLinkDouble | ReferenceLinkSingle
|
964
|
+
|
965
|
+
ReferenceLinkDouble = Label:content < Spnl > !"[]" Label:label
|
966
|
+
{ link_to content, label, text }
|
967
|
+
|
968
|
+
ReferenceLinkSingle = Label:content < (Spnl "[]")? >
|
969
|
+
{ link_to content, content, text }
|
970
|
+
|
971
|
+
ExplicitLink = Label:l Spnl "(" Sp Source:s Spnl Title Sp ")"
|
972
|
+
{ "{#{l}}[#{s}]" }
|
973
|
+
|
974
|
+
Source = ( "<" < SourceContents > ">" | < SourceContents > )
|
975
|
+
{ text }
|
976
|
+
|
977
|
+
SourceContents = ( ( !"(" !")" !">" Nonspacechar )+ | "(" SourceContents ")")*
|
978
|
+
| ""
|
979
|
+
|
980
|
+
Title = ( TitleSingle | TitleDouble | "" ):a
|
981
|
+
{ a }
|
982
|
+
|
983
|
+
TitleSingle = "'" ( !( "'" Sp ( ")" | Newline ) ) . )* "'"
|
984
|
+
|
985
|
+
TitleDouble = "\"" ( !( "\"" Sp ( ")" | Newline ) ) . )* "\""
|
986
|
+
|
987
|
+
AutoLink = AutoLinkUrl | AutoLinkEmail
|
988
|
+
|
989
|
+
AutoLinkUrl = "<" < /[A-Za-z]+/ "://" ( !Newline !">" . )+ > ">"
|
990
|
+
{ text }
|
991
|
+
|
992
|
+
AutoLinkEmail = "<" ("mailto:")? < /[\w+.\/!%~$-]+/i "@" ( !Newline !">" . )+ > ">"
|
993
|
+
{ "mailto:#{text}" }
|
994
|
+
|
995
|
+
Reference = NonindentSpace !"[]"
|
996
|
+
Label:label ":" Spnl RefSrc:link RefTitle BlankLine+
|
997
|
+
{ # TODO use title
|
998
|
+
reference label, link
|
999
|
+
nil
|
1000
|
+
}
|
1001
|
+
|
1002
|
+
Label = "[" ( !"^" &{ notes? } | &. &{ !notes? } )
|
1003
|
+
StartList:a
|
1004
|
+
( !"]" Inline:l { a << l } )*
|
1005
|
+
"]"
|
1006
|
+
{ a.join.gsub(/\s+/, ' ') }
|
1007
|
+
|
1008
|
+
RefSrc = < Nonspacechar+ > { text }
|
1009
|
+
|
1010
|
+
RefTitle = ( RefTitleSingle | RefTitleDouble | RefTitleParens | EmptyTitle )
|
1011
|
+
|
1012
|
+
EmptyTitle = ""
|
1013
|
+
|
1014
|
+
RefTitleSingle = Spnl "'" < ( !( "'" Sp Newline | Newline ) . )* > "'" { text }
|
1015
|
+
|
1016
|
+
RefTitleDouble = Spnl "\"" < ( !("\"" Sp Newline | Newline) . )* > "\"" { text }
|
1017
|
+
|
1018
|
+
RefTitleParens = Spnl "(" < ( !(")" Sp Newline | Newline) . )* > ")" { text }
|
1019
|
+
|
1020
|
+
References = ( Reference | SkipBlock )*
|
1021
|
+
|
1022
|
+
Ticks1 = "`" !"`"
|
1023
|
+
Ticks2 = "``" !"`"
|
1024
|
+
Ticks3 = "```" !"`"
|
1025
|
+
Ticks4 = "````" !"`"
|
1026
|
+
Ticks5 = "`````" !"`"
|
1027
|
+
|
1028
|
+
Code = ( Ticks1 Sp < (
|
1029
|
+
( !"`" Nonspacechar )+ | !Ticks1 "`"+ |
|
1030
|
+
!( Sp Ticks1 ) ( Spacechar | Newline !BlankLine )
|
1031
|
+
)+ > Sp Ticks1 |
|
1032
|
+
Ticks2 Sp < (
|
1033
|
+
( !"`" Nonspacechar )+ |
|
1034
|
+
!Ticks2 "`"+ |
|
1035
|
+
!( Sp Ticks2 ) ( Spacechar | Newline !BlankLine )
|
1036
|
+
)+ > Sp Ticks2 |
|
1037
|
+
Ticks3 Sp < (
|
1038
|
+
( !"`" Nonspacechar )+ |
|
1039
|
+
!Ticks3 "`"+ |
|
1040
|
+
!( Sp Ticks3 ) ( Spacechar | Newline !BlankLine )
|
1041
|
+
)+ > Sp Ticks3 |
|
1042
|
+
Ticks4 Sp < (
|
1043
|
+
( !"`" Nonspacechar )+ |
|
1044
|
+
!Ticks4 "`"+ |
|
1045
|
+
!( Sp Ticks4 ) ( Spacechar | Newline !BlankLine )
|
1046
|
+
)+ > Sp Ticks4 |
|
1047
|
+
Ticks5 Sp < (
|
1048
|
+
( !"`" Nonspacechar )+ |
|
1049
|
+
!Ticks5 "`"+ |
|
1050
|
+
!( Sp Ticks5 ) ( Spacechar | Newline !BlankLine )
|
1051
|
+
)+ > Sp Ticks5
|
1052
|
+
)
|
1053
|
+
{ "<code>#{text}</code>" }
|
1054
|
+
|
1055
|
+
RawHtml = < (HtmlComment | HtmlBlockScript | HtmlTag) >
|
1056
|
+
{ if html? then text else '' end }
|
1057
|
+
|
1058
|
+
BlankLine = Sp Newline { "\n" }
|
1059
|
+
|
1060
|
+
Quoted = "\"" (!"\"" .)* "\"" | "'" (!"'" .)* "'"
|
1061
|
+
HtmlAttribute = (AlphanumericAscii | "-")+ Spnl ("=" Spnl (Quoted | (!">" Nonspacechar)+))? Spnl
|
1062
|
+
HtmlComment = "<!--" (!"-->" .)* "-->"
|
1063
|
+
HtmlTag = "<" Spnl "/"? AlphanumericAscii+ Spnl HtmlAttribute* "/"? Spnl ">"
|
1064
|
+
Eof = !.
|
1065
|
+
Nonspacechar = !Spacechar !Newline .
|
1066
|
+
Sp = Spacechar*
|
1067
|
+
Spnl = Sp (Newline Sp)?
|
1068
|
+
SpecialChar = "*" | "_" | "`" | "&" | "[" | "]" | "(" | ")" | "<" | "!" | "#" | "\\" | "'" | "\"" | ExtendedSpecialChar
|
1069
|
+
NormalChar = !( SpecialChar | Spacechar | Newline ) .
|
1070
|
+
Digit = [0-9]
|
1071
|
+
|
1072
|
+
%literals = RDoc::Markdown::Literals
|
1073
|
+
Alphanumeric = %literals.Alphanumeric
|
1074
|
+
AlphanumericAscii = %literals.AlphanumericAscii
|
1075
|
+
BOM = %literals.BOM
|
1076
|
+
Newline = %literals.Newline
|
1077
|
+
NonAlphanumeric = %literals.NonAlphanumeric
|
1078
|
+
Spacechar = %literals.Spacechar
|
1079
|
+
|
1080
|
+
HexEntity = "&" "#" /[Xx]/ < /[0-9a-fA-F]+/ > ";"
|
1081
|
+
{ [text.to_i(16)].pack 'U' }
|
1082
|
+
DecEntity = "&" "#" < /[0-9]+/ > ";"
|
1083
|
+
{ [text.to_i].pack 'U' }
|
1084
|
+
CharEntity = "&" </[A-Za-z0-9]+/ > ";"
|
1085
|
+
{ if entity = HTML_ENTITIES[text] then
|
1086
|
+
entity.pack 'U*'
|
1087
|
+
else
|
1088
|
+
"&#{text};"
|
1089
|
+
end
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
NonindentSpace = " " | " " | " " | ""
|
1093
|
+
Indent = "\t" | " "
|
1094
|
+
IndentedLine = Indent Line
|
1095
|
+
OptionallyIndentedLine = Indent? Line
|
1096
|
+
|
1097
|
+
# StartList starts a list data structure that can be added to with cons:
|
1098
|
+
StartList = &.
|
1099
|
+
{ [] }
|
1100
|
+
|
1101
|
+
Line = RawLine:a { a }
|
1102
|
+
RawLine = ( < (!"\r" !"\n" .)* Newline >
|
1103
|
+
| < .+ > Eof ) { text }
|
1104
|
+
|
1105
|
+
SkipBlock = HtmlBlock
|
1106
|
+
| ( !"#" !SetextBottom1 !SetextBottom2 !BlankLine RawLine )+
|
1107
|
+
BlankLine*
|
1108
|
+
| BlankLine+
|
1109
|
+
| RawLine
|
1110
|
+
|
1111
|
+
# Syntax extensions
|
1112
|
+
|
1113
|
+
ExtendedSpecialChar = &{ notes? } ( "^" )
|
1114
|
+
|
1115
|
+
NoteReference = &{ notes? }
|
1116
|
+
RawNoteReference:ref
|
1117
|
+
{ note_for ref }
|
1118
|
+
|
1119
|
+
RawNoteReference = "[^" < ( !Newline !"]" . )+ > "]" { text }
|
1120
|
+
|
1121
|
+
# TODO multiple paragraphs for a footnote
|
1122
|
+
Note = &{ notes? }
|
1123
|
+
NonindentSpace RawNoteReference:ref ":" Sp
|
1124
|
+
StartList:a
|
1125
|
+
RawNoteBlock
|
1126
|
+
( &Indent RawNoteBlock:i { a.concat i } )*
|
1127
|
+
{ @footnotes[ref] = paragraph a
|
1128
|
+
|
1129
|
+
nil
|
1130
|
+
}
|
1131
|
+
|
1132
|
+
InlineNote = &{ notes? }
|
1133
|
+
"^["
|
1134
|
+
StartList:a
|
1135
|
+
( !"]" Inline:l { a << l } )+
|
1136
|
+
"]"
|
1137
|
+
{
|
1138
|
+
ref = [:inline, @note_order.length]
|
1139
|
+
@footnotes[ref] = paragraph a
|
1140
|
+
|
1141
|
+
note_for ref
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
Notes = ( Note | SkipBlock )*
|
1145
|
+
|
1146
|
+
RawNoteBlock = StartList:a
|
1147
|
+
( !BlankLine OptionallyIndentedLine:l { a << l } )+
|
1148
|
+
( < BlankLine* > { a << text } )
|
1149
|
+
{ a }
|
1150
|
+
|
1151
|
+
# Markdown extensions added by RDoc follow
|
1152
|
+
|
1153
|
+
CodeFence = &{ github? }
|
1154
|
+
Ticks3 (Sp StrChunk:format)? Spnl < (
|
1155
|
+
( !"`" Nonspacechar )+ |
|
1156
|
+
!Ticks3 "`"+ |
|
1157
|
+
Spacechar |
|
1158
|
+
Newline
|
1159
|
+
)+ > Ticks3 Sp Newline*
|
1160
|
+
{ verbatim = RDoc::Markup::Verbatim.new text
|
1161
|
+
verbatim.format = format.intern if format
|
1162
|
+
verbatim
|
1163
|
+
}
|
1164
|
+
|
1165
|
+
DefinitionList = &{ definition_lists? }
|
1166
|
+
( DefinitionListItem+:list )
|
1167
|
+
{ RDoc::Markup::List.new :NOTE, *list.flatten }
|
1168
|
+
|
1169
|
+
DefinitionListItem = ( DefinitionListLabel+ ):label
|
1170
|
+
( DefinitionListDefinition+ ):defns
|
1171
|
+
{ list_items = []
|
1172
|
+
list_items <<
|
1173
|
+
RDoc::Markup::ListItem.new(label, defns.shift)
|
1174
|
+
|
1175
|
+
list_items.concat defns.map { |defn|
|
1176
|
+
RDoc::Markup::ListItem.new nil, defn
|
1177
|
+
} unless list_items.empty?
|
1178
|
+
|
1179
|
+
list_items
|
1180
|
+
}
|
1181
|
+
|
1182
|
+
DefinitionListLabel = StrChunk:label Sp Newline
|
1183
|
+
{ label }
|
1184
|
+
|
1185
|
+
DefinitionListDefinition = NonindentSpace ":" Space Inlines:a BlankLine+
|
1186
|
+
{ paragraph a }
|