Skip to content

Repository files navigation

markflow

A Kotlin/JVM library and Gradle plugin for Markdown processing pipelines. Parse, transform, and emit Markdown (or HTML) with a composable, AST-based API.

Overview

markflow is built on commonmark-java and provides:

  • A clean Kotlin API for parsing Markdown into a mutable AST
  • Composable transformation passes (heading manipulation, front matter promotion, etc.)
  • Round-trip Markdown output via commonmark-java's MarkdownRenderer, with reliable front matter handling
  • A Gradle plugin exposing common transformations as cacheable, incremental tasks

It is not a static site generator. It is a document-processing library and build-tool integration layer — the Markdown equivalent of what a CSS post-processor does for stylesheets.

Design Decisions

Parser: commonmark-java

markflow uses commonmark-java as its parser and formatter. commonmark-java was chosen because:

  • It is actively maintained (Atlassian origin, used by OpenJDK, Google, Gerrit)
  • It is spec-compliant with CommonMark
  • It provides round-trip Markdown output via MarkdownRenderer
  • It supports GFM tables, YAML front matter (including raw/opaque capture), strikethrough, footnotes, and other common extensions out of the box
  • It is BSD 2-Clause licensed, compatible with all likely dependencies

Alternatives considered:

Flexmark-java was the original choice and has a richer extension ecosystem (TOC, definition lists, typographic quotes, etc.), but has been effectively unmaintained since 2023 with 178+ open issues. The maintenance risk outweighs the extension breadth for a library intended for long-term use.

JetBrains Markdown is actively developed but ruled out: its AST is largely immutable, it has no Markdown output support, and it targets Kotlin Multiplatform which is not a current requirement.

Front Matter: Opaque Capture via RawContentParser

commonmark-java's YamlFrontMatterExtension supports a RawContentParser mode that captures the entire front matter block as a single raw string rather than parsing it into key/value pairs. This means:

  • The MarkdownRenderer preserves front matter verbatim by default
  • Callers that need to inspect or modify front matter values do so via Jackson YAML, extracting the raw text, modifying it, and writing it back
  • No front matter content is silently dropped or reordered

Transformation Pipeline

Transformations are independent AST passes. Each pass is a MarkdownTransformer that receives a Document and returns a (possibly mutated) Document. Passes are composed into a MarkdownPipeline and applied in order. This keeps individual transformers small, testable, and independently togglable.

Module Structure

markflow/
library/ # Pure Kotlin library — no Gradle or Maven dependencies
gradle-plugin/ # Gradle plugin wrapping library tasks

library

The standalone Kotlin library JAR. Depends only on commonmark-java and Jackson YAML. No build-tool APIs. Usable from any JVM context: Gradle, Maven, a CLI, application code.

Key types:

TypeDescription
MarkdownDocumentA parsed document: mutable commonmark-java Document + raw front matter string
MarkdownParserParses a String or File into a MarkdownDocument
MarkdownTransformerSingle-responsibility AST transformation pass
MarkdownPipelineOrdered composition of MarkdownTransformer instances
MarkdownFormatterEmits a MarkdownDocument as Markdown (via MarkdownRenderer) or HTML (via HtmlRenderer)
FrontMatterTyped view of the front matter block via Jackson YAML

Built-in transformers:

TransformerDescription
TitlePromoterExtracts title: from front matter and prepends an H1 heading if none exists
HeadingDemoterIncrements all heading levels by a configurable offset (e.g. H1→H2)
TableFormatterPads GFM table columns to consistent widths
SentencePerLineFormatterSplits paragraph text at sentence boundaries, one sentence per line
TemplateSubstitutorReplaces {{key}} placeholders with provided values, skipping fenced code blocks
HtmlCommentExpanderExpands structured HTML comments to Markdown content via registered handlers

gradle-plugin

Plugin ID: net.oxspring.markflow

Exposes library functionality as cacheable, incremental Gradle tasks with @InputFiles / @OutputFiles annotations and UP-TO-DATE checking.

Tasks:

TaskDescription
ProcessMarkdownTaskApplies a configured pipeline to a set of input .md files, writing results to an output directory
MergeMarkdownTaskConcatenates multiple .md files (AST-level merge) into a single output file, with optional heading demotion per file
LintMarkdownTaskReports style violations (heading level skips, missing front matter fields, etc.) without modifying files

The plugin registers a markflow { } extension block for project-level configuration.

Package Namespace

net.oxspring.markflow

Sub-packages follow feature boundaries:

PackageContents
net.oxspring.markflowPublic API: MarkdownDocument, MarkdownParser, MarkdownPipeline, MarkdownFormatter
net.oxspring.markflow.transformBuilt-in MarkdownTransformer implementations
net.oxspring.markflow.frontmatterFrontMatter, front matter access utilities
net.oxspring.markflow.gradleGradle plugin and task implementations

MVP Scope (v1.0)

The v1.0 MVP targets feature parity with the custom Gradle tasks in the wtn monorepo, specifically:

Replaces ProcessGuideTask

ProcessGuideTask processes a directory of Hugo guide Markdown files, applying:

  • {{version}}, {{year}}, {{date}} token substitution (skipping fenced code blocks)
  • <!-- screenshot: name.png | alt text -->![alt](screenshots/name.png) expansion

markflow replaces this with a ProcessMarkdownTask configured with:

  • TemplateSubstitutor (token substitution, fence-aware)
  • HtmlCommentExpander with a screenshot handler

Replaces front matter title extraction in BuildPdfTask

BuildPdfTask reads title: from each file's YAML front matter and manually prepends `# Title

