flexmark-ext-prism-linenumber

flexmark-java extension for prism syntax highlighter.

License

License

GroupId

GroupId

org.riversun
ArtifactId

ArtifactId

flexmark-ext-prism-linenumber
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

flexmark-ext-prism-linenumber
flexmark-java extension for prism syntax highlighter.
Project URL

Project URL

https://github.com/riversun/flexmark-ext-prism-linenumber
Source Code Management

Source Code Management

https://github.com/riversun/flexmark-ext-prism-linenumber

Download flexmark-ext-prism-linenumber

How to add to project

<!-- https://jarcasting.com/artifacts/org.riversun/flexmark-ext-prism-linenumber/ -->
<dependency>
    <groupId>org.riversun</groupId>
    <artifactId>flexmark-ext-prism-linenumber</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.riversun/flexmark-ext-prism-linenumber/
implementation 'org.riversun:flexmark-ext-prism-linenumber:1.0.0'
// https://jarcasting.com/artifacts/org.riversun/flexmark-ext-prism-linenumber/
implementation ("org.riversun:flexmark-ext-prism-linenumber:1.0.0")
'org.riversun:flexmark-ext-prism-linenumber:jar:1.0.0'
<dependency org="org.riversun" name="flexmark-ext-prism-linenumber" rev="1.0.0">
  <artifact name="flexmark-ext-prism-linenumber" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.riversun', module='flexmark-ext-prism-linenumber', version='1.0.0')
)
libraryDependencies += "org.riversun" % "flexmark-ext-prism-linenumber" % "1.0.0"
[org.riversun/flexmark-ext-prism-linenumber "1.0.0"]

Dependencies

provided (1)

Group / Artifact Type Version
com.vladsch.flexmark : flexmark-all jar 0.50.26

test (1)

Group / Artifact Type Version
junit : junit jar 4.7

Project Modules

There are no modules declared in this project.

Overview

flexmark-java extension for prism syntax highlighter.

This extension will insert 'class="line-numbers"' attribute into fenced code block.

It is licensed under MIT.

How to use

Maven

<dependency>
	<groupId>org.riversun</groupId>
	<artifactId>flexmark-ext-prism-linenumber</artifactId>
	<version>1.0.0</version>
</dependency>

This library and flexmark-java make following markdown output html

Input markdown


**Hello**

```java

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

```

Output html

<p><strong>Hello</strong></p>
<pre class="line-numbers"><code class="language-java">

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( &quot;Hello World!&quot; );
    }
}

</code></pre>

Example code

import java.io.IOException;
import java.util.Arrays;

import org.riversun.flexmark.PrismCodeLineNumberExtension;

import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.builder.Extension;
import com.vladsch.flexmark.util.data.MutableDataHolder;
import com.vladsch.flexmark.util.data.MutableDataSet;

/**
 * 
 * Example for flexmark-java extension for prism syntax highlighter linenumber
 * rendering
 *
 */
public class Example {

  public static void main(String[] args) throws IOException {

    String srcMarkdown = "**Hello**\n" +
        "\n" +
        "```java\n" +
        "\n" +
        "/**\n" +
        " * Hello world!\n" +
        " *\n" +
        " */\n" +
        "public class App \n" +
        "{\n" +
        "    public static void main( String[] args )\n" +
        "    {\n" +
        "        System.out.println( \"Hello World!\" );\n" +
        "    }\n" +
        "}\n" +
        "\n" +
        "```";

    MutableDataHolder options = new MutableDataSet();
    options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[] {
        PrismCodeLineNumberExtension.create()

    }));

    Parser parser = Parser.builder(options).build();

    Node document = parser.parse(srcMarkdown);

    HtmlRenderer renderer = HtmlRenderer.builder(options).build();

    final String html = renderer.render(document);

    System.out.println(html);

  }

Versions

Version
1.0.0