Code Monkey home page Code Monkey logo

java-markdown-generator's Introduction

Java Markdown Generator

Travis JitPack Bintray Maven Central Codecov

Simple to use Java library to generate beautiful markdown.

Screenshot

Usage

Integration

Gradle

You can get snapshot and release builds from JitPack:

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.Steppschuh:Java-Markdown-Generator:master-SNAPSHOT'
}

Alternatively, release builds are also available on Bintray:

repositories {
    maven { url 'http://dl.bintray.com/steppschuh/Markdown-Generator' }
}
dependencies {
    compile 'net.steppschuh.markdowngenerator:markdowngenerator:1.3.2'
}

Maven

<dependency>
  <groupId>net.steppschuh.markdowngenerator</groupId>
  <artifactId>markdowngenerator</artifactId>
  <version>1.3.2</version>
</dependency>

JAR

You can download the latest .jar files from GitHub or Bintray.

Examples

Most Markdown elements have static convenience methods in the Markdown class. You can also use their repesctive constructors, as shown below.

Emphasis

@Test
public void example() throws Exception {
    StringBuilder sb = new StringBuilder()
            .append(new Text("I am normal")).append("\n")
            .append(new BoldText("I am bold")).append("\n")
            .append(new ItalicText("I am italic")).append("\n")
            .append(new StrikeThroughText("I am strike-through"));

    System.out.println(sb);
}

Output:

I am normal
**I am bold**
_I am italic_
~~I am strike-through~~

Headings

@Test
public void example() throws Exception {
    StringBuilder sb = new StringBuilder()
            .append(new Heading("Heading with level 1", 1)).append("\n")
            .append(new Heading("Heading with level 2", 2)).append("\n")
            .append(new Heading("Heading with level 3", 3)).append("\n")
            .append(new Heading("Heading with level 4", 4)).append("\n")
            .append(new Heading("Heading with level 5", 5)).append("\n")
            .append(new Heading("Heading with level 6", 6));

    System.out.println(sb);
}

Output:

Heading with level 1
====================
Heading with level 2
--------------------
### Heading with level 3
#### Heading with level 4
##### Heading with level 5
###### Heading with level 6

Rules

@Test
public void example() throws Exception {
    System.out.println(new HorizontalRule());
    System.out.println(new HorizontalRule(20, HorizontalRule.ASTERISK));
}

Output:

---
********************

Images

@Test
public void example() throws Exception {
    String text = "I am an image";
    String url = "https://dummyimage.com/300";
    System.out.println(new Image(text, url));
}

Output:

![I am an image](https://dummyimage.com/300)

Lists

@Test
public void example() throws Exception {
    List<Object> items = Arrays.asList(
            "Items can be anything",
            new Date(0),
            1337
    );
    System.out.println(new UnorderedList<>(items));
}

Output:

- Items can be anything
- Thu Jan 01 01:00:00 CET 1970
- 1337

Tasks

@Test
public void example() throws Exception {
    List<TaskListItem> items = Arrays.asList(
            new TaskListItem("Task 1", true),
            new TaskListItem("Task 2", false),
            new TaskListItem("Task 3")
    );
    System.out.println(new TaskList(items));
}

Output:

- [x] Task 1
- [ ] Task 2
- [ ] Task 3

Tables

@Test
public void example() throws Exception {
    Table.Builder tableBuilder = new Table.Builder()
            .withAlignments(Table.ALIGN_RIGHT, Table.ALIGN_LEFT)
            .withRowLimit(7)
            .addRow("Index", "Boolean");

    for (int i = 1; i <= 20; i++) {
        tableBuilder.addRow(i, Math.random() > 0.5);
    }

    System.out.println(tableBuilder.build());
}

Output:

| Index | Boolean |
| -----:| ------- |
|     1 | false   |
|     2 | true    |
|     3 | false   |
| ~~~~~ | ~~~~~~~ |
|    18 | false   |
|    19 | true    |
|    20 | false   |

Code

@Test
public void example() throws Exception {
    String code = "// notice this new line\n" +
            "System.out.println(\"Hello\");";
    System.out.println(new CodeBlock(code, "Java"));
}

Output:

    ```Java
    // notice this new line
    System.out.println("Hello");
    ```

java-markdown-generator's People

Contributors

steppschuh avatar christianhoesel avatar kaiser-chris avatar qworel97 avatar tianshuang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.