` before passing files to Pandoc. markflow replaces this with:

  • TitlePromoter transformer, promoting title: front matter to an H1 heading
  • MergeMarkdownTask concatenating pages in a declared order with a HeadingDemoter offset

Linting (new capability)

LintMarkdownTask enforces the guide's documented style rules:

  • One sentence per line (configurable)
  • Maximum line length (configurable, default 120)
  • No heading level skips
  • Required front matter fields (configurable)

Build & Test

./gradlew assemble # Compile all modules
./gradlew check # Tests + ktlint + Kover coverage verification
./gradlew build # assemble + check

Test framework: JUnit 6 (Jupiter) with AssertJ.

Key Dependencies

DependencyVersionLicense
commonmark-java0.30.xBSD 2-Clause
commonmark-ext-gfm-tables0.30.xBSD 2-Clause
commonmark-ext-yaml-front-matter0.30.xBSD 2-Clause
Jackson YAML2.xApache 2.0
Kotlin2.xApache 2.0
Gradle Plugin API9.xApache 2.0

License

Apache 2.0. See LICENSE.

About

Markdown processing utilities for use at build time.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - roxspring/markflow: Markdown processing utilities for use at build time. · GitHub
Skip to content

Repository files navigation

markflow

A Kotlin/JVM library and Gradle plugin for Markdown processing pipelines. Parse, transform, and emit Markdown (or HTML) with a composable, AST-based API.

Overview

markflow is built on commonmark-java and provides:

  • A clean Kotlin API for parsing Markdown into a mutable AST
  • Composable transformation passes (heading manipulation, front matter promotion, etc.)
  • Round-trip Markdown output via commonmark-java's MarkdownRenderer, with reliable front matter handling
  • A Gradle plugin exposing common transformations as cacheable, incremental tasks

It is not a static site generator. It is a document-processing library and build-tool integration layer — the Markdown equivalent of what a CSS post-processor does for stylesheets.

Design Decisions

Parser: commonmark-java

markflow uses commonmark-java as its parser and formatter. commonmark-java was chosen because:

  • It is actively maintained (Atlassian origin, used by OpenJDK, Google, Gerrit)
  • It is spec-compliant with CommonMark
  • It provides round-trip Markdown output via MarkdownRenderer
  • It supports GFM tables, YAML front matter (including raw/opaque capture), strikethrough, footnotes, and other common extensions out of the box
  • It is BSD 2-Clause licensed, compatible with all likely dependencies

Alternatives considered:

Flexmark-java was the original choice and has a richer extension ecosystem (TOC, definition lists, typographic quotes, etc.), but has been effectively unmaintained since 2023 with 178+ open issues. The maintenance risk outweighs the extension breadth for a library intended for long-term use.

JetBrains Markdown is actively developed but ruled out: its AST is largely immutable, it has no Markdown output support, and it targets Kotlin Multiplatform which is not a current requirement.

Front Matter: Opaque Capture via RawContentParser

commonmark-java's YamlFrontMatterExtension supports a RawContentParser mode that captures the entire front matter block as a single raw string rather than parsing it into key/value pairs. This means:

  • The MarkdownRenderer preserves front matter verbatim by default
  • Callers that need to inspect or modify front matter values do so via Jackson YAML, extracting the raw text, modifying it, and writing it back
  • No front matter content is silently dropped or reordered

Transformation Pipeline

Transformations are independent AST passes. Each pass is a MarkdownTransformer that receives a Document and returns a (possibly mutated) Document. Passes are composed into a MarkdownPipeline and applied in order. This keeps individual transformers small, testable, and independently togglable.

Module Structure

markflow/
library/ # Pure Kotlin library — no Gradle or Maven dependencies
gradle-plugin/ # Gradle plugin wrapping library tasks

library

The standalone Kotlin library JAR. Depends only on commonmark-java and Jackson YAML. No build-tool APIs. Usable from any JVM context: Gradle, Maven, a CLI, application code.

Key types:

TypeDescription
MarkdownDocumentA parsed document: mutable commonmark-java Document + raw front matter string
MarkdownParserParses a String or File into a MarkdownDocument
MarkdownTransformerSingle-responsibility AST transformation pass
MarkdownPipelineOrdered composition of MarkdownTransformer instances
MarkdownFormatterEmits a MarkdownDocument as Markdown (via MarkdownRenderer) or HTML (via HtmlRenderer)
FrontMatterTyped view of the front matter block via Jackson YAML

Built-in transformers:

TransformerDescription
TitlePromoterExtracts title: from front matter and prepends an H1 heading if none exists
HeadingDemoterIncrements all heading levels by a configurable offset (e.g. H1→H2)
TableFormatterPads GFM table columns to consistent widths
SentencePerLineFormatterSplits paragraph text at sentence boundaries, one sentence per line
TemplateSubstitutorReplaces {{key}} placeholders with provided values, skipping fenced code blocks
HtmlCommentExpanderExpands structured HTML comments to Markdown content via registered handlers

gradle-plugin

Plugin ID: net.oxspring.markflow

Exposes library functionality as cacheable, incremental Gradle tasks with @InputFiles / @OutputFiles annotations and UP-TO-DATE checking.

Tasks:

TaskDescription
ProcessMarkdownTaskApplies a configured pipeline to a set of input .md files, writing results to an output directory
MergeMarkdownTaskConcatenates multiple .md files (AST-level merge) into a single output file, with optional heading demotion per file
LintMarkdownTaskReports style violations (heading level skips, missing front matter fields, etc.) without modifying files

The plugin registers a markflow { } extension block for project-level configuration.

Package Namespace

net.oxspring.markflow

Sub-packages follow feature boundaries:

PackageContents
net.oxspring.markflowPublic API: MarkdownDocument, MarkdownParser, MarkdownPipeline, MarkdownFormatter
net.oxspring.markflow.transformBuilt-in MarkdownTransformer implementations
net.oxspring.markflow.frontmatterFrontMatter, front matter access utilities
net.oxspring.markflow.gradleGradle plugin and task implementations

MVP Scope (v1.0)

The v1.0 MVP targets feature parity with the custom Gradle tasks in the wtn monorepo, specifically:

Replaces ProcessGuideTask

ProcessGuideTask processes a directory of Hugo guide Markdown files, applying:

  • {{version}}, {{year}}, {{date}} token substitution (skipping fenced code blocks)
  • <!-- screenshot: name.png | alt text -->![alt](screenshots/name.png) expansion

markflow replaces this with a ProcessMarkdownTask configured with:

  • TemplateSubstitutor (token substitution, fence-aware)
  • HtmlCommentExpander with a screenshot handler

Replaces front matter title extraction in BuildPdfTask

BuildPdfTask reads title: from each file's YAML front matter and manually prepends `# Title

