Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

flexmark-java

> 前端框架
Open source

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF,

2.6K stars0 likes1 views
WebsiteGitHub

About

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF,

flexmark-java

flexmark-java is a Java implementation of [CommonMark (spec 0.28)] parser using the blocks first, inlines after Markdown parsing architecture.

Its strengths are speed, flexibility, Markdown source element based AST with details of the source position down to individual characters of lexemes that make up the element and extensibility.

The API allows granular control of the parsing process and is optimized for parsing with a large number of installed extensions. The parser and extensions come with plenty of options for parser behavior and HTML rendering variations. The end goal is to have the parser and renderer be able to mimic other parsers with great degree of accuracy. This is now partially complete with the implementation of Markdown Processor Emulation

Motivation for this project was the need to replace [pegdown] parser in my [Markdown Navigator] plugin for JetBrains IDEs. [pegdown] has a great feature set but its speed in general is less than ideal and for pathological input either hangs or practically hangs during parsing.

:warning: Version 0.60.0 has breaking changes due to re-organization, renaming, clean up and optimization of implementation classes. Changes are detailed in Version-0.60.0-Changes.

latest

Requirements

  • For Versions 0.62.2 or below, Java 8 or above, Java 9+ compatible. For Versions 0.64.0 or above, Java 11 or above.

  • The project is on Maven: com.vladsch.flexmark

  • The core has no dependencies other than org.jetbrains:annotations:24.0.1. For extensions, see extension description below.

    The API is still evolving to accommodate new extensions and functionality.

Quick Start

For Maven, add flexmark-all as a dependency which includes core and all modules to the following sample:

xml
<dependency>
    <groupId>com.vladsch.flexmark</groupId>
    <artifactId>flexmark-all</artifactId>
    <version>0.64.8</version>
</dependency>

Source: BasicSample.java

…

Building via Gradle

bash
implementation 'com.vladsch.flexmark:flexmark-all:0.64.8'

Building with Android Studio

Additional settings due to duplicate files:

groovy
packagingOptions {
    exclude 'META-INF/LICENSE-LGPL-2.1.txt'
    exclude 'META-INF/LICENSE-LGPL-3.txt'
    exclude 'META-INF/LICENSE-W3C-TEST'
    exclude 'META-INF/DEPENDENCIES'
}

More information can be found in the documentation:
Wiki Home     Usage Examples     Extension Details     Writing Extensions

Pegdown Migration Helper

PegdownOptionsAdapter class converts pegdown Extensions.* flags to flexmark options and extensions list. Pegdown Extensions.java is included for convenience and new options not found in pegdown 1.6.0. These are located in flexmark-profile-pegdown module but you can grab the source from this repo: [PegdownOptionsAdapter.java], [Extensions.java] and make your own version, modified to your project's needs.

You can pass your extension flags to static PegdownOptionsAdapter.flexmarkOptions(int) or you can instantiate PegdownOptionsAdapter and use convenience methods to set, add and remove extension flags. PegdownOptionsAdapter.getFlexmarkOptions() will return a fresh copy of DataHolder every time with the options reflecting pegdown extension flags.

…

Default flexmark-java pegdown emulation uses less strict HTML block parsing which interrupts an HTML block on a blank line. Pegdown only interrupts an HTML block on a blank line if all tags in the HTML block are closed.

To get closer to original pegdown HTML block parsing behavior use the method which takes a boolean strictHtml argument:

…

A sample with a [custom link resolver] is also available, which includes link resolver for changing URLs or attributes of links and a custom node renderer if you need to override the generated link HTML.

:information_source: [flexmark-java] has many more extensions and configuration options than [pegdown] in addition to extensions available in pegdown 1.6.0. Available Extensions via PegdownOptionsAdapter

