Skip to content

wyona/html2mrkdwn

 
 

Repository files navigation

HTML 2 Slack mrkdwn

Convert HTML into Slack mrkdwn with Java.

Build with Gradle

  • gradle wrapper
  • export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
  • ./gradlew tasks --all
  • ./gradlew clean assemble
  • ls build/libs/html2mrkdwn-1.0.1.jar

Build and Distribution with Maven

Issues can be submitted at https://issues.sonatype.org/

Installation

Gradle:

dependencies {
    compile 'org.wyona.html2mrkdwn:html2mrkdwn:1.0.1'
}

Maven:

<dependencies>
    <dependency>
        <groupId>org.wyona.html2mrkdwn</groupId>
        <artifactId>html2mrkdwn</artifactId>
        <version>1.0.1</version>
    </dependency>
</dependencies>

Usage

import org.wyona.html2mrkdwn.CopyDown;

public class Main {
    public static void main (String[] args) {
        CopyDown converter = new CopyDown();
        String myHtml = "<h1>Some title</h1><div>Some html<p>Another paragraph</p></div>";
        String markdown = converter.convert(myHtml);
        System.out.println(markdown);
        // Some title\n==========\n\nSome html\n\nAnother paragraph\n
    }
}

Options

It is possible to use options for converting markdown:

import org.wyona.html2mrkdwn.CopyDown;
import org.wyona.html2mrkdwn.Options;
import org.wyona.html2mrkdwn.OptionsBuilder;

public class Main {
   public static void main (String[] args) {
       OptionsBuilder optionsBuilder = OptionsBuilder.anOptions();
       Options options = optionsBuilder
               .withBr("-")
               // more options
               .build();
       CopyDown converter = new CopyDown(options);
       String myHtml = "<h1>Some title</h1><div>Some html<p>Another paragraph</p></div>";
       String markdown = converter.convert(myHtml);
       System.out.println(markdown);
   }
}
Option Valid values Default
headingStyle SETEXT or ATX SETEXT
hr Any Thematic break * * *
bulletListMarker -, +, or * *
codeBlockStyle INDENTED or FENCED INDENTED
fence ``` or ~~~ ```
emDelimiter _ or * _
strongDelimiter ** or __ **
linkStyle INLINED or REFERENCED INLINED
linkReferenceStyle FULL, COLLAPSED, or SHORTCUT FULL

Acknowledgment

This library is a fork of https://github.com/furstenheim/copy-down which is a port to Java of the wonderful library Turndown.js.

About

Transform html to markdown

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%