Class: Jazzy::Markdown::JazzyHTML
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- Jazzy::Markdown::JazzyHTML
show all
- Includes:
- Footnotes, Redcarpet::Render::SmartyPants, Rouge::Plugins::Redcarpet
- Defined in:
- lib/jazzy/jazzy_markdown.rb
Constant Summary
collapse
- UNIQUELY_HANDLED_CALLOUTS =
%w[parameters
parameter
returns].freeze
- GENERAL_CALLOUTS =
%w[attention
author
authors
bug
complexity
copyright
date
experiment
important
invariant
keyword
mutatingvariant
nonmutatingvariant
note
postcondition
precondition
recommended
recommendedover
remark
remarks
requires
see
seealso
since
todo
throws
version
warning].freeze
- SPECIAL_LIST_TYPES =
(UNIQUELY_HANDLED_CALLOUTS + GENERAL_CALLOUTS).freeze
- SPECIAL_LIST_TYPE_REGEX =
%r{
\A\s* # optional leading spaces
(<p>\s*)? # optional opening p tag
# any one of our special list types
(#{SPECIAL_LIST_TYPES.map(&Regexp.method(:escape)).join('|')})
[\s:] # followed by either a space or a colon
}ix
- ELIDED_LI_TOKEN =
'7wNVzLB0OYPL2eGlPKu8q4vITltqh0Y6DPZf659TPMAeYh49o'.freeze
Instance Attribute Summary collapse
Attributes included from Footnotes
#footnotes_hash
Instance Method Summary
collapse
Methods included from Footnotes
#footnote_def, #footnote_ref, #map_footnote, next_footnote, #reset
Instance Attribute Details
#default_language ⇒ Object
Returns the value of attribute default_language.
50
51
52
|
# File 'lib/jazzy/jazzy_markdown.rb', line 50
def default_language
@default_language
end
|
Instance Method Details
#block_code(code, language) ⇒ Object
155
156
157
|
# File 'lib/jazzy/jazzy_markdown.rb', line 155
def block_code(code, language)
super(code, language || default_language)
end
|
#codespan(text) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/jazzy/jazzy_markdown.rb', line 63
def codespan(text)
if /^\$\$(.*)\$\$$/m =~ text
o = ["<div class='math m-block'>", Regexp.last_match[1], '</div>']
Markdown.has_math = true
elsif /^\$(.*)\$$/m =~ text
o = ["<span class='math m-inline'>", Regexp.last_match[1], '</span>']
Markdown.has_math = true
else
o = ['<code>', text, '</code>']
end
o[0] + CGI.escapeHTML(o[1]) + o[2]
end
|
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/jazzy/jazzy_markdown.rb', line 52
def (text, )
text_slug = text.gsub(/[^[[:word:]]]+/, '-')
.downcase
.sub(/^-/, '')
.sub(/-$/, '')
"<h#{header_level} id='#{text_slug}' class='heading'>" \
"#{text}" \
"</h#{header_level}>\n"
end
|
#list(text, list_type) ⇒ Object
145
146
147
148
149
150
151
152
153
|
# File 'lib/jazzy/jazzy_markdown.rb', line 145
def list(text, list_type)
elided = text.gsub!(ELIDED_LI_TOKEN, '')
return if text =~ /\A\s*\Z/ && elided
str = "\n"
str << (list_type == :ordered ? "<ol>\n" : "<ul>\n")
str << text
str << (list_type == :ordered ? "</ol>\n" : "</ul>\n")
str.gsub(%r{\n?<ul>\n<\/ul>}, '')
end
|
#list_item(text, _list_type) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/jazzy/jazzy_markdown.rb', line 123
def list_item(text, _list_type)
if text =~ SPECIAL_LIST_TYPE_REGEX
type = Regexp.last_match(2)
if UNIQUELY_HANDLED_CALLOUTS.include? type.downcase
return ELIDED_LI_TOKEN
end
return render_aside(type, text.sub(/#{Regexp.escape(type)}:\s+/, ''))
end
str = '<li>'
str << text.strip
str << "</li>\n"
end
|
#render_aside(type, text) ⇒ Object
136
137
138
139
140
141
142
143
|
# File 'lib/jazzy/jazzy_markdown.rb', line 136
def render_aside(type, text)
"</ul><div class=\"aside aside-\#{type.underscore.tr('_', '-')}\">\n <p class=\"aside-title\">\#{type.underscore.humanize}</p>\n \#{text}\n</div><ul>\n HTML\nend\n"
|
159
160
161
|
# File 'lib/jazzy/jazzy_markdown.rb', line 159
def rouge_formatter(lexer)
Highlighter::Formatter.new(lexer.tag)
end
|