linkrobins / markdown-widget
Markdown widget for fof/forum-widgets-core
Package info
github.com/linkrobins/markdown-widget
Type:flarum-extension
pkg:composer/linkrobins/markdown-widget
Requires
- php: ^8.3
- flarum/core: ^2.0
- fof/forum-widgets-core: ^2.0.0-beta.3
Requires (Dev)
- flarum/phpstan: ^2.0
- flarum/testing: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A simple Markdown widget for Flarum 2.0, built as a widget for fof/forum-widgets-core. If you would rather write raw HTML, see linkrobins/html-widget.
What it does
Adds one configurable Markdown widget to the FoF Forum Widgets placement editor. Admin sets:
- Title — optional, shown above the body
- Description: optional small text under the title
- Icon — FontAwesome class (e.g.
fab fa-markdown) - Markdown body — standard GitHub-flavored Markdown, rendered to HTML on the client
Drag and place it from the FoF Forum Widgets admin page like any other widget.
Settings
Configured in the admin panel's Extensions page → LR Markdown Widget, then placed from the FoF Forum Widgets page.
| Setting | Required | What it does |
|---|---|---|
| Title | no | Shown above the body. Leave blank for a widget with no header. |
| Description | no | Small text under the title, in the same style as other FoF widgets' descriptions. |
| Icon class | no | A FontAwesome class rendered beside the title, e.g. fab fa-markdown. Leave blank for no icon. |
| Markdown body | yes | GitHub-flavored Markdown. Inline HTML is allowed but sanitized. |
| Background color | no | The widget's background. Leave blank to follow your theme, which is what keeps it looking native in both light and dark mode. |
How a change reaches readers
The body is not baked into the forum's boot payload. It is fetched from its own endpoint on demand, and only a short hash of the current settings rides along in the payload.
That hash is what makes an edit show up: changing any setting changes the hash, which changes the fetch URL, so a normal page reload picks up the new content. Readers do not need a hard refresh, and unchanged content is cached for a few minutes rather than being re-fetched on every page view.
Private forums
If guests can't view your forum, they don't get the widget's content either: it is only sent to visitors who can view the forum, the same as your discussions. There are no permissions of its own to set.
What it does NOT do
- One widget per forum, not a list of them. For several blocks of content, place several different widgets.
- No per-tag or per-page targeting — placement is whatever FoF Forum Widgets gives it.
- If you would rather write raw HTML, use
linkrobins/html-widgetinstead.
Requirements
- Flarum 2.0 or later
fof/forum-widgets-coreinstalled and enabled
The Markdown renderer (marked) and the HTML sanitizer (DOMPurify) are bundled into the extension — nothing is fetched from a CDN at runtime.
Installation
composer require linkrobins/markdown-widget
In the admin panel's Extensions page, find LR Markdown Widget under the Forum Widgets category and switch it on. Configure title/icon/body, then go to FoF Forum Widgets settings and place it where you want it.
To update later: composer update linkrobins/markdown-widget, then php flarum cache:clear.
Markdown features
Supports the full Markdown syntax that marked.js handles, including:
- Headings (
# H1,## H2, ...) - Bold (
**bold**) and italic (*italic*) - Lists (ordered and unordered)
- Links and images
- Code spans and fenced code blocks
- Blockquotes
- Tables (GFM)
- Horizontal rules
- Inline HTML (sanitized before display)
The widget styles headings, lists, code, blockquotes, and tables to fit cleanly in any placement.
Security note
The rendered HTML is passed through DOMPurify before display, so <script> tags, event-handler attributes, and other unsafe markup in the Markdown body are stripped. The body is still admin-only — treat it like any other admin-controlled content.
License
MIT