Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Add helpdesk authoring: a rich markdown article editor and article tree - #1112

Merged
ericnewcomer merged 67 commits into
mainfrom
ericnewcomer/knowledge
Aug 6, 2026
Merged

ericnewcomer merged 67 commits into
mainfrom
ericnewcomer/knowledge

Conversation

@ericnewcomer

Copy link
Copy Markdown
Member

Summary

Adds the authoring surface for the helpdesk: a rich markdown editor (temba-markdown-edit) that edits the rendered article rather than its source, and an article tree (temba-article-list) for organizing, reordering and publishing articles. Supporting changes ride along: a temba-toggle switch, a textinput suffix slot, and modax sizing/gutter hooks the article dialog uses.

Changes

Markdown editor (src/form/MarkdownEditor.ts, src/form/MarkdownDocument.ts)

  • WYSIWYG editing over markdown: the article renders as blocks and each edited block is serialized back to markdown, so untouched blocks round-trip byte for byte. Raw HTML is escaped, never parsed.
  • Icon toolbar that follows the caret: headings, emphasis, code, lists, quotes, dividers, links, image upload — plus a markdown-source mode whose toolbar is bare except the way back to rich text.
  • Layout tools: image+text columns built on markdown tables (widths drag-resizable, kept as % shares), single-column styled blocks, and per-column background/padding/border carried as a tiny stylesheet in otherwise-empty header cells. Backgrounds are indexes into the org's shared palette rather than embedded hex; text and border colors derive from each column's own fill.
  • Links and images edit through popovers floated over the content: a link's URL is read and changed without ever showing its markdown, and a clicked image becomes a real selection offering its sizes (#size= fragment in the URL, so it survives any renderer).
  • Clicks on links never navigate — modifier or not — a click is the author reaching for the text.
  • Paste rebuilds outside markup into clean blocks; copies carry contents without layout.

Article list (src/list/ArticleList.ts)

  • The helpdesk tree: articles nest two levels, drag to reorder or reparent, branches fold open and shut with an animated sweep, and each row carries its publish switch.
  • Rows open the editor in a dialog rather than navigating to a page.

