Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Kramdown::Document#to_html calls #644

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/kramdown/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ def initialize(source, options = {})
end
end

# Use Kramdown::Converter::Html class to convert this document into HTML.
def to_html
output, warnings = Kramdown::Converter::Html.convert(@root, @options)
@warnings.concat(warnings)
output
end

# Check if a method is invoked that begins with +to_+ and if so, try to instantiate a converter
# class (i.e. a class in the Kramdown::Converter module) and use it for converting the document.
#
# For example, +to_html+ would instantiate the Kramdown::Converter::Html class.
# For example, +to_latex+ would instantiate the Kramdown::Converter::Latex class.
def method_missing(id, *attr, &block)
if id.to_s =~ /^to_(\w+)$/ && (name = Utils.camelize($1)) &&
try_require('converter', name) && Converter.const_defined?(name)
Expand Down