bean-kramdown 0.13.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/AUTHORS +1 -0
- data/CONTRIBUTERS +11 -0
- data/COPYING +24 -0
- data/ChangeLog +6683 -0
- data/GPL +674 -0
- data/README +43 -0
- data/VERSION +1 -0
- data/bin/kramdown +78 -0
- data/lib/kramdown.rb +23 -0
- data/lib/kramdown/compatibility.rb +49 -0
- data/lib/kramdown/converter.rb +41 -0
- data/lib/kramdown/converter/base.rb +169 -0
- data/lib/kramdown/converter/bean_html.rb +71 -0
- data/lib/kramdown/converter/html.rb +411 -0
- data/lib/kramdown/converter/kramdown.rb +428 -0
- data/lib/kramdown/converter/latex.rb +607 -0
- data/lib/kramdown/converter/toc.rb +82 -0
- data/lib/kramdown/document.rb +119 -0
- data/lib/kramdown/element.rb +524 -0
- data/lib/kramdown/error.rb +30 -0
- data/lib/kramdown/options.rb +373 -0
- data/lib/kramdown/parser.rb +39 -0
- data/lib/kramdown/parser/base.rb +136 -0
- data/lib/kramdown/parser/bean_kramdown.rb +25 -0
- data/lib/kramdown/parser/bean_kramdown/info_box.rb +52 -0
- data/lib/kramdown/parser/bean_kramdown/oembed.rb +230 -0
- data/lib/kramdown/parser/html.rb +570 -0
- data/lib/kramdown/parser/kramdown.rb +339 -0
- data/lib/kramdown/parser/kramdown/abbreviation.rb +71 -0
- data/lib/kramdown/parser/kramdown/autolink.rb +53 -0
- data/lib/kramdown/parser/kramdown/blank_line.rb +43 -0
- data/lib/kramdown/parser/kramdown/block_boundary.rb +46 -0
- data/lib/kramdown/parser/kramdown/blockquote.rb +51 -0
- data/lib/kramdown/parser/kramdown/codeblock.rb +63 -0
- data/lib/kramdown/parser/kramdown/codespan.rb +56 -0
- data/lib/kramdown/parser/kramdown/emphasis.rb +70 -0
- data/lib/kramdown/parser/kramdown/eob.rb +39 -0
- data/lib/kramdown/parser/kramdown/escaped_chars.rb +38 -0
- data/lib/kramdown/parser/kramdown/extensions.rb +204 -0
- data/lib/kramdown/parser/kramdown/footnote.rb +74 -0
- data/lib/kramdown/parser/kramdown/header.rb +68 -0
- data/lib/kramdown/parser/kramdown/horizontal_rule.rb +39 -0
- data/lib/kramdown/parser/kramdown/html.rb +169 -0
- data/lib/kramdown/parser/kramdown/html_entity.rb +44 -0
- data/lib/kramdown/parser/kramdown/image.rb +157 -0
- data/lib/kramdown/parser/kramdown/line_break.rb +38 -0
- data/lib/kramdown/parser/kramdown/link.rb +154 -0
- data/lib/kramdown/parser/kramdown/list.rb +240 -0
- data/lib/kramdown/parser/kramdown/math.rb +65 -0
- data/lib/kramdown/parser/kramdown/paragraph.rb +63 -0
- data/lib/kramdown/parser/kramdown/smart_quotes.rb +214 -0
- data/lib/kramdown/parser/kramdown/table.rb +178 -0
- data/lib/kramdown/parser/kramdown/typographic_symbol.rb +52 -0
- data/lib/kramdown/parser/markdown.rb +69 -0
- data/lib/kramdown/utils.rb +42 -0
- data/lib/kramdown/utils/entities.rb +348 -0
- data/lib/kramdown/utils/html.rb +85 -0
- data/lib/kramdown/utils/ordered_hash.rb +100 -0
- data/lib/kramdown/version.rb +28 -0
- metadata +140 -0
data/README
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
= kramdown
|
2
|
+
|
3
|
+
kramdown is yet-another-markdown-parser but fast, pure Ruby, using a strict syntax definition and
|
4
|
+
supporting several common extensions. The syntax definition for the kramdown syntax can be found in
|
5
|
+
doc/syntax.page and a quick reference is available in doc/quickref.page.
|
6
|
+
|
7
|
+
The kramdown library is mainly written to support the kramdown-to-HTML conversion chain. However,
|
8
|
+
due to its flexibility it supports other input and output formats as well. Here is a list of the
|
9
|
+
supported formats:
|
10
|
+
|
11
|
+
* input formats: kramdown (a Markdown superset), Markdown, HTML
|
12
|
+
* output formats: HTML, kramdown, LaTeX (and therefore PDF)
|
13
|
+
|
14
|
+
All the documentation on the available input and output formats is available in the doc/ directory
|
15
|
+
and online at http://kramdown.rubyforge.org.
|
16
|
+
|
17
|
+
|
18
|
+
== Usage
|
19
|
+
|
20
|
+
kramdown has a basic *Cloth API, so using kramdown is as easy as
|
21
|
+
|
22
|
+
require 'kramdown'
|
23
|
+
|
24
|
+
Kramdown::Document.new(text).to_html
|
25
|
+
|
26
|
+
For detailed information have a look at the API documentation of the Kramdown::Document class.
|
27
|
+
|
28
|
+
The full API documentation is available at http://kramdown.rubyforge.org/rdoc/, other sites with an
|
29
|
+
API documentation for kramdown probably don't provide the complete documentation!
|
30
|
+
|
31
|
+
|
32
|
+
== Development
|
33
|
+
|
34
|
+
Just clone the git repository as described in doc/installation.page and you are good to go. You
|
35
|
+
probably want to install `rake` so that you can use the provided rake tasks. Aside from that:
|
36
|
+
|
37
|
+
* The +tidy+ binary needs to be installed for the automatically derived tests to work.
|
38
|
+
* The +latex+ binary needs to be installed for the latex-compilation tests to work.
|
39
|
+
|
40
|
+
|
41
|
+
== License
|
42
|
+
|
43
|
+
GPLv3 - see the COPYING file.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.13.7
|
data/bin/kramdown
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#! /Users/vincent/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
#--
|
5
|
+
# Copyright (C) 2009-2012 Thomas Leitner <t_leitner@gmx.at>
|
6
|
+
#
|
7
|
+
# This file is part of kramdown.
|
8
|
+
#
|
9
|
+
# kramdown is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# This program is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'optparse'
|
25
|
+
require 'kramdown'
|
26
|
+
|
27
|
+
options = {}
|
28
|
+
format = 'html'
|
29
|
+
OptionParser.new do |opts|
|
30
|
+
opts.banner = "Usage: kramdown [options] [FILE FILE ...]"
|
31
|
+
opts.summary_indent = ' '*4
|
32
|
+
|
33
|
+
opts.separator ""
|
34
|
+
opts.separator "Command line options:"
|
35
|
+
opts.separator ""
|
36
|
+
|
37
|
+
opts.on("-i", "--input ARG", "Specify the input format: kramdown (default) or html") {|v| options[:input] = v}
|
38
|
+
opts.on("-o", "--output ARG", "Specify the output format: html (default), kramdown or latex") {|v| format = v}
|
39
|
+
|
40
|
+
opts.on("-v", "--version", "Show the version of kramdown") do
|
41
|
+
puts Kramdown::VERSION
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
opts.on("-h", "--help", "Show the help") do
|
45
|
+
puts opts.summarize('', 5, 72)
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.separator ""
|
50
|
+
opts.separator "kramdown options:"
|
51
|
+
opts.separator ""
|
52
|
+
|
53
|
+
Kramdown::Options.definitions.each do |n, definition|
|
54
|
+
no = n.to_s.tr('_', '-')
|
55
|
+
if definition.type == Kramdown::Options::Boolean
|
56
|
+
opts.on("--[no-]#{no}") {|v| options[n] = Kramdown::Options.parse(n, v)}
|
57
|
+
else
|
58
|
+
type = definition.type
|
59
|
+
type = String if type == Symbol || type == Object
|
60
|
+
opts.on("--#{no} ARG", type) {|v| options[n] = Kramdown::Options.parse(n, v)}
|
61
|
+
end
|
62
|
+
|
63
|
+
definition.desc.split(/\n/).each do |line|
|
64
|
+
opts.separator opts.summary_indent + ' '*6 + line
|
65
|
+
end
|
66
|
+
opts.separator ''
|
67
|
+
end
|
68
|
+
|
69
|
+
end.parse!
|
70
|
+
|
71
|
+
begin
|
72
|
+
doc = Kramdown::Document.new(ARGF.read, options)
|
73
|
+
puts doc.send("to_#{format}")
|
74
|
+
doc.warnings.each {|warn| $stderr.puts "Warning: #{warn}"}
|
75
|
+
rescue Kramdown::Error => e
|
76
|
+
$stderr.puts "Error: #{e.message}"
|
77
|
+
exit(1)
|
78
|
+
end
|
data/lib/kramdown.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2012 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'kramdown/document'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2012 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
# All the code in this file is backported from Ruby 1.8.7 sothat kramdown works under 1.8.5
|
23
|
+
#
|
24
|
+
# :stopdoc:
|
25
|
+
|
26
|
+
if RUBY_VERSION <= '1.8.6'
|
27
|
+
require 'rexml/parsers/baseparser'
|
28
|
+
module REXML
|
29
|
+
module Parsers
|
30
|
+
class BaseParser
|
31
|
+
UNAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}" unless const_defined?(:UNAME_STR)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if !String.instance_methods.include?("start_with?")
|
37
|
+
|
38
|
+
class String
|
39
|
+
def start_with?(str)
|
40
|
+
self[0, str.length] == str
|
41
|
+
end
|
42
|
+
def end_with?(str)
|
43
|
+
self[-str.length, str.length] == str
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2012 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
module Kramdown
|
24
|
+
|
25
|
+
# This module contains all available converters, i.e. classes that take a root Element and convert
|
26
|
+
# it to a specific output format. The result is normally a string. For example, the
|
27
|
+
# Converter::Html module converts an element tree into valid HTML.
|
28
|
+
#
|
29
|
+
# Converters use the Base class for common functionality (like applying a template to the output)
|
30
|
+
# \- see its API documentation for how to create a custom converter class.
|
31
|
+
module Converter
|
32
|
+
|
33
|
+
autoload :Base, 'kramdown/converter/base'
|
34
|
+
autoload :Html, 'kramdown/converter/html'
|
35
|
+
autoload :Latex, 'kramdown/converter/latex'
|
36
|
+
autoload :Kramdown, 'kramdown/converter/kramdown'
|
37
|
+
autoload :Toc, 'kramdown/converter/toc'
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2009-2012 Thomas Leitner <t_leitner@gmx.at>
|
5
|
+
#
|
6
|
+
# This file is part of kramdown.
|
7
|
+
#
|
8
|
+
# kramdown is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#++
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'erb'
|
24
|
+
|
25
|
+
module Kramdown
|
26
|
+
|
27
|
+
module Converter
|
28
|
+
|
29
|
+
# == \Base class for converters
|
30
|
+
#
|
31
|
+
# This class serves as base class for all converters. It provides methods that can/should be
|
32
|
+
# used by all converters (like #generate_id) as well as common functionality that is
|
33
|
+
# automatically applied to the result (for example, embedding the output into a template).
|
34
|
+
#
|
35
|
+
# A converter object is used as a throw-away object, i.e. it is only used for storing the needed
|
36
|
+
# state information during conversion. Therefore one can't instantiate a converter object
|
37
|
+
# directly but only use the Base::convert method.
|
38
|
+
#
|
39
|
+
# == Implementing a converter
|
40
|
+
#
|
41
|
+
# Implementing a new converter is rather easy: just derive a new class from this class and put
|
42
|
+
# it in the Kramdown::Converter module (the latter is only needed if auto-detection should work
|
43
|
+
# properly). Then you need to implement the #convert method which has to contain the conversion
|
44
|
+
# code for converting an element and has to return the conversion result.
|
45
|
+
#
|
46
|
+
# The actual transformation of the document tree can be done in any way. However, writing one
|
47
|
+
# method per element type is a straight forward way to do it - this is how the Html and Latex
|
48
|
+
# converters do the transformation.
|
49
|
+
#
|
50
|
+
# Have a look at the Base::convert method for additional information!
|
51
|
+
class Base
|
52
|
+
|
53
|
+
# Can be used by a converter for storing arbitrary information during the conversion process.
|
54
|
+
attr_reader :data
|
55
|
+
|
56
|
+
# The hash with the conversion options.
|
57
|
+
attr_reader :options
|
58
|
+
|
59
|
+
# The root element that is converted.
|
60
|
+
attr_reader :root
|
61
|
+
|
62
|
+
# The warnings array.
|
63
|
+
attr_reader :warnings
|
64
|
+
|
65
|
+
# Initialize the converter with the given +root+ element and +options+ hash.
|
66
|
+
def initialize(root, options)
|
67
|
+
@options = options
|
68
|
+
@root = root
|
69
|
+
@data = {}
|
70
|
+
@warnings = []
|
71
|
+
end
|
72
|
+
private_class_method(:new, :allocate)
|
73
|
+
|
74
|
+
# Convert the element tree +tree+ and return the resulting conversion object (normally a
|
75
|
+
# string) and an array with warning messages. The parameter +options+ specifies the conversion
|
76
|
+
# options that should be used.
|
77
|
+
#
|
78
|
+
# Initializes a new instance of the calling class and then calls the #convert method with
|
79
|
+
# +tree+ as parameter. If the +template+ option is specified and non-empty, the result is
|
80
|
+
# rendered into the specified template. The template resolution is done in the following way:
|
81
|
+
#
|
82
|
+
# 1. Look in the current working directory for the template.
|
83
|
+
#
|
84
|
+
# 2. Append +.convertername+ (e.g. +.html+) to the template name and look for the resulting
|
85
|
+
# file in the current working directory.
|
86
|
+
#
|
87
|
+
# 3. Append +.convertername+ to the template name and look for it in the kramdown data
|
88
|
+
# directory.
|
89
|
+
def self.convert(tree, options = {})
|
90
|
+
converter = new(tree, ::Kramdown::Options.merge(options.merge(tree.options[:options] || {})))
|
91
|
+
result = converter.convert(tree)
|
92
|
+
result = apply_template(converter, result) if !converter.options[:template].empty?
|
93
|
+
[result, converter.warnings]
|
94
|
+
end
|
95
|
+
|
96
|
+
# Convert the element +el+ and return the resulting object.
|
97
|
+
#
|
98
|
+
# This is the only method that has to be implemented by sub-classes!
|
99
|
+
def convert(el)
|
100
|
+
raise NotImplementedError
|
101
|
+
end
|
102
|
+
|
103
|
+
# Apply the +template+ using +body+ as the body string.
|
104
|
+
def self.apply_template(converter, body) # :nodoc:
|
105
|
+
erb = ERB.new(get_template(converter.options[:template]))
|
106
|
+
obj = Object.new
|
107
|
+
obj.instance_variable_set(:@converter, converter)
|
108
|
+
obj.instance_variable_set(:@body, body)
|
109
|
+
erb.result(obj.instance_eval{binding})
|
110
|
+
end
|
111
|
+
|
112
|
+
# Return the template specified by +template+.
|
113
|
+
def self.get_template(template) # :nodoc:
|
114
|
+
format_ext = '.' + self.name.split(/::/).last.downcase
|
115
|
+
shipped = File.join(::Kramdown.data_dir, template + format_ext)
|
116
|
+
if File.exist?(template)
|
117
|
+
File.read(template)
|
118
|
+
elsif File.exist?(template + format_ext)
|
119
|
+
File.read(template + format_ext)
|
120
|
+
elsif File.exist?(shipped)
|
121
|
+
File.read(shipped)
|
122
|
+
else
|
123
|
+
raise "The specified template file #{template} does not exist"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Add the given warning +text+ to the warning array.
|
128
|
+
def warning(text)
|
129
|
+
@warnings << text
|
130
|
+
end
|
131
|
+
|
132
|
+
# Return +true+ if the header element +el+ should be used for the table of contents (as
|
133
|
+
# specified by the +toc_levels+ option).
|
134
|
+
def in_toc?(el)
|
135
|
+
@options[:toc_levels].include?(el.options[:level])
|
136
|
+
end
|
137
|
+
|
138
|
+
# Generate an unique alpha-numeric ID from the the string +str+ for use as a header ID.
|
139
|
+
#
|
140
|
+
# Uses the option +auto_id_prefix+: the value of this option is prepended to every generated
|
141
|
+
# ID.
|
142
|
+
def generate_id(str)
|
143
|
+
gen_id = str.gsub(/^[^a-zA-Z]+/, '')
|
144
|
+
gen_id.tr!('^a-zA-Z0-9 -', '')
|
145
|
+
gen_id.tr!(' ', '-')
|
146
|
+
gen_id.downcase!
|
147
|
+
gen_id = 'section' if gen_id.length == 0
|
148
|
+
@used_ids ||= {}
|
149
|
+
if @used_ids.has_key?(gen_id)
|
150
|
+
gen_id += '-' << (@used_ids[gen_id] += 1).to_s
|
151
|
+
else
|
152
|
+
@used_ids[gen_id] = 0
|
153
|
+
end
|
154
|
+
@options[:auto_id_prefix] + gen_id
|
155
|
+
end
|
156
|
+
|
157
|
+
SMART_QUOTE_INDICES = {:lsquo => 0, :rsquo => 1, :ldquo => 2, :rdquo => 3} # :nodoc:
|
158
|
+
|
159
|
+
# Return the entity that represents the given smart_quote element.
|
160
|
+
def smart_quote_entity(el)
|
161
|
+
res = @options[:smart_quotes][SMART_QUOTE_INDICES[el.value]]
|
162
|
+
::Kramdown::Utils::Entities.entity(res)
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rexml/parsers/baseparser'
|
2
|
+
|
3
|
+
module Kramdown
|
4
|
+
|
5
|
+
module Converter
|
6
|
+
|
7
|
+
# Converts a Kramdown::Document to HTML.
|
8
|
+
#
|
9
|
+
# You can customize the HTML converter by sub-classing it and overriding the +convert_NAME+
|
10
|
+
# methods. Each such method takes the following parameters:
|
11
|
+
#
|
12
|
+
# [+el+] The element of type +NAME+ to be converted.
|
13
|
+
#
|
14
|
+
# [+indent+] A number representing the current amount of spaces for indent (only used for
|
15
|
+
# block-level elements).
|
16
|
+
#
|
17
|
+
# The return value of such a method has to be a string containing the element +el+ formatted as
|
18
|
+
# HTML element.
|
19
|
+
class Html < Base
|
20
|
+
|
21
|
+
def convert_info_box(el, indent)
|
22
|
+
if el.attr['class']
|
23
|
+
el.attr['class'] = el.attr['class'].include?('test') ?
|
24
|
+
el.attr['class'] :
|
25
|
+
el.attr['class'].split.unshift('test').reject(&:empty?).join(' ')
|
26
|
+
else
|
27
|
+
el.attr['class'] = 'infoBox'
|
28
|
+
end
|
29
|
+
|
30
|
+
"#{' '*indent}<div#{html_attributes(el.attr)}>\n#{inner(el, indent)}#{' '*indent}</div>\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
def convert_oembed(el, indent)
|
34
|
+
provider = el.attr['provider_name']
|
35
|
+
el.attr['provider_name'] = nil
|
36
|
+
el_id = ""
|
37
|
+
if el.attr['html']
|
38
|
+
oembed_html = el.attr['html']
|
39
|
+
el.attr['html'] = nil
|
40
|
+
end
|
41
|
+
if el.attr['id']
|
42
|
+
el_id = " aria-labelledby=\"#{el.attr['id']}\""
|
43
|
+
el.attr['id'] = nil
|
44
|
+
end
|
45
|
+
if el.attr['role'] === "img"
|
46
|
+
"#{' '*indent}<figure%s#{html_attributes(el.attr)}>#{inner(el, indent)}</figure>\n" % el_id
|
47
|
+
else
|
48
|
+
if provider.casecmp "twitter"
|
49
|
+
"#{' '*indent}<figure#{html_attributes(el.attr)}>#{oembed_html}#{inner(el, indent)}</figure>\n"
|
50
|
+
else
|
51
|
+
"#{' '*indent}<figure%s#{html_attributes(el.attr)}>#{oembed_html}#{inner(el, indent)}</figure>\n" % el_id
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def convert_figure(el, indent)
|
57
|
+
"#{' '*indent}<figure#{html_attributes(el.attr)}>#{inner(el, indent)}</figure>\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
def convert_figCaption(el, indent)
|
61
|
+
id = ""
|
62
|
+
if el.attr['id']
|
63
|
+
id = " id=\"#{el.attr['id']}\""
|
64
|
+
el.attr['id'] = nil
|
65
|
+
end
|
66
|
+
"#{' '*indent}<figCaption%s#{html_attributes(el.attr)}>#{escape_html(el.value)}</figCaption>\n" % id
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|