` before passing files to Pandoc. markflow replaces this with:

  • TitlePromoter transformer, promoting title: front matter to an H1 heading
  • MergeMarkdownTask concatenating pages in a declared order with a HeadingDemoter offset

Linting (new capability)

LintMarkdownTask enforces the guide's documented style rules:

  • One sentence per line (configurable)
  • Maximum line length (configurable, default 120)
  • No heading level skips
  • Required front matter fields (configurable)

Build & Test

./gradlew assemble # Compile all modules
./gradlew check # Tests + ktlint + Kover coverage verification
./gradlew build # assemble + check

Test framework: JUnit 6 (Jupiter) with AssertJ.

Key Dependencies

DependencyVersionLicense
commonmark-java0.30.xBSD 2-Clause
commonmark-ext-gfm-tables0.30.xBSD 2-Clause
commonmark-ext-yaml-front-matter0.30.xBSD 2-Clause
Jackson YAML2.xApache 2.0
Kotlin2.xApache 2.0
Gradle Plugin API9.xApache 2.0

License

Apache 2.0. See LICENSE.

About

Markdown processing utilities for use at build time.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - roxspring/markflow: Markdown processing utilities for use at build time. · GitHub
Skip to content

Repository files navigation

markflow

A Kotlin/JVM library and Gradle plugin for Markdown processing pipelines. Parse, transform, and emit Markdown (or HTML) with a composable, AST-based API.

Overview

markflow is built on commonmark-java and provides:

  • A clean Kotlin API for parsing Markdown into a mutable AST
  • Composable transformation passes (heading manipulation, front matter promotion, etc.)
  • Round-trip Markdown output via commonmark-java's MarkdownRenderer, with reliable front matter handling
  • A Gradle plugin exposing common transformations as cacheable, incremental tasks

It is not a static site generator. It is a document-processing library and build-tool integration layer — the Markdown equivalent of what a CSS post-processor does for stylesheets.

Design Decisions

Parser: commonmark-java

markflow uses commonmark-java as its parser and formatter. commonmark-java was chosen because:

  • It is actively maintained (Atlassian origin, used by OpenJDK, Google, Gerrit)
  • It is spec-compliant with CommonMark
  • It provides round-trip Markdown output via MarkdownRenderer
  • It supports GFM tables, YAML front matter (including raw/opaque capture), strikethrough, footnotes, and other common extensions out of the box
  • It is BSD 2-Clause licensed, compatible with all likely dependencies

Alternatives considered:

Flexmark-java was the original choice and has a richer extension ecosystem (TOC, definition lists, typographic quotes, etc.), but has been effectively unmaintained since 2023 with 178+ open issues. The maintenance risk outweighs the extension breadth for a library intended for long-term use.

JetBrains Markdown is actively developed but ruled out: its AST is largely immutable, it has no Markdown output support, and it targets Kotlin Multiplatform which is not a current requirement.

Front Matter: Opaque Capture via RawContentParser

commonmark-java's YamlFrontMatterExtension supports a RawContentParser mode that captures the entire front matter block as a single raw string rather than parsing it into key/value pairs. This means:

  • The MarkdownRenderer preserves front matter verbatim by default
  • Callers that need to inspect or modify front matter values do so via Jackson YAML, extracting the raw text, modifying it, and writing it back
  • No front matter content is silently dropped or reordered

Transformation Pipeline

Transformations are independent AST passes. Each pass is a MarkdownTransformer that receives a Document and returns a (possibly mutated) Document. Passes are composed into a MarkdownPipeline and applied in order. This keeps individual transformers small, testable, and independently togglable.

Module Structure

markflow/
library/ # Pure Kotlin library — no Gradle or Maven dependencies
gradle-plugin/ # Gradle plugin wrapping library tasks

library

The standalone Kotlin library JAR. Depends only on commonmark-java and Jackson YAML. No build-tool APIs. Usable from any JVM context: Gradle, Maven, a CLI, application code.

Key types:

TypeDescription
MarkdownDocumentA parsed document: mutable commonmark-java Document + raw front matter string
MarkdownParserParses a String or File into a MarkdownDocument
MarkdownTransformerSingle-responsibility AST transformation pass
MarkdownPipelineOrdered composition of MarkdownTransformer instances
MarkdownFormatterEmits a MarkdownDocument as Markdown (via MarkdownRenderer) or HTML (via HtmlRenderer)
FrontMatterTyped view of the front matter block via Jackson YAML

Built-in transformers:

TransformerDescription
TitlePromoterExtracts title: from front matter and prepends an H1 heading if none exists
HeadingDemoterIncrements all heading levels by a configurable offset (e.g. H1→H2)
TableFormatterPads GFM table columns to consistent widths
SentencePerLineFormatterSplits paragraph text at sentence boundaries, one sentence per line
TemplateSubstitutorReplaces {{key}} placeholders with provided values, skipping fenced code blocks
HtmlCommentExpanderExpands structured HTML comments to Markdown content via registered handlers

gradle-plugin

Plugin ID: net.oxspring.markflow

Exposes library functionality as cacheable, incremental Gradle tasks with @InputFiles / @OutputFiles annotations and UP-TO-DATE checking.

Tasks:

TaskDescription
ProcessMarkdownTaskApplies a configured pipeline to a set of input .md files, writing results to an output directory
MergeMarkdownTaskConcatenates multiple .md files (AST-level merge) into a single output file, with optional heading demotion per file
LintMarkdownTaskReports style violations (heading level skips, missing front matter fields, etc.) without modifying files

The plugin registers a markflow { } extension block for project-level configuration.

Package Namespace

net.oxspring.markflow

Sub-packages follow feature boundaries:

PackageContents
net.oxspring.markflowPublic API: MarkdownDocument, MarkdownParser, MarkdownPipeline, MarkdownFormatter
net.oxspring.markflow.transformBuilt-in MarkdownTransformer implementations
net.oxspring.markflow.frontmatterFrontMatter, front matter access utilities
net.oxspring.markflow.gradleGradle plugin and task implementations

MVP Scope (v1.0)

The v1.0 MVP targets feature parity with the custom Gradle tasks in the wtn monorepo, specifically:

Replaces ProcessGuideTask

ProcessGuideTask processes a directory of Hugo guide Markdown files, applying:

  • {{version}}, {{year}}, {{date}} token substitution (skipping fenced code blocks)
  • <!-- screenshot: name.png | alt text -->![alt](screenshots/name.png) expansion

markflow replaces this with a ProcessMarkdownTask configured with:

  • TemplateSubstitutor (token substitution, fence-aware)
  • HtmlCommentExpander with a screenshot handler

Replaces front matter title extraction in BuildPdfTask

BuildPdfTask reads title: from each file's YAML front matter and manually prepends `# Title

