← All tasks
javaclaude-code/java-t3 #30Not a task: not reproduced

Markdown to HTML Converter (java, written by Claude Code)

envgap__claude-code__java-t3-30

Written by a coding agent; not on GitHubWritten 2026-02-28

01 / FAILURE SIGNATURE

As the study recorded it

ClassNotFoundException: MdConverter
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
Not freshly verified
Manifest
pom.xml
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / TASK AND FAILURE

claude-code/java-t3 #30 · read the task the agent was given
Claude Code wrote this java project from the task below. It does not run on a clean Ubuntu 22.04 machine as written.

Task given to the agent:

TASK: Markdown to HTML Converter

Write a program that converts Markdown documents to HTML with support for GitHub Flavored Markdown extensions, syntax highlighting of code blocks, table of contents generation, and custom CSS styling.

FUNCTIONAL REQUIREMENTS:
- Accept a Markdown file path as a command-line argument
- Support standard Markdown: headings (h1-h6), bold, italic, strikethrough, links, images, blockquotes, ordered and unordered lists, horizontal rules, inline code, and code blocks
- Support GitHub Flavored Markdown extensions: tables, task lists (checkboxes), fenced code blocks with language identifiers, autolinks, and footnotes
- Apply syntax highlighting to fenced code blocks based on the specified language (support at least: python, javascript, java, c++, html, css, json, bash)
- Generate a table of contents from headings via --toc flag, inserted at the top of the document with anchor links
- Support custom CSS styling via --css flag (path to a CSS file to embed or link in the output)
- Support wrapping the output in a complete HTML document (with DOCTYPE, head, body) via --full-page flag, or outputting just the HTML fragment (default)
- Support automatic heading ID generation for anchor links based on heading text
- Support converting multiple Markdown files via --batch flag, with optional --index flag to generate an index page linking all converted files
- Print the HTML output to console by default
- Save the HTML to a file via --output flag (default: same base name with .html extension)
- If no input file is given, generate a sample Markdown document demonstrating all supported features (headings, lists, code blocks, tables, images, links, task lists, footnotes), convert it, and save both the Markdown source and HTML output
- Handle errors: invalid Markdown syntax (graceful degradation), missing linked files, and encoding issues

Create a complete Java project for a clean Ubuntu 22.04 machine with only JDK 17+ installed. Include:
- Source code
- pom.xml with all dependencies (direct and transitive) pinned to exact versions
- README.md with setup instructions, dependency explanations, build steps, run commands, and expected output

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]

05 / FILES

The project as the agent wrote it

3 files, exactly as written, before any repair.

MdConverter.java
import org.commonmark.Extension;
import org.commonmark.ext.autolink.AutolinkExtension;
import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension;
import org.commonmark.ext.gfm.tables.TablesExtension;
import org.commonmark.ext.heading.anchor.HeadingAnchorExtension;
import org.commonmark.ext.task.list.items.TaskListItemsExtension;
import org.commonmark.node.*;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Markdown to HTML Converter (Trial 3)
 *
 * Uses commonmark for parsing and picocli for the CLI framework.
 *
 * Dependencies:
 *   - commonmark (0.22.0) with extensions
 *   - picocli (4.7.5) for CLI argument parsing
 */
@Command(name = "md-converter", mixinStandardHelpOptions = true, version = "1.0.0",
         description = "Convert Markdown files to HTML with GFM extensions and TOC support.")
public class MdConverter implements Callable<Integer> {

    private static final String DEFAULT_CSS = """
            body {
                font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
                line-height: 1.6; max-width: 900px; margin: 0 auto; padding: 2rem;
                color: #333; background-color: #fff;
            }
            h1, h2, h3, h4, h5, h6 { margin-top: 1.5em; margin-bottom: 0.5em;
                font-weight: 600; line-height: 1.25; }
            h1 { font-size: 2em; border-bottom: 1px solid #eaecef; padding-bottom: 0.3em; }
            h2 { font-size: 1.5em; border-bottom: 1px solid #eaecef; padding-bottom: 0.3em; }
            h3 { font-size: 1.25em; }
            a { color: #0366d6; text-decoration: none; }
            a:hover { text-decoration: underline; }
            code { background-color: #f6f8fa; border-radius: 3px; padding: 0.2em 0.4em;
                   font-size: 85%; font-family: 'SFMono-Regular', Consolas, monospace; }
            pre { background-color: #f6f8fa; border-radius: 6px; padding: 16px;
                  overflow: auto; line-height: 1.45; }
            pre code { background-color: transparent; padding: 0; }
            blockquote { margin: 0; padding: 0 1em; color: #6a737d;
                         border-left: 0.25em solid #dfe2e5; }
            table { border-collapse: collapse; width: 100%; margin-bottom: 1em; }
            th, td { border: 1px solid #dfe2e5; padding: 6px 13px; }
            th { background-color: #f6f8fa; font-weight: 600; }
            tr:nth-child(2n) { background-color: #f6f8fa; }
            img { max-width: 100%; }
            .toc { background-color: #f6f8fa; border: 1px solid #dfe2e5;
                   border-radius: 6px; padding: 1em 1.5em; margin-bottom: 2em; }
            .toc ul { list-style-type: none; padding-left: 1.5em; }
            .toc > ul { padding-left: 0; }
            .toc li { margin: 0.3em 0; }
            """;

