Toggle Asterisks and Hyphen Markdown List Markers Macro

October 26, 2013

Toggle Asterisks and Hyphen Markdown List Markers Macro → via @_patrickwelker

“Hello World”, this is just another post about one tiny tiny Keyboard Maestro macro.

I’m currently in the process of converting some lists from one format into another. This macro helps me speed up the process. It takes a Markdown list that has asterisks or hyphens as list markers and depending on which one it finds in the selected text switches to the other one. All indentation is kept.

So this…

- Sausages
    - Song
	    - Adam Buxton
		    - Great YouTube Video
    - Food
	    - ♥ of my dog

… becomes this:

* Sausages
    * Song
	    * Adam Buxton
		    * Great YouTube Video
    * Food
	    * ♥ of my dog

You might wonder how one could possibly need such a script if Markdown doesn’t differentiate between the list markers. Well, this becomes useful if you use apps like Listacular or any other app that has a feature which treats the list markers differently (there are quite a few)1.

This is the macro:

toggle-macro

The only magic that is happening is an regular expression which went from this mess (picture) into this ([\t ]*)\*(.*) concise beauty (thanks to the clever folks at the Stack Exchange community).

PS: If you want to switch list markers on the whole document instead of just the selection add a type action with the ⌘A shortcut as the first action in the macro chain.

DOWNLOAD

  1. Side note: I’m still hoping 1Writer will support or adapt a more Markdown friendly syntax for turning list items into todos. Using -- breaks working with those files for me.

comments powered by Disqus

Related Posts