` before passing files to Pandoc. markflow replaces this with:

  • TitlePromoter transformer, promoting title: front matter to an H1 heading
  • MergeMarkdownTask concatenating pages in a declared order with a HeadingDemoter offset

Linting (new capability)

LintMarkdownTask enforces the guide's documented style rules:

  • One sentence per line (configurable)
  • Maximum line length (configurable, default 120)
  • No heading level skips
  • Required front matter fields (configurable)

Build & Test

./gradlew assemble # Compile all modules
./gradlew check # Tests + ktlint + Kover coverage verification
./gradlew build # assemble + check

Test framework: JUnit 6 (Jupiter) with AssertJ.

Key Dependencies

DependencyVersionLicense
commonmark-java0.30.xBSD 2-Clause
commonmark-ext-gfm-tables0.30.xBSD 2-Clause
commonmark-ext-yaml-front-matter0.30.xBSD 2-Clause
Jackson YAML2.xApache 2.0
Kotlin2.xApache 2.0
Gradle Plugin API9.xApache 2.0

License

Apache 2.0. See LICENSE.

About

Markdown processing utilities for use at build time.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - roxspring/markflow: Markdown processing utilities for use at build time. · GitHub
Skip to content

Repository files navigation

markflow

A Kotlin/JVM library and Gradle plugin for Markdown processing pipelines. Parse, transform, and emit Markdown (or HTML) with a composable, AST-based API.

Overview

markflow is built on commonmark-java and provides:

  • A clean Kotlin API for parsing Markdown into a mutable AST
  • Composable transformation passes (heading manipulation, front matter promotion, etc.)
  • Round-trip Markdown output via commonmark-java's MarkdownRenderer, with reliable front matter handling
  • A Gradle plugin exposing common transformations as cacheable, incremental tasks

It is not a static site generator. It is a document-processing library and build-tool integration layer — the Markdown equivalent of what a CSS post-processor does for stylesheets.

Design Decisions

Parser: commonmark-java

markflow uses commonmark-java as its parser and formatter. commonmark-java was chosen because:

  • It is actively maintained (Atlassian origin, used by OpenJDK, Google, Gerrit)
  • It is spec-compliant with CommonMark
  • It provides round-trip Markdown output via MarkdownRenderer
  • It supports GFM tables, YAML front matter (including raw/opaque capture), strikethrough, footnotes, and other common extensions out of the box
  • It is BSD 2-Clause licensed, compatible with all likely dependencies

Alternatives considered:

Flexmark-java was the original choice and has a richer extension ecosystem (TOC, definition lists, typographic quotes, etc.), but has been effectively unmaintained since 2023 with 178+ open issues. The maintenance risk outweighs the extension breadth for a library intended for long-term use.

JetBrains Markdown is actively developed but ruled out: its AST is largely immutable, it has no Markdown output support, and it targets Kotlin Multiplatform which is not a current requirement.

Front Matter: Opaque Capture via RawContentParser

commonmark-java's YamlFrontMatterExtension supports a RawContentParser mode that captures the entire front matter block as a single raw string rather than parsing it into key/value pairs. This means:

  • The MarkdownRenderer preserves front matter verbatim by default
  • Callers that need to inspect or modify front matter values do so via Jackson YAML, extracting the raw text, modifying it, and writing it back
  • No front matter content is silently dropped or reordered

Transformation Pipeline

Transformations are independent AST passes. Each pass is a MarkdownTransformer that receives a Document and returns a (possibly mutated) Document. Passes are composed into a MarkdownPipeline and applied in order. This keeps individual transformers small, testable, and independently togglable.

Module Structure

markflow/
library/ # Pure Kotlin library — no Gradle or Maven dependencies
gradle-plugin/ # Gradle plugin wrapping library tasks

library

The standalone Kotlin library JAR. Depends only on commonmark-java and Jackson YAML. No build-tool APIs. Usable from any JVM context: Gradle, Maven, a CLI, application code.

Key types:

TypeDescription
MarkdownDocumentA parsed document: mutable commonmark-java Document + raw front matter string
MarkdownParserParses a String or File into a MarkdownDocument
MarkdownTransformerSingle-responsibility AST transformation pass
MarkdownPipelineOrdered composition of MarkdownTransformer instances
MarkdownFormatterEmits a MarkdownDocument as Markdown (via MarkdownRenderer) or HTML (via HtmlRenderer)
FrontMatterTyped view of the front matter block via Jackson YAML

Built-in transformers:

TransformerDescription
TitlePromoterExtracts title: from front matter and prepends an H1 heading if none exists
HeadingDemoterIncrements all heading levels by a configurable offset (e.g. H1→H2)
TableFormatterPads GFM table columns to consistent widths
SentencePerLineFormatterSplits paragraph text at sentence boundaries, one sentence per line
TemplateSubstitutorReplaces {{key}} placeholders with provided values, skipping fenced code blocks
HtmlCommentExpanderExpands structured HTML comments to Markdown content via registered handlers

gradle-plugin

Plugin ID: net.oxspring.markflow

Exposes library functionality as cacheable, incremental Gradle tasks with @InputFiles / @OutputFiles annotations and UP-TO-DATE checking.

Tasks:

TaskDescription
ProcessMarkdownTaskApplies a configured pipeline to a set of input .md files, writing results to an output directory
MergeMarkdownTaskConcatenates multiple .md files (AST-level merge) into a single output file, with optional heading demotion per file
LintMarkdownTaskReports style violations (heading level skips, missing front matter fields, etc.) without modifying files

The plugin registers a markflow { } extension block for project-level configuration.

Package Namespace

net.oxspring.markflow

Sub-packages follow feature boundaries:

PackageContents
net.oxspring.markflowPublic API: MarkdownDocument, MarkdownParser, MarkdownPipeline, MarkdownFormatter
net.oxspring.markflow.transformBuilt-in MarkdownTransformer implementations
net.oxspring.markflow.frontmatterFrontMatter, front matter access utilities
net.oxspring.markflow.gradleGradle plugin and task implementations

MVP Scope (v1.0)

The v1.0 MVP targets feature parity with the custom Gradle tasks in the wtn monorepo, specifically:

Replaces ProcessGuideTask

ProcessGuideTask processes a directory of Hugo guide Markdown files, applying:

  • {{version}}, {{year}}, {{date}} token substitution (skipping fenced code blocks)
  • <!-- screenshot: name.png | alt text -->![alt](screenshots/name.png) expansion

markflow replaces this with a ProcessMarkdownTask configured with:

  • TemplateSubstitutor (token substitution, fence-aware)
  • HtmlCommentExpander with a screenshot handler

Replaces front matter title extraction in BuildPdfTask

BuildPdfTask reads title: from each file's YAML front matter and manually prepends `# Title