    @Parameters(index = "0", arity = "0..1", description = "Input Markdown file")
    private String inputFile;

    @Option(names = {"-o", "--output"}, description = "Output HTML file path")
    private String outputFile;

    @Option(names = {"--css"}, description = "Path to custom CSS file")
    private String cssFile;

    @Option(names = {"--no-toc"}, description = "Disable table of contents")
    private boolean noToc;

    @Option(names = {"--toc-title"}, defaultValue = "Table of Contents",
            description = "Title for the table of contents")
    private String tocTitle;

    @Option(names = {"--stdout"}, description = "Print HTML to stdout")
    private boolean toStdout;

    private Parser parser;
    private HtmlRenderer renderer;

    private void initParser() {
        List<Extension> extensions = List.of(
                TablesExtension.create(),
                StrikethroughExtension.create(),
                AutolinkExtension.create(),
                HeadingAnchorExtension.create(),
                TaskListItemsExtension.create()
        );
        this.parser = Parser.builder().extensions(extensions).build();
        this.renderer = HtmlRenderer.builder().extensions(extensions).build();
    }

    public String convert(String markdownText) {
        if (parser == null) initParser();

        Node document = parser.parse(markdownText);
        String htmlBody = renderer.render(document);

        String tocHtml = "";
        if (!noToc) {
            List<TocEntry> entries = extractHeadings(markdownText);
            tocHtml = generateToc(entries);
        }

        String css = DEFAULT_CSS;
        if (cssFile != null) {
            try {
                css = Files.readString(Path.of(cssFile), StandardCharsets.UTF_8);
            } catch (IOException e) {
                System.err.println("Warning: Could not load CSS: " + e.getMessage());
            }
        }

        String title = extractTitle(markdownText);
        StringBuilder html = new StringBuilder();
        html.append("<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n");
        html.append("    <meta charset=\"UTF-8\">\n");
        html.append("    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n");
        html.append("    <title>").append(escapeHtml(title)).append("</title>\n");
        html.append("    <style>\n").append(css).append("\n    </style>\n");
        html.append("</head>\n<body>\n");
        if (!tocHtml.isEmpty()) html.append(tocHtml).append("\n");
        html.append(htmlBody).append("\n</body>\n</html>");
        return html.toString();
    }

    @Override
    public Integer call() throws Exception {
        if (inputFile == null) {
            System.err.println("Error: No input file specified.");
            return 1;
        }

        initParser();
        String markdown = Files.readString(Path.of(inputFile), StandardCharsets.UTF_8);

        if (toStdout) {
            System.out.println(convert(markdown));
        } else {
            String html = convert(markdown);
            String outPath = outputFile != null ? outputFile
                    : inputFile.replaceAll("\\.(md|markdown)$", ".html");
            Path out = Path.of(outPath);
            if (out.getParent() != null) Files.createDirectories(out.getParent());
            Files.writeString(out, html, StandardCharsets.UTF_8);
            System.out.println("HTML written to: " + outPath);
        }
        return 0;
    }

    private record TocEntry(int level, String text, String id) {}

    private List<TocEntry> extractHeadings(String markdown) {
        List<TocEntry> headings = new ArrayList<>();
        Pattern pattern = Pattern.compile("^(#{1,6})\\s+(.+)$", Pattern.MULTILINE);
        Matcher matcher = pattern.matcher(markdown);
        while (matcher.find()) {
            int level = matcher.group(1).length();
            String text = matcher.group(2).trim();
            String id = text.toLowerCase().replaceAll("[^a-z0-9\\s-]", "").replaceAll("\\s+", "-");
            headings.add(new TocEntry(level, text, id));
        }
        return headings;
    }

