This Maven plugin uses GitHub API for converting Markdown to HTML | Read-only mirror of https://github.com/SchweizerischeBundesbahnen/markdown2html-maven-plugin — SBB. Issues & pull requests at the source.
  • Java 70%
  • HTML 16.1%
  • CSS 13.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-12-03 03:44:22 +00:00
.github chore(deps): update astral-sh/setup-uv action to v10.4.0 2026-11-23 20:02:28 +00:00
.idea/codeStyles Initial commit 2024-07-10 13:03:31 +02:00
.mvn fix: stray closing br tags (#74) 2026-07-29 19:35:59 +02:00
LICENSES feat: local markdown renderer (#75) 2026-07-29 22:21:11 +02:00
src test: re-record the GitHub baseline after a camo change (#98) 2026-11-13 09:56:20 +01:00
.gitignore ci: enhance GitHub workflows and improve build process (#64) 2025-07-07 08:57:54 +02:00
.pre-commit-config.yaml chore(deps): update pre-commit hook commitizen-tools/commitizen to v4.20.1 2026-11-27 10:31:27 +00:00
.yamlfix.toml Initial commit 2024-07-10 13:03:31 +02:00
CHANGELOG.md chore(main): release 1.8.0 (#83) 2026-10-04 18:43:59 +02:00
CODING_STANDARDS.md Initial commit 2024-07-10 13:03:31 +02:00
CONTRIBUTING.md ci: enhance GitHub workflows and improve build process (#64) 2025-07-07 08:57:54 +02:00
lombok.config feat: initial implementation (#3) 2024-07-10 13:46:45 +02:00
pom.xml fix(deps): update dependency org.codehaus.mojo:exec-maven-plugin to v3.8.0 2026-12-03 03:44:22 +00:00
README.md feat: skip the conversion with markdown2html.skip (#88) 2026-10-04 18:17:30 +02:00
RELEASE.md ci: enhance GitHub workflows and improve build process (#64) 2025-07-07 08:57:54 +02:00
renovate.json Initial commit 2024-07-10 13:03:31 +02:00

Quality Gate Status Bugs Code Smells Coverage Duplicated Lines (%) Lines of Code Reliability Rating Security Rating Maintainability Rating Vulnerabilities

Markdown to HTML Maven Plugin

This Maven plugin converts Markdown to HTML.

Rendering happens locally, with commonmark-java: CommonMark plus the extensions GitHub Flavored Markdown adds on top of it — tables, strikethrough, task lists and autolinks — plus the two things GitHub renders in Markdown files that no spec covers: footnotes and alerts (> [!NOTE], > [!TIP], > [!IMPORTANT], > [!WARNING], > [!CAUTION]), in GitHub's own markup down to the octicon. A single newline stays a newline rather than becoming a <br>, which is how GitHub renders a Markdown file such as README.md.

Earlier versions posted the Markdown to the GitHub API instead. Converting locally removes the network call from the build, along with its rate limits and its need for a token.

Syntax highlighting

Fenced code blocks that name a language are coloured during the build, by the lexers of RSyntaxTextArea, in GitHub's light theme. The colours are written as inline style attributes, so the generated file needs no stylesheet of its own and cannot leak styles into the page it is embedded in. Set highlightCode to false to leave code blocks plain.

Known languages: bash/sh/shell/zsh/console, bat/cmd, c, cpp, cs/csharp, css, csv, dart, dockerfile/docker, go/golang, groovy, html, ini/toml, java, javascript/js, json, jsp, kotlin/kt, less, lua, makefile/make, perl, php, properties, proto/protobuf, python/py, ruby/rb, rust/rs, scala, sql, typescript/ts, xml, yaml/yml. Anything else is rendered plain, with its language-… class kept.

GitHub typography

Highlighting colours the code; it does not style the document. Set embedStylesheet to true and the output is wrapped in <style>…</style><div class="markdown-body">, carrying github-markdown-css (MIT, vendored into the plugin, nothing fetched at build or display time). Every rule in it is scoped to markdown-body, so it styles the generated content and nothing else on the page.

Differences from github.com

The output is the same markup, without the chrome github.com wraps around it: headings carry no permalink anchor (use generateHeadingIds for ids), code is highlighted by different lexers than GitHub's Linguist so the colouring is close but not identical, images are not proxied through camo and not wrapped in a link, external links get no rel="nofollow", and :emoji: shortcodes are left as written.

GitHubParityTest verifies the rest against the live GitHub API on every build: byte for byte on the constructs GitHub leaves undecorated, after stripping the chrome listed above on the ones it decorates, and byte for byte again on alerts — those against mode gfm, the only mode of the API that renders them. VisualParityTest answers the other question - whether the two look the same - by rendering both in a browser and comparing screenshots. It needs a browser, so it runs in its own CI job, behind the visual-parity profile:

mvn -P visual-parity verify

The profile brings what it needs: it installs the browser, runs the comparison against GitHub, and checks the image baselines below in their container.

Baselines

Both of those answer whether the two renderings agree today. What they cannot say is which side moved when they stop agreeing, so both sides are also recorded:

  • src/test/resources/baseline/{github,local}-*.html — the markup each side produces. A failing github case means GitHub changed, a failing local case means this plugin did, and git diff says what. Re-record with mvn test -Dbaseline.update=true.
  • src/visual-test/resources/baseline/{text,code,blocks}.png — how the output looks, syntax colours and alerts included, which is the part the live comparison has to switch off. One picture per area, so a failure names where to look. Text rasterises differently on every platform, so these are recorded and checked inside the Playwright container, which the profile starts for them. To re-record after an intended change:
mvn -P visual-parity verify -Dvisual.baseline.update=true

Build

This extension can be produced using maven:

mvn clean package

Usage

This plugin can be used in a maven project by adding the following to the pom.xml:

    <build>
        <plugins>
            <plugin>
                <groupId>ch.sbb.maven.plugins</groupId>
                <artifactId>markdown2html-maven-plugin</artifactId>
                <version>${markdown2html-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <id>readme.md-to-about.html</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>convert</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <inputFile>${project.basedir}/README.md</inputFile>
                    <outputFile>${project.basedir}/README.html</outputFile>
                    <failOnError>true</failOnError>
                    <generateHeadingIds>true</generateHeadingIds>
                    <highlightCode>true</highlightCode>
                    <excludeChapters>
                        <excludeChapter>## Build</excludeChapter>
                        <excludeChapter>## Installation to Polarion</excludeChapter>
                        <excludeChapter>## Changelog</excludeChapter>
                    </excludeChapters>
                    <relativeLinkPrefix>https://localhost:9090/</relativeLinkPrefix>
                    <openExternalLinksInNewTab>true</openExternalLinksInNewTab>
                    <removeLinesWithStrings>
                        <removeLinesWithString>https://sonarcloud.io/api/project_badges/</removeLinesWithString>
                    </removeLinesWithStrings>
                    <removeLinesUsingPatterns>
                        <removeLinesUsingPattern>(?m)^.*\[Quality Gate Status\].*(\R|)</removeLinesUsingPattern>
                        <removeLinesUsingPattern>(?m)^.*\[Bugs\].*(\R|)</removeLinesUsingPattern>
                        <removeLinesUsingPattern>(?m)^.*\[Code Smells\].*(\R|)</removeLinesUsingPattern>
                        <removeLinesUsingPattern>(?m)^.*\[Coverage\].*(\R|)</removeLinesUsingPattern>
                        <removeLinesUsingPattern>(?m)^.*\[Duplicated Lines \(%\)\].*(\R|)</removeLinesUsingPattern>
                        <removeLinesUsingPattern>(?m)^.*\[Lines of Code\].*(\R|)</removeLinesUsingPattern>
                        <removeLinesUsingPattern>(?m)^.*\[Reliability Rating\].*(\R|)</removeLinesUsingPattern>
                        <removeLinesUsingPattern>(?m)^.*\[Security Rating\].*(\R|)</removeLinesUsingPattern>
                        <removeLinesUsingPattern>(?m)^.*\[Maintainability Rating\].*(\R|)</removeLinesUsingPattern>
                        <removeLinesUsingPattern>(?m)^.*\[Vulnerabilities\].*(\R|)</removeLinesUsingPattern>
                    </removeLinesUsingPatterns>
                    <imageProcessingType>EMBED</imageProcessingType>
                    <embedStylesheet>true</embedStylesheet>
                </configuration>
            </plugin>
...
        </plugins>
    </build>

skip, or the property markdown2html.skip, skips the conversion: nothing is read and nothing is written. A build skips it for a run which needs no generated page:

mvn verify -Dmarkdown2html.skip=true

tokenEnvVarName is deprecated and ignored - no GitHub token is needed anymore. It is still accepted, since Maven fails on configuration it cannot map to a parameter, and can be dropped from the pom.xml.