Module: Upmark
- Defined in:
- lib/upmark.rb,
lib/upmark/errors.rb,
lib/upmark/parser/xml.rb,
lib/upmark/transform/ignore.rb,
lib/upmark/transform_helpers.rb,
lib/upmark/transform/markdown.rb,
lib/upmark/transform/normalise.rb,
lib/upmark/transform/preprocess.rb
Defined Under Namespace
Modules: Parser, Transform, TransformHelpers
Constant Summary collapse
- ParseFailed =
Class.new(StandardError)
Class Method Summary collapse
Class Method Details
.convert(html) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/upmark.rb', line 13 def self.convert(html) xml = Parser::XML.new normalise = Transform::Normalise.new preprocess = Transform::Preprocess.new markdown = Transform::Markdown.new ast = xml.parse(html.strip) ast = normalise.apply(ast) ast = preprocess.apply(ast) ast = markdown.apply(ast) # The result is either a String or an Array. ast = ast.join if ast.is_a?(Array) # Any more than two consecutive newline characters is superflous. ast = ast.gsub(/\n(\s*\n)+/, "\n\n") ast.strip rescue Parslet::ParseFailed raise Upmark::ParseFailed end |