` before passing files to Pandoc. markflow replaces this with:

  • TitlePromoter transformer, promoting title: front matter to an H1 heading
  • MergeMarkdownTask concatenating pages in a declared order with a HeadingDemoter offset

Linting (new capability)

LintMarkdownTask enforces the guide's documented style rules:

  • One sentence per line (configurable)
  • Maximum line length (configurable, default 120)
  • No heading level skips
  • Required front matter fields (configurable)

Build & Test

./gradlew assemble # Compile all modules
./gradlew check # Tests + ktlint + Kover coverage verification
./gradlew build # assemble + check

Test framework: JUnit 6 (Jupiter) with AssertJ.

Key Dependencies

DependencyVersionLicense
commonmark-java0.30.xBSD 2-Clause
commonmark-ext-gfm-tables0.30.xBSD 2-Clause
commonmark-ext-yaml-front-matter0.30.xBSD 2-Clause
Jackson YAML2.xApache 2.0
Kotlin2.xApache 2.0
Gradle Plugin API9.xApache 2.0

License

Apache 2.0. See LICENSE.

About

Markdown processing utilities for use at build time.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - roxspring/markflow: Markdown processing utilities for use at build time. · GitHub
Skip to content

Repository files navigation

markflow

A Kotlin/JVM library and Gradle plugin for Markdown processing pipelines. Parse, transform, and emit Markdown (or HTML) with a composable, AST-based API.

Overview

markflow is built on commonmark-java and provides:

  • A clean Kotlin API for parsing Markdown into a mutable AST
  • Composable transformation passes (heading manipulation, front matter promotion, etc.)
  • Round-trip Markdown output via commonmark-java's MarkdownRenderer, with reliable front matter handling
  • A Gradle plugin exposing common transformations as cacheable, incremental tasks

It is not a static site generator. It is a document-processing library and build-tool integration layer — the Markdown equivalent of what a CSS post-processor does for stylesheets.

Design Decisions

Parser: commonmark-java

markflow uses commonmark-java as its parser and formatter. commonmark-java was chosen because:

  • It is actively maintained (Atlassian origin, used by OpenJDK, Google, Gerrit)
  • It is spec-compliant with CommonMark
  • It provides round-trip Markdown output via MarkdownRenderer
  • It supports GFM tables, YAML front matter (including raw/opaque capture), strikethrough, footnotes, and other common extensions out of the box
  • It is BSD 2-Clause licensed, compatible with all likely dependencies

Alternatives considered:

Flexmark-java was the original choice and has a richer extension ecosystem (TOC, definition lists, typographic quotes, etc.), but has been effectively unmaintained since 2023 with 178+ open issues. The maintenance risk outweighs the extension breadth for a library intended for long-term use.

JetBrains Markdown is actively developed but ruled out: its AST is largely immutable, it has no Markdown output support, and it targets Kotlin Multiplatform which is not a current requirement.

Front Matter: Opaque Capture via RawContentParser

commonmark-java's YamlFrontMatterExtension supports a RawContentParser mode that captures the entire front matter block as a single raw string rather than parsing it into key/value pairs. This means:

  • The MarkdownRenderer preserves front matter verbatim by default
  • Callers that need to inspect or modify front matter values do so via Jackson YAML, extracting the raw text, modifying it, and writing it back
  • No front matter content is silently dropped or reordered

Transformation Pipeline

Transformations are independent AST passes. Each pass is a MarkdownTransformer that receives a Document and returns a (possibly mutated) Document. Passes are composed into a MarkdownPipeline and applied in order. This keeps individual transformers small, testable, and independently togglable.

Module Structure

markflow/
library/ # Pure Kotlin library — no Gradle or Maven dependencies
gradle-plugin/ # Gradle plugin wrapping library tasks

library

The standalone Kotlin library JAR. Depends only on commonmark-java and Jackson YAML. No build-tool APIs. Usable from any JVM context: Gradle, Maven, a CLI, application code.

Key types:

TypeDescription
MarkdownDocumentA parsed document: mutable commonmark-java Document + raw front matter string
MarkdownParserParses a String or File into a MarkdownDocument
MarkdownTransformerSingle-responsibility AST transformation pass
MarkdownPipelineOrdered composition of MarkdownTransformer instances
MarkdownFormatterEmits a MarkdownDocument as Markdown (via MarkdownRenderer) or HTML (via HtmlRenderer)
FrontMatterTyped view of the front matter block via Jackson YAML

Built-in transformers:

TransformerDescription
TitlePromoterExtracts title: from front matter and prepends an H1 heading if none exists
HeadingDemoterIncrements all heading levels by a configurable offset (e.g. H1→H2)
TableFormatterPads GFM table columns to consistent widths
SentencePerLineFormatterSplits paragraph text at sentence boundaries, one sentence per line
TemplateSubstitutorReplaces {{key}} placeholders with provided values, skipping fenced code blocks
HtmlCommentExpanderExpands structured HTML comments to Markdown content via registered handlers

gradle-plugin

Plugin ID: net.oxspring.markflow

Exposes library functionality as cacheable, incremental Gradle tasks with @InputFiles / @OutputFiles annotations and UP-TO-DATE checking.

Tasks:

TaskDescription
ProcessMarkdownTaskApplies a configured pipeline to a set of input .md files, writing results to an output directory
MergeMarkdownTaskConcatenates multiple .md files (AST-level merge) into a single output file, with optional heading demotion per file
LintMarkdownTaskReports style violations (heading level skips, missing front matter fields, etc.) without modifying files

The plugin registers a markflow { } extension block for project-level configuration.

Package Namespace

net.oxspring.markflow

Sub-packages follow feature boundaries:

PackageContents
net.oxspring.markflowPublic API: MarkdownDocument, MarkdownParser, MarkdownPipeline, MarkdownFormatter
net.oxspring.markflow.transformBuilt-in MarkdownTransformer implementations
net.oxspring.markflow.frontmatterFrontMatter, front matter access utilities
net.oxspring.markflow.gradleGradle plugin and task implementations

MVP Scope (v1.0)

The v1.0 MVP targets feature parity with the custom Gradle tasks in the wtn monorepo, specifically:

Replaces ProcessGuideTask

ProcessGuideTask processes a directory of Hugo guide Markdown files, applying:

  • {{version}}, {{year}}, {{date}} token substitution (skipping fenced code blocks)
  • <!-- screenshot: name.png | alt text -->![alt](screenshots/name.png) expansion

markflow replaces this with a ProcessMarkdownTask configured with:

  • TemplateSubstitutor (token substitution, fence-aware)
  • HtmlCommentExpander with a screenshot handler

Replaces front matter title extraction in BuildPdfTask

BuildPdfTask reads title: from each file's YAML front matter and manually prepends `# Title