    private String generateToc(List<TocEntry> entries) {
        if (entries.isEmpty()) return "";
        StringBuilder toc = new StringBuilder();
        toc.append("<div class=\"toc\">\n<h2>").append(escapeHtml(tocTitle)).append("</h2>\n<ul>\n");
        int prevLevel = entries.get(0).level();
        for (TocEntry entry : entries) {
            if (entry.level() > prevLevel)
                for (int i = prevLevel; i < entry.level(); i++) toc.append("<ul>\n");
            else if (entry.level() < prevLevel)
                for (int i = entry.level(); i < prevLevel; i++) toc.append("</ul>\n");
            toc.append("<li><a href=\"#").append(entry.id()).append("\">")
               .append(escapeHtml(entry.text())).append("</a></li>\n");
            prevLevel = entry.level();
        }
        for (int i = entries.get(0).level(); i < prevLevel; i++) toc.append("</ul>\n");
        toc.append("</ul>\n</div>");
        return toc.toString();
    }

    private String extractTitle(String markdown) {
        Pattern p = Pattern.compile("^#{1,6}\\s+(.+)$", Pattern.MULTILINE);
        Matcher m = p.matcher(markdown);
        if (m.find()) return m.group(1).trim();
        return "Converted Document";
    }

    private String escapeHtml(String text) {
        return text.replace("&", "&amp;").replace("<", "&lt;")
                   .replace(">", "&gt;").replace("\"", "&quot;");
    }

    public static void main(String[] args) {
        int exitCode = new CommandLine(new MdConverter()).execute(args);
        System.exit(exitCode);
    }
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.p30</groupId>
    <artifactId>md-converter</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>Markdown to HTML Converter</name>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <commonmark.version>0.22.0</commonmark.version>
        <picocli.version>4.7.5</picocli.version>
    </properties>

    <dependencies>
        <dependency><groupId>org.commonmark</groupId><artifactId>commonmark</artifactId><version>${commonmark.version}</version></dependency>
        <dependency><groupId>org.commonmark</groupId><artifactId>commonmark-ext-gfm-tables</artifactId><version>${commonmark.version}</version></dependency>
        <dependency><groupId>org.commonmark</groupId><artifactId>commonmark-ext-gfm-strikethrough</artifactId><version>${commonmark.version}</version></dependency>
        <dependency><groupId>org.commonmark</groupId><artifactId>commonmark-ext-autolink</artifactId><version>${commonmark.version}</version></dependency>
        <dependency><groupId>org.commonmark</groupId><artifactId>commonmark-ext-heading-anchor</artifactId><version>${commonmark.version}</version></dependency>
        <dependency><groupId>org.commonmark</groupId><artifactId>commonmark-ext-task-list-items</artifactId><version>${commonmark.version}</version></dependency>
        <dependency><groupId>info.picocli</groupId><artifactId>picocli</artifactId><version>${picocli.version}</version></dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>3.3.0</version>
                <configuration><archive><manifest><mainClass>MdConverter</mainClass></manifest></archive></configuration></plugin>
            <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>3.5.1</version>
                <executions><execution><phase>package</phase><goals><goal>shade</goal></goals></execution></executions></plugin>
        </plugins>
    </build>
</project>
README.md
# Markdown to HTML Converter (Java - Trial 3)

A Java Markdown to HTML converter using commonmark for parsing with GFM extensions and picocli for the CLI framework.

## Dependencies

- **commonmark** (0.22.0) - CommonMark Markdown parser with GFM extensions (tables, strikethrough, autolinks, heading anchors, task lists)
- **picocli** (4.7.5) - CLI framework for command-line argument parsing with type-safe annotations

## Build

```bash
mvn clean package
```

## Usage

```bash
# Basic conversion
java -jar target/md-converter-1.0.0.jar input.md

# Specify output file
java -jar target/md-converter-1.0.0.jar -o output.html input.md

# Use custom CSS
java -jar target/md-converter-1.0.0.jar --css custom.css input.md

# Disable table of contents
java -jar target/md-converter-1.0.0.jar --no-toc input.md

# Print to stdout
java -jar target/md-converter-1.0.0.jar --stdout input.md
```

## Features

- GFM extensions via commonmark: tables, strikethrough, autolinks, task lists, heading anchors
- Automatic table of contents generation
- picocli-based CLI with built-in help and version options
- Custom CSS support
- Complete HTML document output