View · Search · Index

Markdown editing with richtext-markdown

The richtext-markdown package adds Markdown editing with Write and Preview tabs to OpenACS richtext fields. Authors write Markdown while applications continue to receive an HTML snippet, suitable for existing display and search workflows.

What the editor does

  • Marked renders Markdown, including common GitHub-style constructs such as lists, fenced code blocks and tables.
  • DOMPurify sanitizes the generated HTML.
  • Turndown converts legacy HTML into an editable Markdown representation. Preformatted code and XoWiki references are preserved; structures such as HTML tables may remain HTML when that better preserves their content.
  • Automatic format conversion turns existing Enhanced Text, Plain Text and Fixed-width Text into editable Markdown when the author selects HTML to activate the editor. Fixed-width text becomes a fenced code block.
  • A source comment accompanies generated HTML so reopening an entry can recover the original Markdown rather than reconstruct it from HTML. If an existing HTML body is unchanged, its original HTML is preserved.
  • The toolbar uses the site's normal button rendering. Textarea size and theme classes can be supplied through the usual widget configuration.

This HTML-backed editor is distinct from the Markdown Text MIME choice, which stores text/markdown. Selecting that format does not by itself activate this widget.

Installation and versions

Install richtext-markdown through the Package Manager. It is currently a preview package. The shared format-selector integration described below is available with these versions or newer:

Package Version
ACS Templating 6.0.0d12
ACS Subsite 6.0.0d7
Forums 1.4.3d1
News 6.0.0d2
XoWiki 6.0.0d10

Use the application versions above for the integrations you need; installing the editor does not require enabling it in every application. Upgrade package metadata as well as Tcl files so the new instance parameters are registered. Reload changed Tcl libraries or restart the server when deploying the updated packages.

The package's sitewide administration page shows configured library versions, CDN/local status, registered resource URNs, download controls and links for version pinning and vulnerability information. Merely opening that page does not install the libraries locally. See also Managing Versions of External JavaScript Libraries.

Classical ACS Templating: select the editor for one field

An application can explicitly select Markdown in its ad_form specification, without enabling richtext editing throughout the site:

ad_form -name example -form {
    {body:richtext(richtext),optional
        {label Body}
        {htmlarea_p 1}
        {options {editor markdown}}
        {html {rows 24 cols 80}}
    }
} -on_submit {
    set contents [template::util::richtext::get_property contents $body]
    set mime_type [template::util::richtext::get_property format $body]
    # Save contents and mime_type through the application's existing API.
}

Render the form in the ADP template as usual:

<formtemplate id="example"></formtemplate>

The explicit htmlarea_p 1 enables the editor for this field even when ACS Templating's UseHtmlAreaForRichtextP is disabled. editor markdown selects the plugin independently of the site default. When loading an existing value, provide the normal richtext pair consisting of its content and stored MIME type. On submission, save both returned properties; do not assume the body is raw Markdown or hardcode a different format.

Keep the format selector and activate only for HTML

For a field that should initially offer the standard format choices, use this options entry instead:

{options {editor markdown format_selector 1}}

Keep htmlarea_p 1 in the field specification. The selector remains visible. HTML activates Write/Preview; Enhanced Text, Markdown Text, Plain Text and Fixed-width Text retain their normal editing and storage semantics until the author chooses HTML. An explicit htmlarea_p 0 disables editor activation for that field.

XoWiki

XoWiki has its own editor selection, separate from ACS Templating's site defaults. Set XoWiki's global package parameter PreferredRichtextEditor to markdown to use it as the default XoWiki richtext editor.

Select the editor for a form field

XoWiki provides ::xowiki::formfield::richtext::markdown as an editor class for richtext form fields. Select it through editor=markdown in a form's Form constraints, for example:

_text:richtext,editor=markdown,rows=24

Here _text is the body field used by a typical XoWiki FormPage; use the appropriate field name for other richtext fields. This gives Write/Preview editing with a 24-line textarea while retaining HTML as the stored content. The explicit editor choice works independently of the XoWiki default and does not require enabling site-wide richtext.

With XoWiki 6.0.0d10 or newer, the default menubar also provides New → Markdown Page when richtext-markdown is installed. It uses a dedicated Markdown form. See XoWiki: Customizing the menubar for folder menu configuration.

Increase the height for ordinary wiki pages

For the classical wiki page editor, use the XoWiki instance's WidgetSpecs setting. For example, on a Bootstrap-themed site:

*,text {richtext(richtext),nospell,optional
    {label Content}
    {htmlarea_p 1}
    {options {editor markdown}}
    {html {rows 24 class form-control}}
}

WidgetSpecs is a Tcl list of alternating pattern/specification pairs. The widget type must immediately follow the specification's opening brace, as shown: a leading newline there produces a different first token. Do not wrap the entire parameter value in another pair of braces.

The first matching specification wins. Modify an existing *,text entry, or put a page-specific entry such as en:require-post,text before the wildcard entry. Retain other options required by the installation. form-control supplies the normal Bootstrap styling and full width; adapt the class for another theme. Form-based pages use their form constraints, such as the rows=24 example above.

Activate News and Forums without enabling site-wide richtext

Do not change ACS Templating's default editor or turn on its site-wide UseHtmlAreaForRichtextP setting merely to enable News or Forums. Instead, open the Parameters page for the particular package instance and set:

RichTextEditor = markdown

To keep site-wide richtext disabled, leave ACS Templating's UseHtmlAreaForRichtextP at 0. Its default RichTextEditor can retain its existing value. The package-instance setting supplies the editor for News or Forums without changing those site defaults.

Configure the News and Forums instances separately. The new parameter's empty default preserves the existing ACS Templating behavior. Setting it to markdown lets the shared richtext widget select this editor for fields in that instance; explicit field options take precedence.

The author workflow is:

  1. Open a new post, reply, news article or revision. The textarea and format selector remain available for non-HTML content.
  2. Select HTML to activate the Markdown editor without reloading the page.
  3. Write Markdown, use Preview, and submit through the application's normal form.

Existing HTML entries open directly in the editor. When an author switches an existing Enhanced Text, Plain Text or Fixed-width Text draft to HTML, OpenACS converts the original format to HTML and Turndown derives the Markdown for editing. Existing Markdown Text uses Marked directly and preserves its exact Markdown source. Fixed-width text becomes a fenced code block.

Switching between formats retains a separate draft for each choice while the form remains open; only the currently selected draft is submitted. If conversion fails, the original text and format remain selected. These settings do not rewrite existing database entries or force Markdown on every new post.

Scope of this recipe

This recipe covers text editing, format conversion and per-field/per-instance activation. Image-paste and attachment integration are separate application work and are not required for these instructions. The editor's sanitized HTML remains subject to the application's normal permissions and content handling.

previous November 2026
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 (4) 25 26 27 28
29 30 1 2 3 4 5

Popular tags

17 , 5.10 , 5.10.0 , 5.10.1 , 5.9.0 , 5.9.1 , ad_form , ADP , ajax , aolserver , asynchronous , Azure , bgdelivery , bootstrap , bugtracker , CentOS , COMET , compatibility , conference , CSP , CSRF , cvs , debian , docker , docker-compose , emacs , engineering-standards , exec , fedora , FreeBSD
1 registered user in community xowiki
in last 30 minutes
Contributors

OpenACS.org