Write and Interpret Markdown Documents from Notepad++

Many windows users like Notepad++ as a light weight and fast text editor with some nice features and support for several programming languages. I use it almost daily to edit and view ascii files, write code, readme files or short notes.

Why not in the course of this, format notes with simple markdown syntax and produce pretty looking documents?

For Notepad++ there are a lot of extra plugins available. Above all, the plugin NppExec is able to customise Notepad++ in a very flexible manner. It allows you to interact with external programs directly from Notepad++ by a console window or batch scripts. NppExec interprets its own internal commands and has predefined environment variables which make it easy to pass your current text file to external tools.

So NppExec can be used to pass a markdown text file currently opened in Notepad++ to a document converter like pandoc. Pandoc interprets your markdown script and converts it to html or other document formats.

Make Notepad++ be able to deal with markdown documents

Take the following steps:

  • First use the Notepad++ Plugin Manager to install NppExec
  • Download pandoc from GitHub and install (https://github.com/jgm/pandoc/releases/tag/1.17.1)
  • After that I recommend to add the path to pandoc.exe to the windows environment variable Path. Otherwise you have to complement the full pandoc directory at row #2 in the script below.
  • Back at Notepad++ press “F6” or click on “Execute…” in NppExec menu.
    There you paste following code in the “Command(s)” text field and save the script e.g. as md2html:

    SET  OUTFILE = $(FILE_NAME).html
    pandoc "$(FULL_CURRENT_PATH)" -f markdown -t html -s --mathjax -o $(OUTFILE)
    echo "Transformation from markdown to html successful:"
    echo Output html file: $(OUTFILE)
    NPP_OPEN $(OUTFILE)

Explanation:

With the NppExec environment variables FILE_NAME and FULL_CURRENT_PATH you get a reference to your current (active) file in Notepad++ (file must be saved).

The user defined variable OUTFILE contains the current filename but with html extension as output filename. Row #2 is the place where the magic happens. pandoc transforms your markdown file to html.

The –mathjax argument is one option to interpret mathematical formulas written in LaTeX stile.

To use other formula interpreter or output file formats see the pandoc user’s guide: http://pandoc.org/README.html

NPP_OPEN $(OUTFILE) opens the just created html document in a new tab.

Convert your document

Write a markdown document, save and press F6 (make sure that the tab with your document is active).

The “Execute…” window will be opened, choose your script “md2html” and press enter. That’s it. Notepad++ opens the html source automatically. By pressing Ctrl+Alt+Shift+X you can Launch the html code from the active tab in Firefox (if installed).

To make the markdown conversion even easier you can create a menu item for NppExec script and assign a shortcut key for it.

You can do it from “NppExec” -> “Advanced Options…”. Set there an “Item Name” and select the “Associated Script” from drop-down list. Press “Add/Modify” button. Now you can find your new item in “Macro” menu. Search for this item name in “Macros” -> “Modify shortcut / Delete macro” under “Plugin Commands” where you can assign a shortcut.

Additional: You can implement markdown syntax highlighting in Notepad++ https://github.com/Edditoria/markdown_npp_zenburn

Now have fun with creating markdown documents in Notepad++!

Yours faithfully,

Dennis Vier

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s