html-to-markdown


License

License

MIT
GroupId

GroupId

com.github.tkqubo
ArtifactId

ArtifactId

html-to-markdown
Last Version

Last Version

0.8.3
Release Date

Release Date

Type

Type

jar
Description

Description

html-to-markdown
html-to-markdown
Project URL

Project URL

https://github.com/tkqubo/scala-html-to-markdown
Project Organization

Project Organization

com.github.tkqubo
Source Code Management

Source Code Management

https://github.com/tkqubo/scala-html-to-markdown

Download html-to-markdown

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.tkqubo/html-to-markdown/ -->
<dependency>
    <groupId>com.github.tkqubo</groupId>
    <artifactId>html-to-markdown</artifactId>
    <version>0.8.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.tkqubo/html-to-markdown/
implementation 'com.github.tkqubo:html-to-markdown:0.8.3'
// https://jarcasting.com/artifacts/com.github.tkqubo/html-to-markdown/
implementation ("com.github.tkqubo:html-to-markdown:0.8.3")
'com.github.tkqubo:html-to-markdown:jar:0.8.3'
<dependency org="com.github.tkqubo" name="html-to-markdown" rev="0.8.3">
  <artifact name="html-to-markdown" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.tkqubo', module='html-to-markdown', version='0.8.3')
)
libraryDependencies += "com.github.tkqubo" % "html-to-markdown" % "0.8.3"
[com.github.tkqubo/html-to-markdown "0.8.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
org.jsoup : jsoup jar 1.12.1

test (4)

Group / Artifact Type Version
org.specs2 : specs2-core_2.12 jar 4.6.0
org.specs2 : specs2-matcher_2.12 jar 4.6.0
org.specs2 : specs2-matcher-extra_2.12 jar 4.6.0
org.specs2 : specs2-mock_2.12 jar 4.6.0

Project Modules

There are no modules declared in this project.

Scala HTML-to-Markdown

Maven Central License: MIT Circle CI Coverage Status

An HTML to Markdown converter written in Scala, inspired by https://github.com/domchristie/to-markdown

Installation

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"

Quick Start

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**."

API

TBD

Writing your own rule

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

Development

Test

sbt test

or, with coverage

sbt clean coverage test

Copyright

Copyright (c) 2015 tkqubo. See LICENSE for details.

Versions

Version
0.8.3
0.8.2
0.7.2
0.5.0
0.4.1
0.4.0
0.3.1
0.3.0
0.2.3