An HTML to Markdown converter written in Scala, inspired by https://github.com/domchristie/to-markdown
Assuming you are using Scala 2.11.x, add the following line to your build file:
libraryDependencies += "com.github.tkqubo" % "html-to-markdown" % "0.3.0"
import com.github.tkqubo.html2md.Html2Markdown
val html = "<h1>introduction</h1><p>this is a <b>converter</b>.</p>"
val markdown = Html2Markdown.toMarkdown(html)
// markdown == "# introduction\n\nthis is a **converter**."
TBD
You can write your own HTML-to-markdown conversion rules. They can be represented as a simple tuple
TBD
// <br>
('br -> "\n")
// <p>
('p -> { content: String => s"\n\n$content\n\n" })
// <em> or <i>
(Seq('em, 'i) -> { content: String => s"_${content}_" })
// <a> with href attr
(
{ e: Element => e.tagName == "a" && e.hasAttr("href") } ->
{ (text: String, e: Element) =>
val titlePart = if (e.hasAttr("title")) s""" "${e.attr("title")}"""" else ""
s"""[$text](${e.attr("href")}$titlePart)"""
}
)
TBD
sbt test
or, with coverage
sbt clean coverage test
Copyright (c) 2015 tkqubo. See LICENSE for details.