mattcasters opened a new pull request, #7443:
URL: https://github.com/apache/hop/pull/7443
# Issue #7442 — Markdown preview: GFM table rendering
Recap for code reviewers.
## Summary
The Markdown file preview in the Hop file explorer
(`MarkDownExplorerFileTypeHandler.previewMarkdown()`) did not render GFM pipe
tables correctly. Tables appeared as plain paragraphs with literal `|`
characters instead of HTML `<table>` elements.
This change adds the required CommonMark extensions, registers them on the
parser and renderer, and adds table-specific CSS for both light and dark mode
previews.
## Problem
`previewMarkdown()` used the base CommonMark parser with no extensions:
```java
Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build();
```
CommonMark core does not support GFM tables. A report such as
`retail-dv-initial-report.md` (pipe tables with alignment markers like `---:`)
was parsed into eight `<p>| ... |</p>` blocks and zero `<table>` elements.
Headings, bold text, inline code, and lists rendered correctly; only
GFM-specific syntax was broken.
## Solution
### 1. Dependencies (`plugins/transforms/textfile/pom.xml`)
Three CommonMark extensions were added (all `provided` scope, version
`${commonmark.version}` = `0.29.0`):
| Artifact | Purpose |
|---|---|
| `commonmark-ext-gfm-tables` | Pipe tables and column alignment |
| `commonmark-ext-task-list-items` | `- [x]` / `- [ ]` task lists |
| `commonmark-ext-footnotes` | `[^1]` footnotes |
These match the existing pattern for `commonmark` core in the textfile
plugin.
### 2. Extension registration (`MarkDownExplorerFileTypeHandler.java`)
Extensions are configured once in a static list and passed to both builder
instances:
```java
private static final List<Extension> MARKDOWN_EXTENSIONS =
List.of(
TablesExtension.create(),
TaskListItemsExtension.create(),
FootnotesExtension.create());
Parser parser = Parser.builder().extensions(MARKDOWN_EXTENSIONS).build();
HtmlRenderer renderer =
HtmlRenderer.builder().extensions(MARKDOWN_EXTENSIONS).build();
```
Parser and HtmlRenderer are thread-safe when built this way, so the static
list is appropriate.
### 3. Table CSS in preview HTML
The inline preview stylesheet had no `table` rules. Shared layout rules were
added (full width, collapsed borders, padding, rounded corners), plus
mode-specific colors:
**Light mode**
- Table background: `#ffffff`
- Header background: `#f1f5f9`
- Borders: `#e2e8f0`
- Alternating rows: `#f8fafc`
**Dark mode**
- Table background: `#0f172a`
- Header background: `#1e293b`
- Borders: `#334155`
- Alternating rows: `#111827`
Colors follow the existing slate palette already used for body, code blocks,
and blockquotes.
## Files changed
| File | Change |
|---|---|
| `plugins/transforms/textfile/pom.xml` | +3 CommonMark extension
dependencies |
|
`plugins/transforms/textfile/src/main/java/.../MarkDownExplorerFileTypeHandler.java`
| Extension registration + table CSS |
**Diff size:** 2 files, +71 / −2 lines.
## Review focus
1. **Classpath / assembly** — Extension JARs use `provided` scope like
`commonmark` core. Confirm they are bundled into the Hop client distribution at
runtime (same mechanism as the existing `commonmark` dependency via the
textfile plugin).
2. **LICENSE** — If ASF release policy requires it, the static `LICENSE`
file may need entries for the three new extension artifacts (currently only
`commonmark` core is listed).
3. **Scope** — Only the explorer Markdown preview is updated.
`DocBuilder.markdownToHtml()` in `plugins/misc/documentation` still uses the
bare parser and would have the same table limitation if HTML doc generation is
expected to handle GFM tables.
4. **No new tests** — Existing `MarkDownExplorerFileTypeTest` covers
file-type metadata only, not preview rendering. Consider whether a small unit
test asserting `<table>` output for a pipe-table snippet is worth adding in a
follow-up.
## Manual verification
1. Build and start Hop GUI.
2. Open a `.md` file with GFM tables (e.g. a data-vault load report).
3. Click the preview toolbar button.
4. Confirm:
- Tables render as bordered HTML tables, not pipe-separated paragraphs.
- Header row has a distinct background.
- Alternating row shading is visible.
- Appearance is correct in both light and dark mode.
## Out of scope / known limitations
- No syntax highlighting for fenced code blocks (would need a separate
JS/CSS library).
- No `commonmark-ext-autolink` or `commonmark-ext-gfm-strikethrough` — bare
URLs and `~~strikethrough~~` still render as literal text.
- No `ul`/`ol` list styling added (lists were already readable).
- Documentation plugin HTML generation unchanged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]