Looking for Markdown Plugin
-
I’m looking for a Markdown plugin for NPP 6.8.3. NppMarkdown didn’t work, I got an error like “There is an error in the DLL file”.
Basically I want to highlight some words, hit a control key combination, like CTL-SH-B, and bold the words in Markdown (this puts ** on either side of the highlighted words).Thanks!
-
Hello Chuck-Roberts,
if you want only adding two asteriks in front and after the words then this pyhton script can do it as well.
Here is described what needs to be done first.for i in range(editor.getSelections()): start = editor.getSelectionNStart(i) end = editor.getSelectionNEnd(i) word = editor.getTextRange(start,end) editor.setTarget(start, end) editor.replaceTarget('**{0}**'.format(word))
Cheers
Claudia -
I developed this a few years ago for the PythonScript plugin… Try it out… I never heard any complaints… :)
-
-
I was doing a slew of posts here and on superuser.com the other day, and found myself wishing for the same thing that @Chuck-Roberts wanted: the ability to easily apply markdown syntax, so I was glad I had recently read this thread, and was able to come back, and study it and related links more.
I cleaned up my results and posted them as PryrtMarkdown.md. Basically, I integrated multiple copies of @Claudia-Frank’s script into the “Python script” menu, and described how to add those scripts to both the Context Menu and call them via keyboard shortcuts.
Since I liked @Ethan-Piliavin’s Markdown-to-HTML converter, I made sure to add that to the Context Menu I described, as well. :-)
For those who don’t want to follow a random link, or in case of link rot, I’ve pasted my writeup here, as well.
Prerequisites
-
Required: Python Script: You might need to install from the Perl Script “MSI” installer instead of Plugin Manager
-
Suggested: Ethan Piliavin’s Python script Markdown to HTML converter
-
Suggested: Preview HTML plugin: need version 1.3 or newer; Plugin Manager is stuck at 1.2.1, so do a manual install:
- Use the official website’s plugin link by downloading the zip file and extracting the DLL into your
Plugins\
directory, and thezip...\Config\PreviewHTML\
folder into yourPlugins\Config\
folder asPlugins\Config\PreviewHTML\
- Use the official website’s plugin link by downloading the zip file and extracting the DLL into your
Restart Notepad++ after installing your plugins.
Create Python Scripts
We need Python scripts to take the currently-selected text, and add the markdown notation to make it bold, emphasized, etc.
You may download the directory of scripts from my dropbox (at least until I hit bandwidth limitations). You can grab the files individually, or grab the whole folder using “
Download as .zip
” from the Dropbox interface. Save the scripts in in%ProgramFiles%\Notepad++\Plugins\Scripts\PryrtMarkdown\
or%AppData%\Notepad++\Plugins\config\PythonScript\scripts\PryrtMarkdown
.If you prefer, you can create and edit the scripts manually:
-
Create new script(s) using
Plugins > Python Script > NewScript
-
Save script(s) in
%ProgramFiles%\Notepad++\Plugins\Scripts\PryrtMarkdown\
or%AppData%\Notepad++\Plugins\config\PythonScript\scripts\PryrtMarkdown
-
Copy/Paste the content from Claudia’s script, quoted here with attributions and a link for markdown syntax help:
#https://notepad-plus-plus.org/community/topic/10957/looking-for-markdown-plugin #https://daringfireball.net/projects/markdown/syntax#em for i in range(editor.getSelections()): start = editor.getSelectionNStart(i) end = editor.getSelectionNEnd(i) word = editor.getTextRange(start,end) editor.setTarget(start, end) editor.replaceTarget('**{0}**'.format(word))
-
For each script, edit the last line to use the appropriate Markdown command:
-
bold:
**{0}**
-
emphasis:
_{0}_
-
inline code
: `{0}
` -
link:URL:
[link text]({0} "OptionalTitle")
=> Will use selected text as the link URL- just delete the space ane
"OptionalTitle"
if you don’t want the optional hover/title for your link
- just delete the space ane
-
link:Text:
[{0}](URL "OptionalTitle")
=> Will use selected text as the link TEXT- just delete the space ane
"OptionalTitle"
if you don’t want the optional hover/title for your link
- just delete the space ane
-
You may freely edit or extend these scripts to create any other Markdown syntax you would like; these are just the ones I found easiest to copy/tweak from the script that Claudia provided. I am sure it wouldn’t be that much more effort to have it automatically select the whole row and surround by sets of
# blah #
for various levels of headers. (I just don’t know the API well enough to do more than simple tweaks to the script, for now.)Context Menus
Notepad++ has an extensible Right-Click Context menu, and you can add these commands into
- To enable the scripts so the Right-Click Context Menu can access them, you need to add the scripts to the main
Python Script
menu, rather than leaving them only in the sub-menus:
* `Plugins > Python Script > Configuration` * Select either `(*) User Scripts` (%AppData%) or `(*) Machine Scripts` (%ProgramFiles%) * Select each script you want to add to the menu, then click the `Add` button on the left `Menu Items` side * Select `okay` when all the scripts have been added to the menu.
- To add it to Right-Click Context Menu:
* Open `%ProgramFiles%\Notepad++\contextMenu.xml` or `%AppData%\Notepad++\contextMenu.xml` (as appropriate for your configuaration) or choose `Settings > Edit Popup Context Menu` to edit the `AppData` directly. * Insert the following code where you'd like it to appear in the context menu <Item id="0"/> <Item FolderName="Markdown commands" PluginEntryName="Python Script" PluginCommandItemName="MarkBold" ItemNameAs="Mark Selection as Bold" /> <Item FolderName="Markdown commands" PluginEntryName="Python Script" PluginCommandItemName="MarkEm" ItemNameAs="Mark Selection as Emphasis" /> <Item FolderName="Markdown commands" PluginEntryName="Python Script" PluginCommandItemName="MarkCodeInline" ItemNameAs="Mark Selection as Inline-Code" /> <Item FolderName="Markdown commands" PluginEntryName="Python Script" PluginCommandItemName="MarkKbd" ItemNameAs="Mark Selection as Keyboard" /> <Item FolderName="Markdown commands" PluginEntryName="Python Script" PluginCommandItemName="MarkLinkInlineURL" ItemNameAs="Mark Selection as URL of Inline-Link" /> <Item FolderName="Markdown commands" PluginEntryName="Python Script" PluginCommandItemName="MarkLinkInlineText" ItemNameAs="Mark Selection as Text of Inline-Link" /> <!-- optional: Ethan Piliavin's Markdown to HTML converter --> <Item FolderName="Markdown commands" PluginEntryName="Python Script" PluginCommandItemName="Markdown" ItemNameAs="Convert Markdown to HTML" /> * Exit NPP and reload.
-
You should have a new section, “Markdown Commands”, in your Right-Click Context Menu.
-
Highlight Text
-
Choose one of the commands, and the script will surround your selection appropriately
-
“Convert Markdown to HTML”:
-
If you have text selected, it will only convert the selected text
-
If you have no text selected, it will convert the entire document
-
-
Keyboard Shortcuts
If you also want keyboard shortcuts, use the
Settings > Shortcut Mapper...
, and select thePlugin Commands
tab. You can assign shortcuts to the “MarkBold”, “MarkEm”, … rows as per normal. (They will probably be near the end of the list, since they were the most-recently added.)Preview
I knew I could copy the results of the Markdown to HTML conversion into an HTML file, then use “Preview HTML” plugin (Ctrl+Shift+H). But while searching around for alternatives, I had run across this superuser.com answer, which shows a way to pipe the markdown source directly into Preview HTML
-
you need to have standalone Python excecutable installed
-
you need to install the python markdown package:
-
pip install markdown
or
-
easy_install markdown
depending on your python setup.
-
-
Plugins > Preview HTML > Edit filter definitions
: add; Content of Filters.ini file [Markdown] Extension=.md .markdown Language=Markdown Command=python -m markdown "%1"
I did a restart of NPP; I don’t know if that was necessary. Thereafter, if I am editing a .md or .markdown file, and have the Preview HTML window open using Ctrl+Shift+H, the markdown is automatically converted to HTML and into the Preview window. :-)
-
-
“Perl Script “MSI” Installer” should, of course, read “Python Script “MSI” Installer”. (Sorry to all the Python aficionados out there; my Perl roots are showing.)
Speaking of Perl, if that’s your scripting language of choice, installing Text::Markdown will install
markdown.pl
andmarkdown.bat
(genererally into...\site\bin\markdown.bat
or similar). If you don’t have the Python standalone executable, but do have Perl, you can change the Preview HTML filter definition for Markdown to[Markdown] Extension=.md .markdown Language=Markdown Command=markdown.bat "%1"
If your various perl bin directories aren’t in your path, you will need to use the full path to those directories (such as
Command=\strawberry\perl\site\bin\markdown.bat "%1"
).If you use extensions beyond the original daringfireball syntax in your markdown, you will probably want Text::MultiMarkdown with its associated
multimarkdown.pl
/multimarkdown.bat
for your filter, instead.