View · Search · Index

Weblog

Filtered by date 2026-11-27, 1 of 1 Postings (all, summary)

Markdown editing with richtext-markdown

Created by Gustaf Neumann, last modified by Gustaf Neumann 8 hours 36 minutes ago

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.
  • Image paste in XoWiki stages images for Preview and saves them as child File items, preserving them in page export/import and XoWiki clipboard operations. Native wiki image markup provides labels and sizing.
  • Image paste in Forums and News uploads PNG, JPEG and GIF images for private Preview, then saves them as attachments. Administrators enable this separately from editor selection; pasted images support editable display widths and responsive delivery.
  • 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. For the integrations described below, including image paste in XoWiki, Forums and News, use these versions or newer:

Package Version
richtext-markdown 0.1d3
ACS Kernel 6.0.0d10
ACS Tcl 6.0.0d15
ACS Templating 6.0.0d12
ACS Subsite 6.0.0d7
Attachments 0.14.2
Forums 1.4.3d2
News 6.0.0d3
XoWiki 6.0.0d11

Use the application versions above for the integrations you need. 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 ACS Kernel upgrade adds srcset and sizes to the allowed HTML attributes; restart after that upgrade to clear cached parameter values.

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. The rows=24 option sets a 24-line textarea; the explicit editor choice overrides the XoWiki default.

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.

Paste images into XoWiki pages

With XoWiki 6.0.0d11 or newer, select the Markdown editor as described above, open a new or existing page, and paste a PNG, JPEG or GIF image into the Write tab. The normal page creation and editing permissions apply. There is no separate XoWiki image-paste switch corresponding to the Forums controls or News' AllowImagePasteP parameter.

Images pasted into a new page are staged privately until the page is saved, and Preview can display them before the first save. On save, XoWiki stores each image as a child File item of the page. These are native XoWiki child resources, rather than files stored through the Attachments service. Deleting the page deletes its child images. Page export/import and XoWiki clipboard copy/paste include the child files, so the images travel with the page when it is moved between folders or instances using those operations.

The saved reference uses XoWiki's portable child-image markup. Keep the generated filename, and add a label and width option to control its appearance:

[[.SELF./image:pasted-317851.png|Chart|-width 200px]]

Here pasted-317851.png is an illustrative filename; use the name generated for your image. Chart supplies the image description, and -width 200px sets its displayed width. Include the CSS unit, such as px or %; a bare number is not a valid CSS width for this markup. Leave the height unspecified to preserve the aspect ratio. Preview honors the label and dimensions as well as the saved page.

These XoWiki sizing options control display size. They do not use the Forums and News responsive attachment variants described below.

Activate News and Forums without enabling site-wide richtext

Open the Parameters page for each News or Forums instance you want to configure and set:

RichTextEditor = markdown

Leave ACS Templating's site-wide UseHtmlAreaForRichtextP at 0 and its default RichTextEditor unchanged. The instance parameter selects the editor locally; explicit field options take precedence. An empty instance parameter preserves the existing ACS Templating behavior.

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. The automatic conversion described in the feature list also applies to existing drafts. For Markdown Text, the editor uses Marked directly and preserves the exact Markdown source.

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.

Enable image paste in Forums and News

Install and enable the shared Attachments service. No Attachments child mount or File Storage folder mapping is required. Image paste also requires richtext-markdown to be installed and selected as the editor, with HTML as the content format. Enabling image paste alone does not activate the editor; site-wide richtext editing can remain disabled.

Forums: enable image paste for each forum

Keep RichTextEditor = markdown on the Forums package instance. In Forums administration, create or edit each forum and configure its independent controls:

  • Allow image paste: Yes permits signed-in authors to paste PNG, JPEG and GIF images into posts and replies.
  • Allow file attachments: No allows image paste without also offering general file uploads. Enable this separately only where general attachments are wanted.

Both controls default to No for new forums. The package instance's AttachmentStyle=simple uses the shared Attachments service directly for general file uploads; image paste uses the direct workflow with either attachment style.

Upgrade note: review Allow file attachments for existing forums after upgrading to Forums 1.4.3d2. Earlier code incorrectly required a child-mounted Attachments instance even for the simple workflow, which could hide upload controls despite an enabled setting. The upgrade preserves existing file-attachment settings, so the fix can make general file uploads available. Set Allow file attachments to No where only image paste is intended. Existing forums initially have image paste disabled and must opt in.

News: enable image paste for the package instance

On the News instance's Parameters page, set:

RichTextEditor = markdown
AllowImagePasteP = 1

AllowImagePasteP defaults to 0. It controls both new articles and new revisions; authors still need the normal News creation or administration permissions. Images are attached to the article's item ID, so they remain available across revisions and are deleted with the article.

Pasting and saving images

Select HTML, put the cursor in the Write tab, and paste an image from the clipboard. The image appears in Preview before saving. Before save, staged images are private to the uploader; saving the post or article attaches them to its content. Abandoned uploads expire automatically.

Disabling image paste blocks new uploads and saving staged images, including from a form opened before the setting changed. Images already attached to posts or articles remain viewable. Without the Markdown editor loaded, the HTML choice provides an HTML-source textarea and does not upload clipboard images. Ordinary file attachments and existing content formats remain independent.

Image sizing and responsive delivery

For Forums and News, pasting inserts an HTML <img> tag in the Write tab, with an editable width attribute. To display the image at 200 pixels wide, change that attribute to width="200". Leave the height unset to preserve its aspect ratio. For example, with an illustrative Forums image URL:

<img src="/forums/markdown-image?key=...&amp;image_width=1200&amp;image_height=600"
     alt="Chart" width="200">

Keep the actual src produced by paste; do not replace its image key or ID with the placeholder shown above. Edit alt for a useful image description. The URL's image_width and image_height describe the original dimensions and must be left unchanged; they are not display-size controls.

The editor generates srcset and sizes for Preview and saved HTML, allowing the browser to select an image suited to its viewport and display density. The shared Attachments helper provides cached variants at 320, 640, 960, 1280 and 1920 pixels, preserving aspect ratio and never enlarging the original. New uploads carry the dimension information needed for this; existing saved posts are not automatically rewritten.

Server-side resizing requires ImageMagick, configured through the Content Repository's ImageMagickConvertBinary parameter (default: convert). If conversion is unavailable, busy or fails, delivery falls back to the original. Original files are retained, and the image URL without a width query parameter serves the original. That query parameter selects a server variant and is distinct from the HTML width attribute used for display sizing.

XoWiki continues to use its native wiki image markup and sizing options; the Forums and News example above does not change that workflow.

Permissions and content handling

Image delivery, including cached variants, checks the application's content visibility and permissions. 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 (1) 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
No registered users in community xowiki
in last 30 minutes
Contributors

OpenACS.org