Supporting components

  • temba-toggle (src/form/Toggle.ts): a switch for the states you flip rather than fill in.
  • temba-textinput gains a suffix slot at the right edge of its chrome (the article dialog's status pill rides there).
  • temba-modax can size the dialog it renders and passes gutter content to its footer.
  • temba-content-list maps its empty message to an attribute.

Behavior examples

Column layouts and styled blocks ride in the markdown itself, so any renderer that understands tables shows something sensible:

Authored in the editor Markdown written
Two columns, 60/40, text beside image | width: 60% | width: 40% | header row, cells as single lines with <br> breaks
Styled callout on palette color 2 | background: 2 | single-column table
Image sized small ![](https://…/shot.png#size=small)

Test plan

  • Full suite green in the stack container: 2912 passed, 0 failed (171 files), coverage 89.8% statements
  • New test files: temba-markdown-edit (77 tests: round-tripping, toolbar, links, images, columns, styled blocks, source mode, screenshots), temba-article-list (tree, folding, reorder, publish), temba-toggle, plus modax/textinput/content-list additions
  • Screenshot truths recorded for the editor's states and the article list

Screenshots

The rendered article under edit Editing with the toolbar lit
document editing
A link's popover A clicked image offering its sizes
link image
Markdown source mode The article tree
source list
The toggle's states Textinput suffix slot
toggle suffix

A formatting toolbar over a plain textarea, with screenshot uploads by button, drop
or paste, and a preview.

The source stays markdown rather than becoming rich text so that what gets stored is
diffable, portable and cheap to chunk for search. The preview is rendered by the
server rather than in the browser: it's the same renderer and the same sanitizing the
published article goes through, so an author can't preview something we'd refuse to
publish, and we never inject unsanitized HTML of our own making.

The toolbar buttons are labelled rather than iconned so this needs no new sprite
entries.
Block formatting marked only the first line of a selection, so selecting three
lines and clicking List produced one list item and two loose lines. Every line
the selection covers is marked now, which is what the button appears to promise.

Uploads write a markdown reference from the response, and two things could make
that reference nonsense. A session that expires mid-upload redirects to a login
page, which resolves as a success carrying no url, so the url is checked before
anything is inserted rather than writing ![undefined](undefined). And filenames
deliberately keep brackets and parens, which are exactly the characters that
delimit a markdown image, so they're stripped from the alt text.

The preview holds server rendered HTML that render() hands to unsafeHTML, so it
becomes internal state rather than a public property - an attribute would let
anything able to set one put unsanitized markup on the page.
The helpdesk's article tree as a content list rather than a hand rolled
one. Hierarchy is carried by a per level indent, a guide rail for each
level of ancestry and a disclosure chevron on anything with children, so
what is a child of what is legible at a glance.

Rows are dragged by their handle to reorder and reparent, replacing the
untested inline script the page had. The tree maths - what travels with
a drag, how deep it can land given the descendants coming with it, and
how a flat order reads back out as parents - are pure functions, so the
cases that actually matter are tested directly rather than through the
DOM.
The markdown editor was a toolbar over a textarea with a preview you switched to.
It's a rich editor now: the article is rendered as you write it, and only the block
holding the caret shows its markdown. A toolbar toggle swaps the whole document to
raw markdown and back, and the two stay in step.

What gets stored is still markdown, and that constraint is what picked the
implementation. The document is modelled as blocks that keep the markdown they were
authored with, so only the block being edited is ever rewritten and a round trip
leaves everything else byte for byte as it was. Parsing to a tree and serializing
back - which is what an editor dependency would do - renormalizes headings, emphasis
markers, bullet characters and line wrapping across content nobody touched, and
article bodies have to stay diffable. Rendering a block at a time also means the
toolbar and uploads write markdown text in both modes, so there's one implementation
of each command rather than two.

Rendering moved to the browser, using the Remarkable instance the repo already ships.
The preview used to be rendered by the server on the grounds that it should run the
same renderer and the same sanitizing as the published article, so an author couldn't
preview something we'd refuse to publish. With rich editing there is no preview - an
author is looking at their own draft in their own browser, so the only content they
can inject is their own and there's nobody else to injure. Readers still get server
rendered, server sanitized HTML. Remarkable escapes rather than passes through raw
HTML, so even the author's own markup can't run here.

Uploads keep their endpoint contract and their hardening: no reference is written
when the response carries no url, and the delimiters markdown uses are stripped out
of alt text. Two things are new. The block and offset a reference goes to are fixed
before the request, because an upload takes seconds and clicking into another block
while it runs would otherwise write one block's text over another's. And the caret
now lands after each reference rather than in front of it, so a batch of files ends
up in the order they were given.

The preview endpoint is gone, so preview_endpoint is no longer read.
The rendered document, a block showing its markdown while the caret is in it, and
the whole thing as raw markdown.
The property was declared without an explicit attribute name, so Lit
mapped it to `emptymessage`. Hosts have been setting `empty-message` in
markup all along, which did nothing - the list subclasses each assign a
default in their constructor, so the message still looked right and the
no-op went unnoticed.
Clicking into the editor used to turn the block holding the caret into a
textarea of its markdown, so editing an article meant looking at its
source. Now the document is a single contenteditable and the caret goes
into the rendered text: no part of it ever becomes markdown, on click,
while typing, or on caret navigation. The source toggle is still the one
way to see markdown, and is unchanged.

Editing is the browser's, which is what makes selecting across blocks,
deleting a range that spans them, select-all and undo behave the way they
do everywhere else - all of that was either missing or sacrificed before.
Around it the editor corrects the markup the browser leaves behind (the
bare <div> after a heading, a list nested inside the block it was made
from, styles hung off an inserted image), keeps Enter inside a fenced
block from splitting it in two, and drives formatting through execCommand
so those edits land in the undo stack too.

The block model is kept, and with it the property it was built for: a
block is only written back out from what it renders as once it has
actually been edited, so opening an article, changing one paragraph and
saving diffs that paragraph and nothing else. Setext headings, + bullets,
__emphasis__ and hard wrapping all survive in blocks nobody touched.

Reading a block back is new, and lives in MarkdownDocument along with the
block splitting. Anything it can't express - a table today, whatever the
renderer grows tomorrow - is rendered as an island that can't be edited
here rather than being rewritten badly, so content the editor doesn't
model is never damaged by it.

Images are inline rather than block, without which the browser splits the
paragraph in two to insert one and a screenshot dropped mid-sentence
lands somewhere other than the caret.

Toolbar commands act on the rendered selection and light up to say what
the caret is sitting in. A link is edited through a bar that appears when
the caret is inside one, so its URL can be changed without its markdown
ever being shown.
An article is read and written in a dialog over the list now, and the
read page it used to link to is gone - so getRowHref has nothing to
answer with and a ctrl-click on a row was landing on a 404.

The rows still lead somewhere, so they keep the clickable affordance
through an isRowClickable hook rather than inferring it from an href
that no longer exists. The edit and delete hover buttons go with it:
nothing passes editable or deletable any more, since the dialog carries
both actions itself.
The dialog has taken a size and a width all along, but the modax in
front of it forwarded neither - so a host wanting anything other than
the default had to reach into the modax's shadow root and set it on the
dialog by hand once it had rendered.
A long article scrolled its own formatting controls out of view, so
adding a heading halfway down meant scrolling back to the top for the
toolbar and back down again for the caret.

The toolbar and the link bar stick together as one piece of chrome,
which is what keeps the link bar under the command that opened it
rather than sliding away beneath a toolbar that stayed. Sticky resolves
against the nearest scrolling ancestor even when that sits outside the
shadow root, which is what the dialog's modal body is.
A checkbox reads as something you're filling in and will submit later,
which is the wrong shape for a state that takes effect when you set it.
This is the same contract - checked, a form value when on, a change
event - shown as a slider and standing the height of a standard button,
so it sits level in a row of them.
An article editor wants a window that stays put: the dialog as tall as
the screen allows, and a long article scrolling where it's being written
rather than growing the dialog past the bottom of the window.

The editor takes the height it's given under 'fill', passing it down to
the document, which scrolls. The modax's body had to stop declaring
display: block for that to be possible at all - a div is block anyway,
and since these styles are adopted they landed after the <style> a body
brings with it and won every tie, so a body could never lay itself out.
Publishing was something you had to open an article to do, which meant
opening one to find out you didn't need to. It's a property of the whole
article rather than of an edit, so it belongs on the row.

The switch says what the status is as well as setting it, so where it's
offered the status pill steps aside rather than saying the same thing
twice - a viewer without the permission gets no switch and keeps the
pill.
@ericnewcomer
ericnewcomer merged commit 88518ab into main Aug 6, 2026
0 of 7 checks passed
@ericnewcomer
ericnewcomer deleted the ericnewcomer/knowledge branch August 6, 2026 18:25
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant