Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·5 min read

In TaskPad a star is a marker, so Markdown needed a translation layer

The importer had one job, and the first thing I had to decide was what a * means. In Markdown, * buy milk is a bullet. In TaskPad, a leading star is a marker with its own meaning, an important item, so passing a README through unchanged would have turned every bullet list into a column of starred tasks. That one collision shaped most of the Markdown import and export code in TaskPad.

Project
TaskPad
Date
Oct 2026
Stack
C#, WPF, AvalonEdit, .NET Framework 4.8
Commit
dcb08a4

Two languages that look alike

TaskPad is a plain-text task editor. A line is parsed by LineParser into an indent, an optional check state, an optional tag and the content. The check states are open, doing, done and cancelled. The tags include a bang, a question mark, a todo keyword, a star, arrows and a dash. The editor colours these, and the checklist behaviour depends on them.

Markdown shares some of that vocabulary and disagrees on the rest. - [x] means done in both. But Markdown has * and + as bullet characters, and TaskPad gives * a meaning. Markdown has no state for "in progress" or "cancelled" at all. Markdown also treats consecutive lines as one paragraph, while a TaskPad note is a list of separate lines. Importing and exporting is a translation between two grammars, and each direction loses something different.

Import: small, deliberate

FromMarkdown is a loop over lines with two regular expressions and one flag:

csharp
static readonly Regex MdTask = new Regex(@"^(\s*)[-*+]\s+\[([ xX])\]\s?", RegexOptions.Compiled);
static readonly Regex MdBullet = new Regex(@"^(\s*)[*+]\s+", RegexOptions.Compiled);

The flag is fence. A line that starts with three backticks toggles it, and while it is on, lines are copied untouched. Without that, a code sample inside a README that contains * item or - [ ] as program text would be rewritten into something else. The order matters: the fence check comes first, then the task checkbox, then the bullet.

The checkbox case normalises [X] to [x] and keeps the indentation, so nested checklists survive. The bullet case is the star problem, and the comment next to it in the code is blunt: "*" is a star in TaskPad. A * or + bullet becomes - . A - bullet already matches TaskPad's dash, so it is left alone. Trailing whitespace is trimmed on every line and the result ends with exactly one newline.

What import does not do is also a choice. Headings with # already work in TaskPad, so they pass through. Emphasis, links and tables are left as text. I did not try to build a Markdown renderer into a line editor. The imported text opens in a new unsaved tab named after the file, with a toast reminding me to save, so nothing is written to disk until I decide.

Export: where the mapping gets real

ToMarkdown walks the document lines and rebuilds each one from the parsed LineParser result. The task states map like this:

csharp
case Check.Done: outLine = ind + "- [x] " + content; break;
case Check.Doing: outLine = ind + "- [ ] " + content + " *(in progress)*"; break;
case Check.Cancelled: outLine = ind + "- [ ] ~~" + content + "~~"; break;

Markdown only has checked and unchecked, so "doing" becomes an unchecked box with an italic suffix, and "cancelled" an unchecked box with strikethrough. That is lossy, and I chose the loss on purpose: a reader of the exported file still sees what the state was, even if another tool would not parse it back.

Tags get the same treatment. A bang becomes a bold item with a warning sign, a question becomes italic, a todo keyword becomes a bold TODO: prefix. Numbered lines keep their own number text. Section lines are bolded.

Comments were the interesting part. TaskPad stores them inline in the line, in a syntax with {==highlighted text==}{>>comment<<}. In Markdown I turned them into footnotes:

csharp
notes.Add(string.Join(" — ", parts));
return (m.Groups["t"].Success ? m.Groups["t"].Value : "") + $"[^{notes.Count}]";

The highlighted text stays in the sentence, a numbered reference follows it, and all threads are appended at the bottom as [^1]: ... definitions with the author in bold. Image width hints, which are an editor-only suffix after a pipe in the alt text, are stripped so that standard renderers get a normal image tag.

Line breaks

The subtlest bug-in-waiting was the paragraph problem. Two consecutive plain lines in a TaskPad note are two lines; exported as-is, Markdown would merge them into one paragraph. The code detects a plain line, meaning one that is not a list item, a heading or a numbered line, and when the previous output line was also plain it replaces the newline with two trailing spaces and a newline, which is Markdown's hard break. List items and headings do not need this, since they already break lines.

The guard on export

Export writes through a save dialog. Before writing, it compares the full path of the chosen file with the note's own path, case-insensitively, and if they match it shows "Pick a different file name — that's the note itself" and stops. A note named plan.task is unlikely to collide with plan.md, but a text export into a plain .txt note is plausible, and silently overwriting the source of truth with a lossy copy is the kind of mistake that is only noticed later.

The plain-text export exists for the same reason as the footnotes: not every destination renders Markdown. It draws underlines under headings, swaps markers for symbols like a box and a check, and drops comments entirely except for the highlighted text.

Lesson

A converter between two formats is mostly a list of decisions about what to lose. Writing them down as small, separate cases made each one reviewable. The star, the fence and the line break were each a single line of code, and each would have been a visible defect in the first real document I tried.

#csharp#wpf#markdown#parsing

Keep reading

Have a project in mind?