Common Setups
This page shows complete converter configurations for three common uses. Each one lists the settings it uses and why. Start from the one closest to your use case, and then change what you need.
Release Notes
To display release notes from GitHub in a browser, such as in a WordPress administrator screen:
$converter = new MarkdownConverter(
imageHosts: ['github.com', '*.githubusercontent.com'],
html: 'sanitize',
inlineStyles: true,
headingOffset: 4,
referenceLinks: true,
emoji: true,
);
imageHostsallows images from the hosts GitHub uses for pictures in release notes.htmlset to'sanitize'keeps a short list of tags that people commonly write in release notes, such asdetailsandkbd. See HTML.inlineStylesadds styles to tables, alerts, and code blocks, because the page that shows the notes has no stylesheet for them.headingOffsetset to4turns#into anh5and every deeper level into anh6, so headings in the notes don't compete with the headings of the page around them.referenceLinksreads links written as[text][label], which release notes generated from commit lists often use.emojishows names such as:bug:and:tada:as emoji, as GitHub does.
The default softBreak setting turns a single newline into a line break, which matches how GitHub shows release notes.
Documentation Pages
To display a documentation page, with links relative to the documentation and no line break at a single newline:
$converter = new MarkdownConverter(
softBreak: 'space',
baseUrl: 'https://example.com/docs',
imageHosts: ['example.com'],
html: 'sanitize',
setextHeadings: true,
referenceLinks: true,
indentedCode: true,
);
softBreakset to'space'joins the lines of a paragraph, as a README file does.baseUrljoins relative links and images to your documentation address.imageHostsallows images from your own host.setextHeadings,referenceLinks, andindentedCodeturn on older Markdown syntax that documentation written for other tools often uses.
Visitor Comments
To display comments from visitors, use the default settings:
$converter = new MarkdownConverter();
With the defaults, HTML shows as text, no image loads, and links can use only http, https, and mailto. Visitors can still write tables, alerts, and links.