` before passing files to Pandoc. markflow replaces this with:

  • TitlePromoter transformer, promoting title: front matter to an H1 heading
  • MergeMarkdownTask concatenating pages in a declared order with a HeadingDemoter offset

Linting (new capability)

LintMarkdownTask enforces the guide's documented style rules:

  • One sentence per line (configurable)
  • Maximum line length (configurable, default 120)
  • No heading level skips
  • Required front matter fields (configurable)

Build & Test

./gradlew assemble # Compile all modules
./gradlew check # Tests + ktlint + Kover coverage verification
./gradlew build # assemble + check

Test framework: JUnit 6 (Jupiter) with AssertJ.

Key Dependencies

DependencyVersionLicense
commonmark-java0.30.xBSD 2-Clause
commonmark-ext-gfm-tables0.30.xBSD 2-Clause
commonmark-ext-yaml-front-matter0.30.xBSD 2-Clause
Jackson YAML2.xApache 2.0
Kotlin2.xApache 2.0
Gradle Plugin API9.xApache 2.0

License

Apache 2.0. See LICENSE.

About

Markdown processing utilities for use at build time.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - roxspring/markflow: Markdown processing utilities for use at build time. · GitHub
Skip to content

Repository files navigation

markflow

A Kotlin/JVM library and Gradle plugin for Markdown processing pipelines. Parse, transform, and emit Markdown (or HTML) with a composable, AST-based API.

Overview

markflow is built on commonmark-java and provides:

  • A clean Kotlin API for parsing Markdown into a mutable AST
  • Composable transformation passes (heading manipulation, front matter promotion, etc.)
  • Round-trip Markdown output via commonmark-java's MarkdownRenderer, with reliable front matter handling
  • A Gradle plugin exposing common transformations as cacheable, incremental tasks

It is not a static site generator. It is a document-processing library and build-tool integration layer — the Markdown equivalent of what a CSS post-processor does for stylesheets.

Design Decisions

Parser: commonmark-java

markflow uses commonmark-java as its parser and formatter. commonmark-java was chosen because:

  • It is actively maintained (Atlassian origin, used by OpenJDK, Google, Gerrit)
  • It is spec-compliant with CommonMark
  • It provides round-trip Markdown output via MarkdownRenderer
  • It supports GFM tables, YAML front matter (including raw/opaque capture), strikethrough, footnotes, and other common extensions out of the box
  • It is BSD 2-Clause licensed, compatible with all likely dependencies

Alternatives considered:

Flexmark-java was the original choice and has a richer extension ecosystem (TOC, definition lists, typographic quotes, etc.), but has been effectively unmaintained since 2023 with 178+ open issues. The maintenance risk outweighs the extension breadth for a library intended for long-term use.

JetBrains Markdown is actively developed but ruled out: its AST is largely immutable, it has no Markdown output support, and it targets Kotlin Multiplatform which is not a current requirement.

Front Matter: Opaque Capture via RawContentParser

commonmark-java's YamlFrontMatterExtension supports a RawContentParser mode that captures the entire front matter block as a single raw string rather than parsing it into key/value pairs. This means:

  • The MarkdownRenderer preserves front matter verbatim by default
  • Callers that need to inspect or modify front matter values do so via Jackson YAML, extracting the raw text, modifying it, and writing it back
  • No front matter content is silently dropped or reordered

Transformation Pipeline

Transformations are independent AST passes. Each pass is a MarkdownTransformer that receives a Document and returns a (possibly mutated) Document. Passes are composed into a MarkdownPipeline and applied in order. This keeps individual transformers small, testable, and independently togglable.

Module Structure

markflow/
library/ # Pure Kotlin library — no Gradle or Maven dependencies
gradle-plugin/ # Gradle plugin wrapping library tasks

library

The standalone Kotlin library JAR. Depends only on commonmark-java and Jackson YAML. No build-tool APIs. Usable from any JVM context: Gradle, Maven, a CLI, application code.

Key types:

TypeDescription
MarkdownDocumentA parsed document: mutable commonmark-java Document + raw front matter string
MarkdownParserParses a String or File into a MarkdownDocument
MarkdownTransformerSingle-responsibility AST transformation pass
MarkdownPipelineOrdered composition of MarkdownTransformer instances
MarkdownFormatterEmits a MarkdownDocument as Markdown (via MarkdownRenderer) or HTML (via HtmlRenderer)
FrontMatterTyped view of the front matter block via Jackson YAML

Built-in transformers:

TransformerDescription
TitlePromoterExtracts title: from front matter and prepends an H1 heading if none exists
HeadingDemoterIncrements all heading levels by a configurable offset (e.g. H1→H2)
TableFormatterPads GFM table columns to consistent widths
SentencePerLineFormatterSplits paragraph text at sentence boundaries, one sentence per line
TemplateSubstitutorReplaces {{key}} placeholders with provided values, skipping fenced code blocks
HtmlCommentExpanderExpands structured HTML comments to Markdown content via registered handlers

gradle-plugin

Plugin ID: net.oxspring.markflow

Exposes library functionality as cacheable, incremental Gradle tasks with @InputFiles / @OutputFiles annotations and UP-TO-DATE checking.

Tasks:

TaskDescription
ProcessMarkdownTaskApplies a configured pipeline to a set of input .md files, writing results to an output directory
MergeMarkdownTaskConcatenates multiple .md files (AST-level merge) into a single output file, with optional heading demotion per file
LintMarkdownTaskReports style violations (heading level skips, missing front matter fields, etc.) without modifying files

The plugin registers a markflow { } extension block for project-level configuration.

Package Namespace

net.oxspring.markflow

Sub-packages follow feature boundaries:

PackageContents
net.oxspring.markflowPublic API: MarkdownDocument, MarkdownParser, MarkdownPipeline, MarkdownFormatter
net.oxspring.markflow.transformBuilt-in MarkdownTransformer implementations
net.oxspring.markflow.frontmatterFrontMatter, front matter access utilities
net.oxspring.markflow.gradleGradle plugin and task implementations

MVP Scope (v1.0)

The v1.0 MVP targets feature parity with the custom Gradle tasks in the wtn monorepo, specifically:

Replaces ProcessGuideTask

ProcessGuideTask processes a directory of Hugo guide Markdown files, applying:

  • {{version}}, {{year}}, {{date}} token substitution (skipping fenced code blocks)
  • <!-- screenshot: name.png | alt text -->![alt](screenshots/name.png) expansion

markflow replaces this with a ProcessMarkdownTask configured with:

  • TemplateSubstitutor (token substitution, fence-aware)
  • HtmlCommentExpander with a screenshot handler

Replaces front matter title extraction in BuildPdfTask

BuildPdfTask reads title: from each file's YAML front matter and manually prepends `# Title

