Skip to content

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.

Three-phase pipeline: Input (BBCode / HTML / MediaWiki / XML) → AST (Document tree) → Discourse Markdown Three-phase pipeline: Input (BBCode / HTML / MediaWiki / XML) → AST (Document tree) → Discourse Markdown

Every conversion has three steps:

  1. 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.
  2. 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.
  3. 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.

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.