Latest Additions and Changes

  • Major reorganization and code cleanup of implementation in version 0.60.0, see Version-0.60.0-Changes thanks to great work by Alex Karezin you can get an overview of module dependencies with ability to drill down to packages and classes.

  • Merge API to merge multiple markdown documents into a single document.

  • Docx Renderer Extension: Limited Attributes Node Handling

  • Extensible HTML to Markdown Converter module: flexmark-html2md-converter. Sample: [HtmlToMarkdownCustomizedSample.java]

  • Java9+ module compatibility

  • Compound Enumerated References Enumerated References Extension for creating legal numbering for elements and headings.

  • Macros Extension to allow arbitrary markdown content to be inserted as block or inline elements, allowing block elements to be used where only inline elements are allowed by syntax.

  • GitLab Flavoured Markdown for parsing and rendering GitLab markdown extensions.

  • OSGi module courtesy Dan Klco (GitHub @klcodanr)

  • Media Tags Media link transformer extension courtesy Cornelia Schultz (GitHub @CorneliaXaos) transforms links using custom prefixes to Audio, Embed, Picture, and Video HTML5 tags.

  • Translation Helper API to make translating markdown documents easier.

  • Admonition To create block-styled side content. For complete documentation please see the [Admonition Extension, Material for MkDocs] documentation.

  • Enumerated Reference to create enumerated references for figures, tables and other markdown elements.

  • Attributes to parse attributes of the form {name name=value name='value' name="value" #id .class-name} attributes.

  • YouTube Embedded Link Transformer thanks to Vyacheslav N. Boyko (GitHub @bvn13) transforms simple links to youtube videos to embedded video iframe HTML.

  • Docx Converter using the [docx4j] library. How to use: [DocxConverter Sample], how to customize: Customizing Docx Rendering

    Development of this module was sponsored by Johner Institut GmbH.

  • Update library to be [CommonMark (spec 0.28)] compliant and add ParserEmulationProfile.COMMONMARK_0_27 and ParserEmulationProfile.COMMONMARK_0_28 to allow selecting a specific spec version options.

  • Custom node rendering API with ability to invoke standard rendering for an overridden node, allowing custom node renders that only handle special cases and let the rest be rendered as usual. [custom link resolver]

  • Gfm-Issues and Gfm-Users extensions for parsing and rendering #123 and @user-name respectively.

  • Deep HTML block parsing option for better handling of raw text tags that come after other tags and for [pegdown] HTML block parsing compatibility.

  • flexmark-all module that includes: core, all extensions, formatter, JIRA and YouTrack converters, pegdown profile module and HTML to Markdown conversion.

  • PDF Output Module PDF output using [Open HTML To PDF]

  • Typographic implemented

  • XWiki Macro Extension

  • Jekyll Tags

  • Html To Markdown

  • Maven Markdown Page Generator Plugin

  • Markdown Formatter module to output AST as markdown with formatting options.

  • Tables for Markdown Formatter with column width and alignment of markdown tables:

    Input Output
    markdown
    day|time|spent
    :---|:---:|--:
    nov. 2. tue|10:00|4h 40m
    nov. 3. thu|11:00|4h
    nov. 7. mon|10:20|4h 20m
    total:|| 13h
    markdown
    | day         | time  |   spent |
    |:------------|:-----:|--------:|
    | nov. 2. tue | 10:00 |  4h 40m |
    | nov. 3. thu | 11:00 |      4h |
    | nov. 7. mon | 10:20 |  4h 20m |
    | total:             ||     13h |

Releases, Bug Fixes, Enhancements and Support

I use flexmark-java as the parser for [Markdown Navigator] plugin for JetBrains IDEs. I tend to use the latest, unreleased version to fix bugs or get improvements. So if you find a bug that is a show stopper for your project or see a bug in [github issues page] marked fixed for next release that is affecting your project then please let me know and I may be able to promptly make a new release to address your issue. Otherwise, I will let bug fixes and enhancements accumulate thinking no one is affected by what is already fixed.

Extension points in the API are many and numerous

There are many extension options in the API with their intended use. A good soft-start is the flexmark-java-samples module which has simple samples for asked for extensions. The next best place is the source of an existing extension that has similar syntax to what you want to add.

If your extension lines up with the right API, the task is usually very short and sweet. If your extension uses the API in an unintended fashion or does not follow expected housekeeping protocols, you may find it an uphill battle with a rat's nest of if/else condition handling and fixing one bug only leading to creating another one.

Generally, if it takes more than a few dozen lines to add a simple extension, then either you are going about it wrong or the API is missing an extension point. If you look at all the implemented extensions you will see that most are a few lines of code other than boiler plate dictated by the API. That is the goal for this library: provide an extensible core that makes writing extensions a breeze.

The larger extensions are flexmark-ext-tables and flexmark-ext-spec-example, the meat of both is around 200 lines of code. You can use them as a guide post for size estimating your extension.

My own experience adding extensions shows that sometimes a new type of extension is best addressed with an API enhancement to make its implementation seamless, or by fixing a bug that was not visible before the extension stressed the API in just the right way. Your intended extension may just be the one requiring such an approach.

Don't hesitate to open an issue if you can't find the answer

The takeaway is: if you want to implement a

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javacommonmarkhtml-to-markdownjavamarkdown

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架