I made a few major updates to mdless 2.0 (first announced a couple days ago) over the holiday weekend. Note that you can make all of the new options permanent in the config file (see Easily Update Config). Options specified on the command line will always override anything in the config file, so you can disable options permanently but enable them on a per-run basis using command line flags.

Inline Styling

The first problem I ran into was that if a link, emphasis, or other inline element came in the middle of a line, everything after that element would fail to be styled. So I added in a routine that I created for Doing that can take the text preceding an element and determine what the escape sequence would be at the end of that text, right before the new element. Then I can restore that sequence after the new element.

Nested Lists

Second, and this was a real pain, nested lists weren’t working. Like at all. I didn’t notice it at first because my test files had very basic lists in them, but lists were being flattened, ordered list sequencing was completely out of whack, and nested paragraphs and code blocks within lists were getting totally borked. Fixing this was a pain. Redcarpet only provides “text” and “type” to the list rendering functions, so you have no idea if it’s nested, at what level, etc. You can start a class variable counter and increment it with each ordered item, but as soon as it nests or starts a new list, you’re in trouble, and lists aren’t rendered in sequence anyway, so an array structure to keep track of them is impossible. They’re rendered inside out, so any kind of basic counter will be off as soon as you have a nested ordered list. Fixing this took me three days, and I went through a dozen solutions before one worked. I think the current solution is pretty solid, seems to handle all of the aforementioned issues and maintain accurate numbering with multiple nested, ordered lists. Also indents paragraphs and code blocks within lists.

I am running into an issue where a numbered item can sometimes have an unnecessary line break after it. I haven’t yet been able to track down where that’s coming from. Also, nested code blocks are indented, but one less indent than their parent list item. These will be fixed in future releases.

TaskPaper highlighting

I also added TaskPaper highlighting to mdless. You can run it with --taskpaper true to force TaskPaper highlighting, or run it with --taskpaper auto to detect TaskPaper formatting either from the file extension or test whether it has at least 1 project and 6 total tasks between projects based on regular expressions. Not the most elegant way to detect it, I’m sure, but it seems to work well in my testing. You can add:

:taskpaper: :auto

to ~/.config/mdless/config.yml to make auto a permanent setting (or use true or false to force it either way).

If TaskPaper highlighting is enabled, no other Markdown processing will be done. TaskPaper formatting intersects with Markdown formatting in ways that can cause unpredictable results. So @tags and values are highlighted, project names are highlighted, and task markers get colored. Other than that, it’s just displayed as is.

As mentioned in an update to the 2.0 announcement, mdless can now render links as inline, reference, or reference-per-paragraph, grouping the references below the paragraph or element that refers to them. Just run with --links paragraph or --links reference to enable either, and these can be made permanent in the config file by adding :links: :reference (or :inline or :paragraph).

Emphasis Markers

The initial release hid the markers around emphasis, e.g. **bold** would just render as bold, applying colors from your theme but leaving out the ** surrounding it. That’s now configurable in the theme settings:

  bold: b
  bold_character: "**"
  italic: u i
  italic_character: "_"
  bold-italic: b u i

You can leave the character settings empty to not display any characters at all (as per previous behavior).

Other Markdown Rendering Options

Redcarpet has flags available for lax spacing (requiring newlines around HTML blocks) and intra-emphasis (where a_underscored_filename would get rendered with italics in the middle). Disabling intra-emphasis means that underscored filenames (and other words) stay as is.

These can be implemented in mdless using --[no-]intra-emphasis and --[no-]lax-spacing, and both options can be made permanent in the config file.

:lax_spacing: true
:intra_emphasis: false

This one is simple, I just added highlighting for [[wiki links]]. It can be toggled with --[no-]wiki-links and uses the colors specified for link brackets and link text. Make it permanent with :wiki_links: true.

Easily Update Config

By the way, you can overwrite the config file with current command line flags and any new keys that have been added by running with --update-config. Any other flags on the command line will be set in the config, and any new keys that may have been added since your config file was created will be added with their default values.

The config file is found at ~/.config/mdless/config.yml. Options specified there can be overridden by using command line flags at any time. This file is automatically written on the first run where the file doesn’t exist, so you can scrap preferences and start again just by deleting the file and running mdless (any command line options used on that first run will be set in the config file, otherwise the default value for each option will be used).

Other Stuff

  • Pad numbers on headline listing to preserve indentation
  • Image rendering with chafa improved, still have to figure out a way to make sure content breaks properly around the embedded image
  • Only detect mmd headers on first line
  • Scrub invalid UTF-8 in document to remove characters that break regexes

Check out the project page for installation and usage details.