markdown-mode is a major mode for editing Markdown-formattedtext. The latest stable version is markdown-mode 2.3, released onAugust 31, 2017. See the release notes for details.markdown-mode is free software, licensed under the GNU GPL,version 3 or later.
Documentation
The primary documentation for Markdown Mode is available below, andis generated from comments in the source code. For a more in-depthtreatment, the Guide to Markdown Mode for Emacs coversMarkdown syntax, advanced movement and editing in Emacs,extensions, configuration examples, tips and tricks, and a surveyof other packages that work with Markdown Mode. Finally, Emacs isalso a self-documenting editor. This means that the source codeitself contains additional documentation: each function has its owndocstring available via C-h f (describe-function
), individualkeybindings can be investigated with C-h k (describe-key
), anda complete list of keybindings is available using C-h m(describe-mode
).
Installation
Workplace HD Ready. What is Markdown? Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents. Created by John Gruber in 2004, Markdown is now one of the world’s most popular markup languages.
Note: To use all of the features of markdown-mode
, you’ll needto install the Emacs package itself and also have a local Markdownprocessor installed (e.g., Markdown.pl, MultiMarkdown, or Pandoc).The external processor is not required for editing, but will beused for rendering HTML for preview and export. After installingthe Emacs package, be sure to configure markdown-command
to pointto the preferred Markdown executable on your system. See theCustomization section below for more details.
The recommended way to install markdown-mode
is to install the packagefrom MELPA Stableusing package.el
. First, configure package.el
and the MELPA Stablerepository by adding the following to your .emacs
, init.el
,or equivalent startup file:
Then, after restarting Emacs or evaluating the above statements, issuethe following command: M-x package-install RET markdown-mode RET.When installed this way, the major modes markdown-mode
and gfm-mode
will be autoloaded and markdown-mode
will be used for file namesending in either .md
or .markdown
.
Alternatively, if you manage loading packages with use-packagethen you can automatically install and configure markdown-mode
byadding a declaration such as this one to your init file (as anexample; adjust settings as desired):
Direct Download
Alternatively you can manually download and install markdown-mode.First, download the latest stable version andsave the file where Emacs can find it (i.e., a directory in yourload-path
). You can then configure markdown-mode
and gfm-mode
to load automatically by adding the following to your init file:
Development Version
To follow or contribute to markdown-mode development, you canbrowse or clone the Git repositoryon GitHub:
Workplace Markdown Rules
If you prefer to install and use the development version, which maybecome unstable at some times, you can either clone the Gitrepository as above or install markdown-mode fromMELPA.
If you clone the repository directly, then make sure that Emacs canfind it by adding the following line to your startup file:
Packaged Installation
markdown-mode is also available in several package managers. Youmay want to confirm that the package you install contains thelatest stable version first (and please notify the packagemaintainer if not).
- Debian Linux: elpa-markdown-mode and emacs-goodies-el
- Ubuntu Linux: elpa-markdown-mode and emacs-goodies-el
- RedHat and Fedora Linux: emacs-goodies
- NetBSD: textproc/markdown-mode
- MacPorts: markdown-mode.el (pending)
- FreeBSD: textproc/markdown-mode.el
Dependencies
To enable editing of code blocks in indirect buffers using C-c ’,you will need to install the edit-indirect
package.
Usage
Keybindings are grouped by prefixes based on their function. Forexample, the commands for styling text are grouped under C-c C-sand toggle commands begin with C-c C-x. The primary commands ineach group will are described below. You can obtain a list of allkeybindings by pressing C-c C-h. Movement and shifting commandstend to be associated with paired delimiters such as M-{ andM-} or C-c < and C-c >. Outline navigation keybindings thesame as in org-mode
. Finally, commands for running Markdown ordoing maintenance on an open file are grouped under the C-c C-cprefix. The most commonly used commands are described below. Youcan obtain a list of all keybindings by pressing C-c C-h.
Links and Images: C-c C-l and C-c C-i
C-c C-l (
markdown-insert-link
) is a general command forinserting new link markup or editing existing link markup. Thisis especially useful when markup or URL hiding is enabled, sothat URLs can’t easily be edited directly. This command can beused to insert links of any form: either inline links,reference links, or plain URLs in angle brackets. The URL or[reference]
label, link text, and optional title are enteredthrough a series of interactive prompts. The type of link isdetermined by which values are provided:- If both a URL and link text are given, insert an inline link:
[text](url)
. - If both a
[reference]
label and link text are given, inserta reference link:[text][reference]
. - If only link text is given, insert an implicit reference link:
[text][]
. - If only a URL is given, insert a plain URL link:
<url>
.
Similarly, C-c C-i (
markdown-insert-image
) is a generalcommand for inserting or editing image markup. As with the linkinsertion command, through a series interactive prompts you caninsert either an inline or reference image:- If both a URL and alt text are given, insert an inlineimage:
![alt text](url)
. - If both a
[reference]
label and alt text are given,insert a reference link:![alt text][reference]
.
If there is an existing link or image at the point, thesecommand will edit the existing markup rather than inserting newmarkup. Otherwise, if there is an active region, these commandsuse the region as either the default URL (if it seems to be aURL) or link text value otherwise. In that case, the regionwill be deleted and replaced by the link.
Note that these functions can be used to convert links andimages from one type to another (inline, reference, or plainURL) by selectively adding or removing properties via theinteractive prompts.
If a reference label is given that is not yet defined, youwill be prompted for the URL and optional title and thereference will be inserted according to the value of
markdown-reference-location
. If a title is given, it will beadded to the end of the reference definition and will be usedto populate the title attribute when converted to HTML.Local images associated with image links may be displayedinline in the buffer by pressing C-c C-x C-i(
markdown-toggle-inline-images
). This is a toggle command, sopressing this once again will remove inline images.- If both a URL and link text are given, insert an inline link:
Text Styles: C-c C-s
C-c C-s i inserts markup to make a region or word italic. Ifthere is an active region, make the region italic. If the pointis at a non-italic word, make the word italic. If the point isat an italic word or phrase, remove the italic markup.Otherwise, simply insert italic delimiters and place the cursorin between them. Similarly, use C-c C-s b for bold, C-c C-s cfor inline code, and C-c C-s k for inserting
<kbd>
tags.C-c C-s q inserts a blockquote using the active region, ifany, or starts a new blockquote. C-c C-s Q is a variationwhich always operates on the region, regardless of whether itis active or not (i.e., when
transient-mark-mode
is off butthe mark is set). The appropriate amount of indentation, ifany, is calculated automatically given the surrounding context,but may be adjusted later using the region indentationcommands.C-c C-s p behaves similarly for inserting preformatted codeblocks (with C-c C-s P being the region-only counterpart)and C-c C-s C inserts a GFM style backquote fenced code block.
Headings: C-c C-s
To insert or replace headings, there are two options. You caninsert a specific level heading directly or you can have
markdown-mode
determine the level for you based on the previousheading. As with the other markup commands, the headinginsertion commands use the text in the active region, if any,as the heading text. Otherwise, if the current line is notblank, they use the text on the current line. Finally, thesetext commands will prompt for heading text if there is noactive region and the current line is blank.C-c C-s h inserts a heading with automatically chosen type andlevel (both determined by the previous heading). C-c C-s Hbehaves similarly, but uses setext (underlined) headings whenpossible, still calculating the level automatically.In cases where the automatically-determined level is not whatyou intended, the level can be quickly promoted or demoted(as described below). Alternatively, a C-u prefix can begiven to insert a heading promoted (lower number) by onelevel or a C-u C-u prefix can be given to insert a headingdemoted (higher number) by one level.
To insert a heading of a specific level and type, use C-c C-s 1through C-c C-s 6 for atx (hash mark) headings and C-c C-s ! orC-c C-s @ for setext headings of level one or two, respectively.Note that ! is S–1 and @ is S–2.
If the point is at a heading, these commands will replace theexisting markup in order to update the level and/or type of theheading. To remove the markup of the heading at the point,press C-c C-k to kill the heading and press C-y to yank theheading text back into the buffer.
Horizontal Rules: C-c C-s -
C-c C-s - inserts a horizontal rule. By default, insert thefirst string in the list
markdown-hr-strings
(the mostprominent rule). With a C-u prefix, insert the last string.With a numeric prefix N, insert the string in position N(counting from 1).Footnotes: C-c C-s f
C-c C-s f inserts a footnote marker at the point, inserts afootnote definition below, and positions the point forinserting the footnote text. Note that footnotes are anextension to Markdown and are not supported by all processors.
Wiki Links: C-c C-s w
C-c C-s w inserts a wiki link of the form WikiLink`. Ifthere is an active region, use the region as the link text. If thepoint is at a word, use the word as the link text. If there isno active region and the point is not at word, simply insertlink markup. Note that wiki links are an extension to Markdownand are not supported by all processors.
Markdown and Maintenance Commands: C-c C-c
Compile:C-c C-c m will run Markdown on the current bufferand show the output in another buffer. Preview: C-c C-c pruns Markdown on the current buffer and previews, stores theoutput in a temporary file, and displays the file in a browser.Export:C-c C-c e will run Markdown on the current bufferand save the result in the file
basename.html
, wherebasename
is the name of the Markdown file with the extensionremoved. Export and View: press C-c C-c v to export thefile and view it in a browser. Open:C-c C-c o will openthe Markdown source file directly usingmarkdown-open-command
.Live Export: Press C-c C-c l to turn onmarkdown-live-preview-mode
to view the exported outputside-by-side with the source Markdown. For all export commands,the output file will be overwritten without notice.markdown-live-preview-window-function
can be customized to openin a browser other thaneww
. If you want to force thepreview window to appear at the bottom or right, you cancustomizemarkdown-split-window-direction
.To summarize:
- C-c C-c m:
markdown-command
>*markdown-output*
buffer. - C-c C-c p:
markdown-command
> temporary file > browser. - C-c C-c e:
markdown-command
>basename.html
. - C-c C-c v:
markdown-command
>basename.html
> browser. - C-c C-c w:
markdown-command
> kill ring. - C-c C-c o:
markdown-open-command
. - C-c C-c l:
markdown-live-preview-mode
>*eww*
buffer.
C-c C-c c will check for undefined references. If there areany, a small buffer will open with a list of undefinedreferences and the line numbers on which they appear. In Emacs22 and greater, selecting a reference from this list andpressing RET will insert an empty reference definition at theend of the buffer. Similarly, selecting the line number willjump to the corresponding line.
C-c C-c n renumbers any ordered lists in the buffer that areout of sequence.
C-c C-c ] completes all headings and normalizes all horizontalrules in the buffer.
- C-c C-c m:
Following Links: C-c C-o
Press C-c C-o when the point is on an inline or referencelink to open the URL in a browser. When the point is at awiki link, open it in another buffer (in the current window,or in the other window with the C-u prefix). Use M-p andM-n to quickly jump to the previous or next link of any type.
Doing Things: C-c C-d
Use C-c C-d to do something sensible with the object at the point:
- Jumps between reference links and reference definitions.If more than one link uses the same reference label, awindow will be shown containing clickable buttons forjumping to each link. Pressing TAB or S-TAB cyclesbetween buttons in this window.
- Jumps between footnote markers and footnote text.
- Toggles the completion status of GFM task list items(checkboxes).
Promotion and Demotion: C-c C– and C-c C-=
Headings, horizontal rules, and list items can be promoted anddemoted, as well as bold and italic text. For headings,“promotion” means decreasing the level (i.e., moving from
<h2>
to<h1>
) while “demotion” means increasing thelevel. For horizontal rules, promotion and demotion meansmoving backward or forward through the list of rule strings inmarkdown-hr-strings
. For bold and italic text, promotion anddemotion means changing the markup from underscores to asterisks.Press C-c C– or C-c LEFT to promote the element at the pointif possible.To remember these commands, note that - is for decreasing thelevel (promoting), and = (on the same key as +) is forincreasing the level (demoting). Similarly, the left and rightarrow keys indicate the direction that the atx heading markupis moving in when promoting or demoting.
Completion: C-c C-]
Complete markup is in normalized form, which means, forexample, that the underline portion of a setext header is thesame length as the heading text, or that the number of leadingand trailing hash marks of an atx header are equal and thatthere is no extra whitespace in the header text. C-c C-]completes the markup at the point, if it is determined to beincomplete.
Editing Lists: M-RET, C-c UP, C-c DOWN, C-c LEFT, and C-c RIGHT
New list items can be inserted with M-RET or C-c C-j. Thiscommand determines the appropriate marker (one of the possibleunordered list markers or the next number in sequence for anordered list) and indentation level by examining nearby listitems. If there is no list before or after the point, start anew list. As with heading insertion, you may prefix thiscommand by C-u to decrease the indentation by one level.Prefix this command by C-u C-u to increase the indentation byone level.
Existing list items (and their nested sub-items) can be movedup or down with C-c UP or C-c DOWN and indented oroutdented with C-c RIGHT or C-c LEFT.
Editing Subtrees: C-c UP, C-c DOWN, C-c LEFT, and C-c RIGHT
Entire subtrees of ATX headings can be promoted and demotedwith C-c LEFT and C-c RIGHT, which are the same keybindingsused for promotion and demotion of list items. If the point is ina list item, the operate on the list item. Otherwise, they operateon the current heading subtree. Similarly, subtrees can bemoved up and down with C-c UP and C-c DOWN.
These commands currently do not work properly if there areSetext headings in the affected region.
Please note the following “boundary” behavior for promotion anddemotion. Any level-six headings will not be demoted further(i.e., they remain at level six, since Markdown and HTML defineonly six levels) and any level-one headings will promoted awayentirely (i.e., heading markup will be removed, since alevel-zero heading is not defined).
Shifting the Region: C-c < and C-c >
Text in the region can be indented or outdented as a group usingC-c > to indent to the next indentation point (calculated inthe current context), and C-c < to outdent to the previousindentation point. These keybindings are the same as those forsimilar commands in
python-mode
.Killing Elements: C-c C-k
Press C-c C-k to kill the thing at point and add importanttext, without markup, to the kill ring. Possible things tokill include (roughly in order of precedece): inline code,headings, horizonal rules, links (add link text to kill ring),images (add alt text to kill ring), angle URIs, emailaddresses, bold, italics, reference definitions (add URI tokill ring), footnote markers and text (kill both marker andtext, add text to kill ring), and list items.
Outline Navigation: C-c C-n, C-c C-p, C-c C-f, C-c C-b, and C-c C-u
These keys are used for hierarchical navigation in lists andheadings. When the point is in a list, they move between listitems. Otherwise, they move between headings. Use C-c C-n andC-c C-p to move between the next and previous visibleheadings or list items of any level. Similarly, C-c C-f andC-c C-b move to the next and previous visible headings orlist items at the same level as the one at the point. Finally,C-c C-u will move up to the parent heading or list item.
Movement by Markdown paragraph: M-{, M-}, and M-h
Paragraphs in
markdown-mode
are regular paragraphs,paragraphs inside blockquotes, individual list items, headings,etc. These keys are usually bound toforward-paragraph
andbackward-paragraph
, but the built-in Emacs functions arebased on simple regular expressions that fail in Markdownfiles. Instead, they are bound tomarkdown-forward-paragraph
andmarkdown-backward-paragraph
. To mark a paragraph,you can use M-h (markdown-mark-paragraph
).Movement by Markdown block: C-M-{, C-M-}, and C-c M-h
Markdown blocks are regular paragraphs in many cases, butcontain many paragraphs in other cases: blocks are consideredto be entire lists, entire code blocks, and entire blockquotes.To move backward one block use C-M-{(
markdown-beginning-block
) and to move forward use C-M-}(markdown-end-of-block
). To mark a block, use C-c M-h(markdown-mark-block
).Movement by Defuns: C-M-a, C-M-e, and C-M-h
The usual Emacs commands can be used to move by defuns(top-level major definitions). In markdown-mode, a defun is asection. As usual, C-M-a will move the point to thebeginning of the current or preceding defun, C-M-e will moveto the end of the current or following defun, and C-M-h willput the region around the entire defun.
Miscellaneous Commands:
When the
edit-indirect
package is installed, C-c ’(markdown-edit-code-block
) can be used to edit a code blockin an indirect buffer in the native major mode. Press C-c C-cto commit changes and return or C-c C-k to cancel.
As noted, many of the commands above behave differently dependingon whether Transient Mark mode is enabled or not. When it makessense, if Transient Mark mode is on and the region is active, thecommand applies to the text in the region (e.g., C-c C-s b makes theregion bold). For users who prefer to work outside of TransientMark mode, since Emacs 22 it can be enabled temporarily by pressingC-SPC C-SPC. When this is not the case, many commands thenproceed to look work with the word or line at the point.
When applicable, commands that specifically act on the region evenoutside of Transient Mark mode have the same keybinding as theirstandard counterpart, but the letter is uppercase. For example,markdown-insert-blockquote
is bound to C-c C-s q and only acts onthe region in Transient Mark mode while markdown-blockquote-region
is bound to C-c C-s Q and always applies to the region (when nonempty).
Note that these region-specific functions are useful in manycases where it may not be obvious. For example, yanking text fromthe kill ring sets the mark at the beginning of the yanked textand moves the point to the end. Therefore, the (inactive) regioncontains the yanked text. So, C-y followed by C-c C-s Q willyank text and turn it into a blockquote.
markdown-mode attempts to be flexible in how it handlesindentation. When you press TAB repeatedly, the point will cyclethrough several possible indentation levels corresponding to thingsyou might have in mind when you press RET at the end of a line orTAB. For example, you may want to start a new list item,continue a list item with hanging indentation, indent for a nestedpre block, and so on. Outdenting is handled similarly when backspaceis pressed at the beginning of the non-whitespace portion of a line.
markdown-mode supports outline-minor-mode as well as org-mode-stylevisibility cycling for atx- or hash-style headings. There are twotypes of visibility cycling: Pressing S-TAB cycles globally betweenthe table of contents view (headings only), outline view (top-levelheadings only), and the full document view. Pressing TAB while thepoint is at a heading will cycle through levels of visibility for thesubtree: completely folded, visible children, and fully visible.Note that mixing hash and underline style headings will give undesiredresults.
Customization
Although no configuration is necessary there are a few thingsthat can be customized. The M-x customize-mode commandprovides an interface to all of the possible customizations:
markdown-command
- the command used to run Markdown (default:markdown
). This variable may be customized to passcommand-line options to your Markdown processor of choice.markdown-command-needs-filename
- set tot
ifmarkdown-command
does not accept standard input (default:nil
). Whennil
,markdown-mode
will pass the Markdowncontent tomarkdown-command
using standard input (stdin
).When set tot
,markdown-mode
will pass the name of the fileas the final command-line argument tomarkdown-command
. Notethat in the latter case, you will only be able to runmarkdown-command
from buffers which are visiting a file.markdown-open-command
- the command used for calling a standaloneMarkdown previewer which is capable of opening Markdown source filesdirectly (default:nil
). This command will be calledwith a single argument, the filename of the current buffer.A representative program is the Mac app Marked 2, alive-updating Markdown previewer which can be called from asimple shell script.markdown-hr-strings
- list of strings to use when insertinghorizontal rules. Different strings will not be distinguishedwhen converted to HTML–they will all be converted to<hr/>
–but they may add visual distinction and style to plaintext documents. To maintain some notion of promotion anddemotion, keep these sorted from largest to smallest.markdown-bold-underscore
- set to a non-nil value to use twounderscores when inserting bold text instead of two asterisks(default:nil
).markdown-italic-underscore
- set to a non-nil value to useunderscores when inserting italic text instead of asterisks(default:nil
).markdown-asymmetric-header
- set to a non-nil value to useasymmetric header styling, placing header characters only onthe left of headers (default:nil
).markdown-header-scaling
- set to a non-nil value to usea variable-pitch font for headings where the size correspondsto the level of the heading (default:nil
).markdown-header-scaling-values
- list of scaling values,relative to baseline, for headers of levels one through six,used whenmarkdown-header-scaling
is non-nil(default:(2.0 1.7 1.4 1.1 1.0 1.0)
).markdown-list-indent-width
- depth of indentation for listswhen inserting, promoting, and demoting list items (default: 4).markdown-indent-function
- the function to use for automaticindentation (default:markdown-indent-line
).markdown-indent-on-enter
- Set to a non-nil value toautomatically indent new lines when RET is pressed.Set toindent-and-new-item
to additionally continue listswhen RET is pressed (default:t
).markdown-enable-wiki-links
- syntax highlighting for wikilinks (default:nil
). Set this to a non-nil value to turn onwiki link support by default. Wiki link support can be toggledlater using the functionmarkdown-toggle-wiki-links
.'markdown-wiki-link-alias-first
- set to a non-nil value totreat aliased wiki links like[[link text|PageName]]
(default:t
). When set to nil, they will be treated as[[PageName|link text]]
.markdown-uri-types
- a list of protocol schemes (e.g., “http”)for URIs thatmarkdown-mode
should highlight.markdown-enable-math
- font lock for inline and display LaTeXmath expressions (default:nil
). Set this tot
to turn onmath support by default. Math support can be toggledinteractively later using C-c C-x C-e(markdown-toggle-math
).markdown-css-paths
- CSS files to link to in XHTML output(default:nil
).markdown-content-type
- when set to a nonempty string, anhttp-equiv
attribute will be included in the XHTML<head>
block (default:'
). If needed, the suggested values areapplication/xhtml+xml
ortext/html
. See also:markdown-coding-system
.markdown-coding-system
- used for specifying the characterset identifier in thehttp-equiv
attribute when included(default:nil
). Seemarkdown-content-type
, which mustbe set before this variable has any effect. When set tonil
,buffer-file-coding-system
will be used to automaticallydetermine the coding system string (falling back toiso-8859-1
when unavailable). Common settings areutf-8
andiso-latin-1
.markdown-xhtml-header-content
- additional content to includein the XHTML<head>
block (default:'
).markdown-xhtml-standalone-regexp
- a regular expression whichmarkdown-mode
uses to determine whether the output ofmarkdown-command
is a standalone XHTML document or an XHTMLfragment (default:'^(<?xml|<!DOCTYPE|<html)'
). Ifthis regular expression not matched in the first five lines ofoutput,markdown-mode
assumes the output is a fragment andadds a header and footer.markdown-link-space-sub-char
- a character to replace spaceswhen mapping wiki links to filenames (default:'_'
).For example, use an underscore for compatibility with thePython Markdown WikiLinks extension. Ingfm-mode
, this isset to'-'
to conform with GitHub wiki links.markdown-reference-location
- where to insert referencedefinitions (default:header
). The possible locations arethe end of the document (end
), after the current block(immediately
), the end of the current subtree (subtree
),or before the next header (header
).markdown-footnote-location
- where to insert footnote text(default:end
). The set of location options is the same asformarkdown-reference-location
.markdown-nested-imenu-heading-index
- Use nested imenuheading instead of a flat index (default:t
). A nestedindex may provide more natural browsing from the menu, but aflat list may allow for faster keyboard navigation via tabcompletion.comment-auto-fill-only-comments
- variable is madebuffer-local and set tonil
by default. In programminglanguage modes, when this variable is non-nil, only commentswill be filled by auto-fill-mode. However, comments inMarkdown documents are rare and the most users probably intendfor the actual content of the document to be filled. Makingthis variable buffer-local allowsmarkdown-mode
to overridethe default behavior induced when the global variable is non-nil.markdown-gfm-additional-languages
, - additional languages tomake available, aside from those predefined inmarkdown-gfm-recognized-languages
, when inserting GFM codeblocks (default:nil
). Language strings must have be trimmedof whitespace and not contain any curly braces. They may be ofarbitrary capitalization, though.markdown-gfm-use-electric-backquote
- usemarkdown-electric-backquote
for interactive insertion of GFMcode blocks when backquote is pressed three times (default:t
).markdown-make-gfm-checkboxes-buttons
- Whether GitHubFlavored Markdown style task lists (checkboxes) should beturned into buttons that can be toggled with mouse–1 or RET. Ifnon-nil (default), then buttons are enabled. This works inmarkdown-mode
as well asgfm-mode
.markdown-hide-urls
- Determines whether URL and referencelabels are hidden for inline and reference links (default:nil
).When non-nil, inline links will appear in the buffer as[link](∞)
instead of[link](http://perhaps.a/very/long/url/)
. To change theplaceholder (composition) character used, set the variablemarkdown-url-compose-char
. URL hiding can be toggledinteractively using C-c C-x C-l (markdown-toggle-url-hiding
)or from the Markdown | Links & Images menu.markdown-hide-markup
- Determines whether all possible markupis hidden or otherwise beautified (default:nil
). The actualbuffer text remains unchanged, but the display will be altered.Brackets and URLs for links will be hidden, asterisks andunderscores for italic and bold text will be hidden, textbullets for unordered lists will be replaced by Unicodebullets, and so on. Since this includes URLs and referencelabels, when non-nil this setting supersedesmarkdown-hide-urls
.Markup hiding can be toggled using C-c C-x C-m(markdown-toggle-markup-hiding
) or from the Markdown | Show &Hide menu.Unicode bullets are used to replace ASCII list item markers.The list of characters used, in order of list level, can bespecified by setting the variable
markdown-list-item-bullets
.The placeholder characters used to replace other markup canbe changed by customizing the corresponding variables:markdown-blockquote-display-char
,markdown-hr-display-char
, andmarkdown-definition-display-char
.markdown-fontify-code-blocks-natively
- Whether to fontifycode in code blocks using the native major mode. This onlyworks for fenced code blocks where the language is specifiedwhere we can automatically determine the appropriate mode touse. The language to mode mapping may be customized by settingthe variablemarkdown-code-lang-modes
. This can be toggledinteractively by pressing C-c C-x C-f(markdown-toggle-fontify-code-blocks-natively
).markdown-gfm-uppercase-checkbox
- When non-nil, complete GFMtask list items with[X]
instead of[x]
(default:nil
).This is useful for compatibility withorg-mode
, which doesn’trecognize the lowercase variant.
Additionally, the faces used for syntax highlighting can be modified toyour liking by issuing M-x customize-group RET markdown-facesor by using the “Markdown Faces” link at the bottom of the modecustomization screen.
Extensions
Besides supporting the basic Markdown syntax, Markdown Mode alsoincludes syntax highlighting for [[Wiki Links]]
. This can beenabled by setting markdown-enable-wiki-links
to a non-nil value.Wiki links may be followed by pressing C-c C-o when the pointis at a wiki link. Use M-p and M-n to quickly jump to theprevious and next links (including links of other types).Aliased or piped wiki links of the form [[link text|PageName]]
are also supported. Since some wikis reverse these components, setmarkdown-wiki-link-alias-first
to nil to treat them as[[PageName|link text]]
. If markdown-wiki-link-fontify-missing
is also non-nil, Markdown Mode will highlight wiki links withmissing target file in a different color. By default, MarkdownMode only searches for target files in the current directory.Search in subdirectories can be enabled by settingmarkdown-wiki-link-search-subdirectories
to a non-nil value.Sequential parent directory search (as in Ikiwiki) can beenabled by setting markdown-wiki-link-search-parent-directories
to a non-nil value.
SmartyPants support is possible by customizing markdown-command
.If you install SmartyPants.pl
at, say, /usr/local/bin/smartypants
,then you can set markdown-command
to 'markdown | smartypants'
.You can do this either by using M-x customize-group markdownor by placing the following in your .emacs
file:
Syntax highlighting for mathematical expressions writtenin LaTeX (only expressions denoted by $..$
, $$..$$
, or [..]
)can be enabled by setting markdown-enable-math
to a non-nil value,either via customize or by placing (setq markdown-enable-math t)
in .emacs
, and then restarting Emacs or callingmarkdown-reload-extensions
.
GitHub Flavored Markdown (GFM)
A GitHub Flavored Markdown mode, gfm-mode
, is alsoavailable. The GitHub implementation differs slightly fromstandard Markdown in that it supports things like differentbehavior for underscores inside of words, automatic linking ofURLs, strikethrough text, and fenced code blocks with an optionallanguage keyword.
The GFM-specific features above apply to README.md
files, wikipages, and other Markdown-formatted files in repositories onGitHub. GitHub also enables additional features forwriting on the site (for issues, pull requests, messages, etc.)that are further extensions of GFM. These features include tasklists (checkboxes), newlines corresponding to hard line breaks,auto-linked references to issues and commits, wiki links, and soon. To make matters more confusing, although task lists are notpart of GFM proper, since 2014 they are rendered (in aread-only fashion) in all Markdown documents in repositories on thesite. These additional extensions are supported to varying degreesby markdown-mode
and gfm-mode
as described below.
URL autolinking: Both
markdown-mode
andgfm-mode
support highlighting of URLs without angle brackets.Multiple underscores in words: You must enable
gfm-mode
to toggle support for underscores inside of words. In this mode variable names such asa_test_variable
will not trigger emphasis (italics).Fenced code blocks: Code blocks quoted with backquotes, with optional programming language keywords, are highlighted in both
markdown-mode
andgfm-mode
. They can be inserted with C-c C-s P. If there is an active region, the text in the region will be placed inside the code block. You will be prompted for the name of the language, but may press enter to continue without naming a language.Strikethrough: Strikethrough text is only supported in
gfm-mode
and can be inserted (and toggled) using C-c C-s d. Following the mnemonics for the other style keybindings, the letter d coincides with the HTML tag<del>
.Task lists:GFM task lists will be rendered as checkboxes (Emacs buttons) in both
markdown-mode
andgfm-mode
whenmarkdown-make-gfm-checkboxes-buttons
is set to a non-nil value (and it is set to t by default). These checkboxes can be toggled by clickingmouse-1
, pressing RET over the button, or by pressing C-c C-x C-x with the point anywhere in the task list item.Wiki links: Generic wiki links are supported in
markdown-mode
, but ingfm-mode
specifically they will be treated as they are on GitHub: spaces will be replaced by hyphens in filenames and the first letter of the filename will be capitalized. For example,[[wiki link]]
will map to a file namedWiki-link
with the same extension as the current file. If a file with this name does not exist in the current directory, the first match in a subdirectory, if any, will be used instead.Newlines: Neither
markdown-mode
norgfm-mode
do anything specifically with respect to newline behavior. If you usegfm-mode
mostly to write text for comments or issues on the GitHub site–where newlines are significant and correspond to hard line breaks–then you may want to enablevisual-line-mode
for line wrapping in buffers. You can do this with agfm-mode-hook
as follows:Preview:GFM-specific preview can be powered by setting
markdown-command
to use Docter. This may also be configured to work with Marked 2 formarkdown-open-command
.
Acknowledgments
markdown-mode has benefited greatly from the efforts of the manyvolunteers who have sent patches, test cases, bug reports,suggestions, helped with packaging, etc. Thank you for yourcontributions! See the contributors graph for details.
Bugs
markdown-mode is developed and tested primarily for compatibilitywith GNU Emacs 24.3 and later. If you find any bugs inmarkdown-mode, please construct a test case or a patch and open aticket on the GitHub issue tracker. See thecontributing guidelines in CONTRIBUTING.md
for details oncreating pull requests.
History
markdown-mode was written and is maintained by Jason Blevins. Thefirst version was released on May 24, 2007.
- 2007–05–24: Version 1.1
- 2007–05–25: Version 1.2
- 2007–06–05: Version 1.3
- 2007–06–29: Version 1.4
- 2007–10–11: Version 1.5
- 2008–06–04: Version 1.6
- 2009–10–01: Version 1.7
- 2011–08–12: Version 1.8
- 2011–08–15: Version 1.8.1
- 2013–01–25: Version 1.9
- 2013–03–24: Version 2.0
- 2016–01–09: Version 2.1
- 2017–05–26: Version 2.2
- 2017–08–31: Version 2.3