` before passing files to Pandoc. markflow replaces this with:

  • TitlePromoter transformer, promoting title: front matter to an H1 heading
  • MergeMarkdownTask concatenating pages in a declared order with a HeadingDemoter offset

Linting (new capability)

LintMarkdownTask enforces the guide's documented style rules:

  • One sentence per line (configurable)
  • Maximum line length (configurable, default 120)
  • No heading level skips
  • Required front matter fields (configurable)

Build & Test

./gradlew assemble # Compile all modules
./gradlew check # Tests + ktlint + Kover coverage verification
./gradlew build # assemble + check

Test framework: JUnit 6 (Jupiter) with AssertJ.

Key Dependencies

DependencyVersionLicense
commonmark-java0.30.xBSD 2-Clause
commonmark-ext-gfm-tables0.30.xBSD 2-Clause
commonmark-ext-yaml-front-matter0.30.xBSD 2-Clause
Jackson YAML2.xApache 2.0
Kotlin2.xApache 2.0
Gradle Plugin API9.xApache 2.0

License

Apache 2.0. See LICENSE.

About

Markdown processing utilities for use at build time.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - roxspring/markflow: Markdown processing utilities for use at build time. · GitHub
Skip to content

Repository files navigation

markflow

A Kotlin/JVM library and Gradle plugin for Markdown processing pipelines. Parse, transform, and emit Markdown (or HTML) with a composable, AST-based API.

Overview

markflow is built on commonmark-java and provides:

  • A clean Kotlin API for parsing Markdown into a mutable AST
  • Composable transformation passes (heading manipulation, front matter promotion, etc.)
  • Round-trip Markdown output via commonmark-java's MarkdownRenderer, with reliable front matter handling
  • A Gradle plugin exposing common transformations as cacheable, incremental tasks

It is not a static site generator. It is a document-processing library and build-tool integration layer — the Markdown equivalent of what a CSS post-processor does for stylesheets.

Design Decisions

Parser: commonmark-java

markflow uses commonmark-java as its parser and formatter. commonmark-java was chosen because:

  • It is actively maintained (Atlassian origin, used by OpenJDK, Google, Gerrit)
  • It is spec-compliant with CommonMark
  • It provides round-trip Markdown output via MarkdownRenderer
  • It supports GFM tables, YAML front matter (including raw/opaque capture), strikethrough, footnotes, and other common extensions out of the box
  • It is BSD 2-Clause licensed, compatible with all likely dependencies

Alternatives considered:

Flexmark-java was the original choice and has a richer extension ecosystem (TOC, definition lists, typographic quotes, etc.), but has been effectively unmaintained since 2023 with 178+ open issues. The maintenance risk outweighs the extension breadth for a library intended for long-term use.

JetBrains Markdown is actively developed but ruled out: its AST is largely immutable, it has no Markdown output support, and it targets Kotlin Multiplatform which is not a current requirement.

Front Matter: Opaque Capture via RawContentParser

commonmark-java's YamlFrontMatterExtension supports a RawContentParser mode that captures the entire front matter block as a single raw string rather than parsing it into key/value pairs. This means:

  • The MarkdownRenderer preserves front matter verbatim by default
  • Callers that need to inspect or modify front matter values do so via Jackson YAML, extracting the raw text, modifying it, and writing it back
  • No front matter content is silently dropped or reordered

Transformation Pipeline

Transformations are independent AST passes. Each pass is a MarkdownTransformer that receives a Document and returns a (possibly mutated) Document. Passes are composed into a MarkdownPipeline and applied in order. This keeps individual transformers small, testable, and independently togglable.

Module Structure

markflow/
library/ # Pure Kotlin library — no Gradle or Maven dependencies
gradle-plugin/ # Gradle plugin wrapping library tasks

library

The standalone Kotlin library JAR. Depends only on commonmark-java and Jackson YAML. No build-tool APIs. Usable from any JVM context: Gradle, Maven, a CLI, application code.

Key types:

TypeDescription
MarkdownDocumentA parsed document: mutable commonmark-java Document + raw front matter string
MarkdownParserParses a String or File into a MarkdownDocument
MarkdownTransformerSingle-responsibility AST transformation pass
MarkdownPipelineOrdered composition of MarkdownTransformer instances
MarkdownFormatterEmits a MarkdownDocument as Markdown (via MarkdownRenderer) or HTML (via HtmlRenderer)
FrontMatterTyped view of the front matter block via Jackson YAML

Built-in transformers:

TransformerDescription
TitlePromoterExtracts title: from front matter and prepends an H1 heading if none exists
HeadingDemoterIncrements all heading levels by a configurable offset (e.g. H1→H2)
TableFormatterPads GFM table columns to consistent widths
SentencePerLineFormatterSplits paragraph text at sentence boundaries, one sentence per line
TemplateSubstitutorReplaces {{key}} placeholders with provided values, skipping fenced code blocks
HtmlCommentExpanderExpands structured HTML comments to Markdown content via registered handlers

gradle-plugin

Plugin ID: net.oxspring.markflow

Exposes library functionality as cacheable, incremental Gradle tasks with @InputFiles / @OutputFiles annotations and UP-TO-DATE checking.

Tasks:

TaskDescription
ProcessMarkdownTaskApplies a configured pipeline to a set of input .md files, writing results to an output directory
MergeMarkdownTaskConcatenates multiple .md files (AST-level merge) into a single output file, with optional heading demotion per file
LintMarkdownTaskReports style violations (heading level skips, missing front matter fields, etc.) without modifying files

The plugin registers a markflow { } extension block for project-level configuration.

Package Namespace

net.oxspring.markflow

Sub-packages follow feature boundaries:

PackageContents
net.oxspring.markflowPublic API: MarkdownDocument, MarkdownParser, MarkdownPipeline, MarkdownFormatter
net.oxspring.markflow.transformBuilt-in MarkdownTransformer implementations
net.oxspring.markflow.frontmatterFrontMatter, front matter access utilities
net.oxspring.markflow.gradleGradle plugin and task implementations

MVP Scope (v1.0)

The v1.0 MVP targets feature parity with the custom Gradle tasks in the wtn monorepo, specifically:

Replaces ProcessGuideTask

ProcessGuideTask processes a directory of Hugo guide Markdown files, applying:

  • {{version}}, {{year}}, {{date}} token substitution (skipping fenced code blocks)
  • <!-- screenshot: name.png | alt text -->![alt](screenshots/name.png) expansion

markflow replaces this with a ProcessMarkdownTask configured with:

  • TemplateSubstitutor (token substitution, fence-aware)
  • HtmlCommentExpander with a screenshot handler

Replaces front matter title extraction in BuildPdfTask

BuildPdfTask reads title: from each file's YAML front matter and manually prepends `# Title

