An Action for the LaunchBar application (macOS).
What it does
The Action takes Markdown-formatted text and converts it to plain text. This is especially useful for creating nice plain-text emails.
An example:
Input (Markdown):
This is an example text to demonstrate how Markdown^[This is an inline footnote] is converted to plain text:
An unordered list:
=================
- a list item
- another list item with a some more text to show how list items are hard-wrapped and indented (in this case with 4 spaces and to a max. length of 72 chars)
- and a last list item with a subitem:
- subitem[^myFnote]
[^myFnote]: Also referenced footnotes can be used.
# An ordered list:
1. This is the __first__ point of an ordered list
1. Footnotes are useful to get longish links^[https://en.wikipedia.org/wiki/Hyperlink#Hyperlinks_in_various_technologies] out of the text body
1. …but the usual Markdown [link syntax](https://daringfireball.net/projects/markdown/syntax#link) will also be referenced at the end of the text.
A table in-between:
| Tables | Are | Cool |
|--|:--:|--:|
| col 1 is | left-aligned | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right-aligned | $1 |
4. To continue a list numbering
4. just start with the desired number
End of text.
***
Output (plain text):
This is an example text to demonstrate how Markdown[1] is converted to
plain text:
AN UNORDERED LIST:
- a list item
- another list item with a some more text to show how list items are
hard-wrapped and indented (in this case with 4 spaces and to a max.
length of 72 chars)
- and a last list item with a subitem:
- subitem[2]
AN ORDERED LIST:
1. This is the FIRST point of an ordered list
2. Footnotes are useful to get longish links[3] out of the text body
3. …but the usual Markdown [link syntax][] will also be referenced at
the end of the text.
A table in-between:
Tables Are Cool
---------- --------------- -------
col 1 is left-aligned $1600
col 2 is centered $12
col 3 is right-aligned $1
4. To continue a list numbering
5. just start with the desired number
End of text.
------------------------------------------------------------------------
[1] This is an inline footnote
[2] Also referenced footnotes can be used.
[3] https://en.wikipedia.org/wiki/Hyperlink#Hyperlinks_in_various_technologies
[link syntax]: https://daringfireball.net/projects/markdown/syntax#link
How to use
- In your text editor, select the Markdown text that should be converted.
- Send it to LaunchBar with your Instant Send key
- Select the action by typing the appropriate abbreviation (for example
mp
ormtp
). - Press Return.
- Once the result appears in the LaunchBar window press ⌘C to copy it to the clipboard.
- Paste it wherever you want.
As you might know, LaunchBar allows you to directly insert string results by pressing Shift-Return. So, if you prefer to replace the current text selection with the result (instead of copying it to the clipboard), then just press Shift-Return in step 4.
If you want to send the result to another action, then press the Tab key as soon as the result appears in the LaunchBar window, and then invoke the other action.
How it works
- The action uses a Perl script.
- The conversion is done by Pandoc.
- After the conversion the script appends a Tab character to the end of each line that is not followed by an empty line. This should prevent certain broken email clients (namely Outlook) from arbitrarily removing line breaks.1 You can deactivate this in the script (see the comments there), if you don’t use Outlook or if you don’t send plain text mails to Outlook users.
Requirements
- LaunchBar, of course.
- Pandoc; can conveniently be installed via Homebrew:
brew install pandoc
If you don’t want to install it, then download the standalone Action, which contains the Pandoc binary (~20MB; see Download section blow). - Perl (preinstalled with macOS).
- I have included the required Perl modules
Pandoc
andJSON
in the Action bundle.2
Customization
Pandoc is highly customizable and you can tweak the output text to your needs. To do so, just edit the Pandoc options in the script. (It is the line that begins with my $md2plain
.)
You can for example adjust line length, indentation of lists, enable/disable “smart” replacement, footnotes location and more. For the complete documentation of the options see the Pandoc user manual. Explanations for the most important options you find also at the end of the script file (default.pl
).
Use the excellent Action Editor to open and edit the script file.
Download
Normal version (recommended):
Download (1.0 / 2017-04-17)
Standalone version (with Pandoc, ~20MB):
Download (1.0 / 2017-04-17)
Footnotes
- Outlook has a setting to disable that behavior, but most people aren’t aware.
- If you are familiar with Perl, then I recommend to install the modules via
cpanm
in your @INC path. This makes it easier for you to keep them up to date.