Introduction
Markbridge is a Ruby library that converts BBCode, HTML, MediaWiki wikitext, and s9e\TextFormatter XML to Markdown. You can convert one document or millions of forum posts. You can also look at the parsed content and change how it is written.
Every conversion has three steps:
- Parse. A parser for your format reads the input and builds a tree, the AST. It never raises on bad markup. Tags it does not know are counted, so you can review them.
- Normalize. Markup can nest things that Markdown cannot, like a link inside a link or a list inside bold. This step rewrites those parts of the tree.
- Render. The renderer walks the tree and writes Markdown.
The tree has the same node types for every input format, and nothing in it knows about Markdown. The renderer that ships with Markbridge writes Markdown for Discourse. You can write your own renderer for the same tree.
When to use it
Section titled “When to use it”Use Markbridge when you have content in one of the four formats and need it as Markdown, or when you want to work with its structure: find all links, replace images, drop colors.
Migrating a forum to Discourse is the main use case, and Markbridge has what such a migration needs:
- A count of the tags no parser handler knew, per post.
- Errors per post instead of a failed run.
- Your own AST nodes for uploads, users and topics, which your importer resolves later.
The migration guide explains that workflow.
Find your way around
Section titled “Find your way around”- Get started installs the gem and runs a first conversion.
- Format guides list what each parser reads and what it becomes.
- Customization covers the renderer options and your own tags and handlers.
- Concepts explains the AST, the parsers, the renderer and performance.
- Migrating to Discourse is the workflow for a forum migration.