` before passing files to Pandoc. markflow replaces this with:

  • TitlePromoter transformer, promoting title: front matter to an H1 heading
  • MergeMarkdownTask concatenating pages in a declared order with a HeadingDemoter offset

Linting (new capability)

LintMarkdownTask enforces the guide's documented style rules:

  • One sentence per line (configurable)
  • Maximum line length (configurable, default 120)
  • No heading level skips
  • Required front matter fields (configurable)

Build & Test

./gradlew assemble # Compile all modules
./gradlew check # Tests + ktlint + Kover coverage verification
./gradlew build # assemble + check

Test framework: JUnit 6 (Jupiter) with AssertJ.

Key Dependencies

DependencyVersionLicense
commonmark-java0.30.xBSD 2-Clause
commonmark-ext-gfm-tables0.30.xBSD 2-Clause
commonmark-ext-yaml-front-matter0.30.xBSD 2-Clause
Jackson YAML2.xApache 2.0
Kotlin2.xApache 2.0
Gradle Plugin API9.xApache 2.0

License

Apache 2.0. See LICENSE.

About

Markdown processing utilities for use at build time.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); GitHub - roxspring/markflow: Markdown processing utilities for use at build time. · GitHub
Skip to content

Repository files navigation

markflow

A Kotlin/JVM library and Gradle plugin for Markdown processing pipelines. Parse, transform, and emit Markdown (or HTML) with a composable, AST-based API.

Overview

markflow is built on commonmark-java and provides:

  • A clean Kotlin API for parsing Markdown into a mutable AST
  • Composable transformation passes (heading manipulation, front matter promotion, etc.)
  • Round-trip Markdown output via commonmark-java's MarkdownRenderer, with reliable front matter handling
  • A Gradle plugin exposing common transformations as cacheable, incremental tasks

It is not a static site generator. It is a document-processing library and build-tool integration layer — the Markdown equivalent of what a CSS post-processor does for stylesheets.

Design Decisions

Parser: commonmark-java

markflow uses commonmark-java as its parser and formatter. commonmark-java was chosen because:

  • It is actively maintained (Atlassian origin, used by OpenJDK, Google, Gerrit)
  • It is spec-compliant with CommonMark
  • It provides round-trip Markdown output via MarkdownRenderer
  • It supports GFM tables, YAML front matter (including raw/opaque capture), strikethrough, footnotes, and other common extensions out of the box
  • It is BSD 2-Clause licensed, compatible with all likely dependencies

Alternatives considered:

Flexmark-java was the original choice and has a richer extension ecosystem (TOC, definition lists, typographic quotes, etc.), but has been effectively unmaintained since 2023 with 178+ open issues. The maintenance risk outweighs the extension breadth for a library intended for long-term use.

JetBrains Markdown is actively developed but ruled out: its AST is largely immutable, it has no Markdown output support, and it targets Kotlin Multiplatform which is not a current requirement.

Front Matter: Opaque Capture via RawContentParser

commonmark-java's YamlFrontMatterExtension supports a RawContentParser mode that captures the entire front matter block as a single raw string rather than parsing it into key/value pairs. This means:

  • The MarkdownRenderer preserves front matter verbatim by default
  • Callers that need to inspect or modify front matter values do so via Jackson YAML, extracting the raw text, modifying it, and writing it back
  • No front matter content is silently dropped or reordered

Transformation Pipeline

Transformations are independent AST passes. Each pass is a MarkdownTransformer that receives a Document and returns a (possibly mutated) Document. Passes are composed into a MarkdownPipeline and applied in order. This keeps individual transformers small, testable, and independently togglable.

Module Structure

markflow/
library/ # Pure Kotlin library — no Gradle or Maven dependencies
gradle-plugin/ # Gradle plugin wrapping library tasks

library

The standalone Kotlin library JAR. Depends only on commonmark-java and Jackson YAML. No build-tool APIs. Usable from any JVM context: Gradle, Maven, a CLI, application code.

Key types:

TypeDescription
MarkdownDocumentA parsed document: mutable commonmark-java Document + raw front matter string
MarkdownParserParses a String or File into a MarkdownDocument
MarkdownTransformerSingle-responsibility AST transformation pass
MarkdownPipelineOrdered composition of MarkdownTransformer instances
MarkdownFormatterEmits a MarkdownDocument as Markdown (via MarkdownRenderer) or HTML (via HtmlRenderer)
FrontMatterTyped view of the front matter block via Jackson YAML

Built-in transformers:

TransformerDescription
TitlePromoterExtracts title: from front matter and prepends an H1 heading if none exists
HeadingDemoterIncrements all heading levels by a configurable offset (e.g. H1→H2)
TableFormatterPads GFM table columns to consistent widths
SentencePerLineFormatterSplits paragraph text at sentence boundaries, one sentence per line
TemplateSubstitutorReplaces {{key}} placeholders with provided values, skipping fenced code blocks
HtmlCommentExpanderExpands structured HTML comments to Markdown content via registered handlers

gradle-plugin

Plugin ID: net.oxspring.markflow

Exposes library functionality as cacheable, incremental Gradle tasks with @InputFiles / @OutputFiles annotations and UP-TO-DATE checking.

Tasks:

TaskDescription
ProcessMarkdownTaskApplies a configured pipeline to a set of input .md files, writing results to an output directory
MergeMarkdownTaskConcatenates multiple .md files (AST-level merge) into a single output file, with optional heading demotion per file
LintMarkdownTaskReports style violations (heading level skips, missing front matter fields, etc.) without modifying files

The plugin registers a markflow { } extension block for project-level configuration.

Package Namespace

net.oxspring.markflow

Sub-packages follow feature boundaries:

PackageContents
net.oxspring.markflowPublic API: MarkdownDocument, MarkdownParser, MarkdownPipeline, MarkdownFormatter
net.oxspring.markflow.transformBuilt-in MarkdownTransformer implementations
net.oxspring.markflow.frontmatterFrontMatter, front matter access utilities
net.oxspring.markflow.gradleGradle plugin and task implementations

MVP Scope (v1.0)

The v1.0 MVP targets feature parity with the custom Gradle tasks in the wtn monorepo, specifically:

Replaces ProcessGuideTask

ProcessGuideTask processes a directory of Hugo guide Markdown files, applying:

  • {{version}}, {{year}}, {{date}} token substitution (skipping fenced code blocks)
  • <!-- screenshot: name.png | alt text -->![alt](screenshots/name.png) expansion

markflow replaces this with a ProcessMarkdownTask configured with:

  • TemplateSubstitutor (token substitution, fence-aware)
  • HtmlCommentExpander with a screenshot handler

Replaces front matter title extraction in BuildPdfTask

BuildPdfTask reads title: from each file's YAML front matter and manually prepends `# Title

` before passing files to Pandoc. markflow replaces this with:

  • TitlePromoter transformer, promoting title: front matter to an H1 heading
  • MergeMarkdownTask concatenating pages in a declared order with a HeadingDemoter offset

Linting (new capability)

LintMarkdownTask enforces the guide's documented style rules:

  • One sentence per line (configurable)
  • Maximum line length (configurable, default 120)
  • No heading level skips
  • Required front matter fields (configurable)

Build & Test

./gradlew assemble # Compile all modules
./gradlew check # Tests + ktlint + Kover coverage verification
./gradlew build # assemble + check

Test framework: JUnit 6 (Jupiter) with AssertJ.

Key Dependencies

DependencyVersionLicense
commonmark-java0.30.xBSD 2-Clause
commonmark-ext-gfm-tables0.30.xBSD 2-Clause
commonmark-ext-yaml-front-matter0.30.xBSD 2-Clause
Jackson YAML2.xApache 2.0
Kotlin2.xApache 2.0
Gradle Plugin API9.xApache 2.0

License

Apache 2.0. See LICENSE.

About

Markdown processing utilities for use at build time.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages