how-to · 7 min read
A content and data handoff: HTML, Markdown, PDF, XML and JSON
A handoff is rarely one conversion. The same copy has to exist as a help page, Markdown in a repository and a PDF for a client, while an integration exchanges XML and JSON. Each step keeps some information and drops the rest, so the job is to choose one source, convert deliberately and check the artifact before anyone depends on it.
This guide follows that path and ends with the validation and review points that catch the usual mistakes. The conversions described here run in the browser with the tools in this collection, and the limits quoted are the limits those tools enforce.
Map the handoff before converting anything
List what the team receives, what it must deliver and which artifact may be edited. In the classic case a docs team inherits an HTML help page, the repository needs Markdown, the client needs a PDF, and a partner needs XML for one endpoint and JSON for another. Five deliverables, but only one should be the source of truth.
Choose that source deliberately and treat generated files as read-only. If the HTML is the only complete copy, regenerate Markdown from it; if writers will maintain the Markdown, regenerate the PDF on every release. Editing a generated artifact means the next regeneration silently discards the change.
- HTML help page: received from the vendor, canonical until the Markdown migration is signed off.
- Markdown: the editable source in the repository after migration.
- PDF: generated client render, never edited and never used as the source.
- XML: the partner's format for the legacy endpoint.
- JSON: the same data for the modern endpoint, validated separately.
HTML to Markdown: keep the structure, drop the styling
HTML carries scripts, styles, layout and media; Markdown keeps only the structure that survives as plain text. Headings, paragraphs, lists, links, images, code, blockquotes and simple tables have equivalents; colors, fonts, grids, widgets and inline styles do not. Scripts, styles and iframes are removed before conversion and reported as warnings.
A typical converter uses a library such as turndown; the HTML to Markdown tool here parses the markup with the browser's DOM parser and writes Markdown directly, with the same trade-offs. Review the warnings first, then the lossy places: nested tables, multi-line cells, code that looks like Markdown, and links or images pointing at remote URLs. The input is capped at 10 MB, and the output should be diffed against the repository version.
Markdown to PDF: a render target, not a source
Markdown is written to be edited; a PDF is written to be read. The conversion parses Markdown with marked, paginates it and writes real text with jsPDF, so the PDF stays selectable and searchable. Page size can be A4 or Letter, margins range from narrow to wide, and the body text can be scaled; long code lines wrap or are truncated.
The layout is deliberately simple: one column, one body font plus Courier for code, no custom fonts, colors or embedded images. Images become an [image: alt] placeholder because remote files are not fetched, emphasis is flattened, and tables get equal-width columns with a repeated header when they span pages. Regenerate the PDF from Markdown after every change; the Markdown input is capped at 5 MB and the result reports a page count.
XML and JSON: one tree, two encodings
XML and JSON describe the same tree with different syntax. A converter must decide what attributes mean in JSON, what text in an element with children means, and how repeated elements become arrays. The XML to JSON tool uses one predictable mapping: attributes become @ keys, text in an element that also has attributes or children goes under #text, repeated children become arrays, and namespaces keep their prefixes and xmlns attributes.
Options cover the small decisions: the attribute prefix can change when a consumer reserves @, and arrays can appear only for repeated children or for every child when a downstream schema expects lists. The JSON to XML tool reverses the mapping, with a configurable root element, @ keys as attributes and sanitised names for keys that are not valid XML names.
Round trips are not byte-for-byte. Comments, processing instructions and the doctype are ignored, text is trimmed, mixed content is aggregated, and a single-element array can return as a scalar. The mapping is not schema-aware, so a well-formed document can still break the partner's contract. Both tools accept up to 10 MB of text.
When to validate, and with which step
Validate at the boundaries, not at the end of the pipeline. Check the input first: HTML parses, XML is well formed, JSON parses. A converter that receives broken input either fails with a position or produces a plausible artifact from a partial parse.
The XML formatter and validator checks well-formedness with DOMParser and reports the parser message with a line and column. It is a syntax check only: it does not validate against XSD, DTD or Relax NG, so use a schema validator for the partner's contract. For JSON, the JSON formatter reports where parsing failed, which catches trailing commas, comments, single quotes and unclosed brackets, but not types or required fields.
The second boundary is the generated artifact. After XML to JSON, confirm the JSON parses and spot-check the expected shapes; after JSON to XML, re-check the generated XML as XML. The tool already parses its own output with DOMParser, and running the XML formatter over it is a cheap second opinion.
Formatting is not validation
The HTML, CSS and JavaScript formatters use Prettier standalone, loaded only when you press Format or Minify. Prettier parses and reprints the file with consistent indentation, quotes and line breaks, which makes review and diffs easier and removes whitespace noise from commits.
It does not make the file correct. Prettier reports syntax it cannot parse, but it is not a linter, type checker or schema validator: it will not say that a selector is ineffective, an attribute is deprecated or a JSON contract is violated. Those need separate tools and, for behavior, tests.
Minify needs its own warning. The HTML minifier collapses whitespace between tags, so markup that relies on inline spacing can render differently; the JavaScript minifier removes comments and whitespace but does not rename variables or remove dead code. Keep a diff between the formatted source and what is committed, and keep unminified comments when they are documentation.
The handoff checklist
Most handoff failures are process failures rather than converter bugs: two people editing different versions, a secret in an exported page, an encoding mix-up, or an artifact nobody reviewed because the conversion looked fine. Run this list at the end of every release and treat deviations as deliberate decisions.
- One canonical source is named; every other format is regenerated from it, not edited.
- The HTML input parses, scripts and styles are stripped, and removed elements are reviewed.
- Markdown changes are diffed; tables, code blocks and links are checked by hand.
- The PDF is generated from the final Markdown, uses the agreed page size and margins, and the page count is checked.
- XML is well formed and, when a contract exists, schema-validated outside this collection.
- JSON parses, and converted XML or JSON output is re-checked in the target format before sending.
- Encoding is UTF-8 end to end, no credentials are present, and files stay within the limits: 10 MB for HTML, XML and JSON conversions and 5 MB for Markdown to PDF.
- The options used (attribute prefix, array mode, root name, page size, font scale) are recorded with the release.

