markdown-mode 2.2
[markdown-mode.git] / README.md
blobae2b9b7fd3d9af5ab7cac18182afec6f6a3dada7
1 # Emacs Markdown Mode [![MELPA badge][melpa-badge]][melpa-link] [![MELPA stable badge][melpa-stable-badge]][melpa-stable-link] [![Travis CI Build Status][travis-badge]][travis-link] [![Guide to Markdown Mode for Emacs][leanpub-badge]][leanpub-link]
3   [melpa-link]: https://melpa.org/#/markdown-mode
4   [melpa-stable-link]: https://stable.melpa.org/#/markdown-mode
5   [melpa-badge]: https://melpa.org/packages/markdown-mode-badge.svg
6   [melpa-stable-badge]: https://stable.melpa.org/packages/markdown-mode-badge.svg
7   [travis-link]: https://travis-ci.org/jrblevin/markdown-mode
8   [travis-badge]: https://travis-ci.org/jrblevin/markdown-mode.svg?branch=master
9   [leanpub-link]: https://leanpub.com/markdown-mode
10   [leanpub-badge]: https://img.shields.io/badge/leanpub-guide-orange.svg
12 <!-- This file is autogenerated by webpage.sh from the comments at the top of
13      markdown-mode.el. Make edits there, not here. -->
15 markdown-mode is a major mode for editing [Markdown][]-formatted
16 text. The latest stable version is markdown-mode 2.2, released on
17 May 26, 2017. See the [release notes][] for details.
18 markdown-mode is free software, licensed under the GNU GPL v2.
20 ![Markdown Mode Screenshot](http://jblevins.org/projects/markdown-mode/screenshots/20160108-001.png)
22 [Markdown]: http://daringfireball.net/projects/markdown/
23 [release notes]: http://jblevins.org/projects/markdown-mode/rev-2-2
25 ## Documentation
27 <a href="https://leanpub.com/markdown-mode"><img src="http://jblevins.org/projects/markdown-mode/guide-v2.2.png" align="right" height="350" width="252"></a>
29 Documentation for Markdown Mode is available below, but Emacs is also
30 a self-documenting editor.  That means that the source code itself
31 contains additional documentation: each function has its own docstring
32 available via <kbd>C-h f</kbd> (`describe-function`), individual keybindings
33 can be investigated with <kbd>C-h k</kbd> (`describe-key`), and a complete list
34 of keybindings is available using <kbd>C-h m</kbd> (`describe-mode`).
36 Additionally, to celebrate Markdown Mode's 10th birthday the package
37 creator is writing a [Guide to Markdown Mode for Emacs][guide].  This
38 ebook will supplement the existing documentation with in-depth
39 discussion of advanced movement and editing commands, configuration
40 examples, tips and tricks, and a survey of other packages that work
41 with Markdown Mode.  It will be [published at Leanpub][guide] and
42 possibly available through other channels.  Please visit
43 the [book homepage][guide] to sign up to be notified when it is ready
44 and to help determine the price.
46  [guide]: https://leanpub.com/markdown-mode
48 ## Installation
50 The recommended way to install markdown-mode is to install the package
51 from [MELPA Stable](https://stable.melpa.org/#/markdown-mode)
52 using `package.el`. First, configure `package.el` and the MELPA Stable
53 repository by adding the following to your `.emacs`, `init.el`,
54 or equivalent startup file:
56 ```lisp
57 (require 'package)
58 (add-to-list 'package-archives
59              '("melpa-stable" . "https://stable.melpa.org/packages/"))
60 (package-initialize)
61 ```
63 Then, after restarting Emacs or evaluating the above statements, issue
64 the following command: <kbd>M-x package-install RET markdown-mode RET</kbd>.
65 When installed this way, the major modes `markdown-mode` and `gfm-mode`
66 will be autoloaded and `markdown-mode` will be used for file names
67 ending in either `.md` or `.markdown`.
69 Alternatively, if you manage loading packages with [use-package][]
70 then you can automatically install and configure `markdown-mode` by
71 adding a declaration such as this one to your init file (as an
72 example; adjust settings as desired):
74 ```lisp
75 (use-package markdown-mode
76   :ensure t
77   :commands (markdown-mode gfm-mode)
78   :mode (("README\\.md\\'" . gfm-mode)
79          ("\\.md\\'" . markdown-mode)
80          ("\\.markdown\\'" . markdown-mode))
81   :init (setq markdown-command "multimarkdown"))
82 ```
84 [MELPA Stable]: http://stable.melpa.org/
85 [use-package]: https://github.com/jwiegley/use-package
87 **Direct Download**
89 Alternatively you can manually download and install markdown-mode.
90 First, download the [latest stable version][markdown-mode.el] and
91 save the file where Emacs can find it (i.e., a directory in your
92 `load-path`). You can then configure `markdown-mode` and `gfm-mode`
93 to load automatically by adding the following to your init file:
95 ```lisp
96 (autoload 'markdown-mode "markdown-mode"
97    "Major mode for editing Markdown files" t)
98 (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
99 (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
101 (autoload 'gfm-mode "markdown-mode"
102    "Major mode for editing GitHub Flavored Markdown files" t)
103 (add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode))
106 [markdown-mode.el]: http://jblevins.org/projects/markdown-mode/markdown-mode.el
108 **Development Version**
110 To follow or contribute to markdown-mode development, you can
111 browse or clone the Git repository
112 [on GitHub](https://github.com/jrblevin/markdown-mode):
115 git clone https://github.com/jrblevin/markdown-mode.git
118 If you prefer to install and use the development version, which may
119 become unstable at some times, you can either clone the Git
120 repository as above or install markdown-mode from
121 [MELPA](https://melpa.org/#/markdown-mode).
123 If you clone the repository directly, then make sure that Emacs can
124 find it by adding the following line to your startup file:
126 ```lisp
127 (add-to-list 'load-path "/path/to/markdown-mode/repository")
130 **Packaged Installation**
132 markdown-mode is also available in several package managers. You
133 may want to confirm that the package you install contains the
134 latest stable version first (and please notify the package
135 maintainer if not).
137    * Debian Linux: [elpa-markdown-mode][] and [emacs-goodies-el][]
138    * Ubuntu Linux: [elpa-markdown-mode][elpa-ubuntu] and [emacs-goodies-el][emacs-goodies-el-ubuntu]
139    * RedHat and Fedora Linux: [emacs-goodies][]
140    * NetBSD: [textproc/markdown-mode][]
141    * MacPorts: [markdown-mode.el][macports-package] ([pending][macports-ticket])
142    * FreeBSD: [textproc/markdown-mode.el][freebsd-port]
144  [elpa-markdown-mode]: https://packages.debian.org/sid/lisp/elpa-markdown-mode
145  [elpa-ubuntu]: http://packages.ubuntu.com/search?keywords=elpa-markdown-mode
146  [emacs-goodies-el]: http://packages.debian.org/emacs-goodies-el
147  [emacs-goodies-el-ubuntu]: http://packages.ubuntu.com/search?keywords=emacs-goodies-el
148  [emacs-goodies]: https://apps.fedoraproject.org/packages/emacs-goodies
149  [textproc/markdown-mode]: http://pkgsrc.se/textproc/markdown-mode
150  [macports-package]: https://trac.macports.org/browser/trunk/dports/editors/markdown-mode.el/Portfile
151  [macports-ticket]: http://trac.macports.org/ticket/35716
152  [freebsd-port]: http://svnweb.freebsd.org/ports/head/textproc/markdown-mode.el
154 **Dependencies**
156 `markdown-mode` depends on `cl-lib`, which has been bundled with
157 GNU Emacs since 24.3.  Users of GNU Emacs 24.1 and 24.2 can install
158 `cl-lib` with `package.el`.
160 ## Usage
162 Keybindings are grouped by prefixes based on their function.  For
163 example, the commands for inserting links are grouped under `C-c
164 C-a`, where the <kbd>C-a</kbd> is a mnemonic for the HTML `<a>` tag.  In
165 other cases, the connection to HTML is not direct.  For example,
166 commands dealing with headings begin with <kbd>C-c C-t</kbd> (mnemonic:
167 titling).  The primary commands in each group will are described
168 below.  You can obtain a list of all keybindings by pressing `C-c
169 C-h`.  Movement and shifting commands tend to be associated with
170 paired delimiters such as <kbd>M-{</kbd> and <kbd>M-}</kbd> or <kbd>C-c <</kbd> and <kbd>C-c ></kbd>.
171 Outline navigation keybindings the same as in `org-mode`.  Finally,
172 commands for running Markdown or doing maintenance on an open file
173 are grouped under the <kbd>C-c C-c</kbd> prefix.  The most commonly used
174 commands are described below.  You can obtain a list of all
175 keybindings by pressing <kbd>C-c C-h</kbd>.
177   * Hyperlinks: <kbd>C-c C-a</kbd>
179     In this group, <kbd>C-c C-a l</kbd> inserts an inline link of the form
180     `[text](url)`.  The link text is determined as follows.  First,
181     if there is an active region (i.e., when transient mark mode is
182     on and the mark is active), use it as the link text.  Second,
183     if the point is at a word, use that word as the link text.  In
184     these two cases, the original text will be replaced with the
185     link and point will be left at the position for inserting a
186     URL.  Otherwise, insert empty link markup and place the point
187     for inserting the link text.
189     <kbd>C-c C-a L</kbd> inserts a reference link of the form `[text][label]`
190     and, optionally, a corresponding reference label definition.
191     The link text is determined in the same way as with an inline
192     link (using the region, when active, or the word at the point),
193     but instead of inserting empty markup as a last resort, the
194     link text will be read from the minibuffer.  The reference
195     label will be read from the minibuffer in both cases, with
196     completion from the set of currently defined references.  To
197     create an implicit reference link, press <kbd>RET</kbd> to accept the
198     default, an empty label.  If the entered referenced label is
199     not defined, additionally prompt for the URL and (optional)
200     title.  If a URL is provided, a reference definition will be
201     inserted in accordance with `markdown-reference-location`.
202     If a title is given, it will be added to the end of the
203     reference definition and will be used to populate the title
204     attribute when converted to XHTML.
206     <kbd>C-c C-a u</kbd> inserts a bare url, delimited by angle brackets.  When
207     there is an active region, the text in the region is used as the
208     URL.  If the point is at a URL, that url is used.  Otherwise,
209     insert angle brackets and position the point in between them
210     for inserting the URL.
212     <kbd>C-c C-a f</kbd> inserts a footnote marker at the point, inserts a
213     footnote definition below, and positions the point for
214     inserting the footnote text.  Note that footnotes are an
215     extension to Markdown and are not supported by all processors.
217     <kbd>C-c C-a w</kbd> behaves much like the inline link insertion command
218     and inserts a wiki link of the form `[[WikiLink]]`.  If there
219     is an active region, use the region as the link text.  If the
220     point is at a word, use the word as the link text.  If there is
221     no active region and the point is not at word, simply insert
222     link markup.  Note that wiki links are an extension to Markdown
223     and are not supported by all processors.
225   * Images: <kbd>C-c C-i</kbd>
227     <kbd>C-c C-i i</kbd> inserts markup for an inline image, using the
228     active region or the word at point, if any, as the alt text.
229     <kbd>C-c C-i I</kbd> behaves similarly and inserts a reference-style
230     image.
232     Local images associated with image links may be displayed
233     inline in the buffer by pressing <kbd>C-c C-i C-t</kbd>
234     (`markdown-toggle-inline-images`). This is a toggle command, so
235     pressing this once again will remove inline images.
237   * Styles: <kbd>C-c C-s</kbd>
239     <kbd>C-c C-s e</kbd> inserts markup to make a region or word italic (<kbd>e</kbd>
240     for `<em>` or emphasis).  If there is an active region, make
241     the region italic.  If the point is at a non-italic word, make
242     the word italic.  If the point is at an italic word or phrase,
243     remove the italic markup.  Otherwise, simply insert italic
244     delimiters and place the cursor in between them.  Similarly,
245     use <kbd>C-c C-s s</kbd> for bold (`<strong>`), <kbd>C-c C-s c</kbd> for
246     inline code (`<code>`), and <kbd>C-c C-s k</kbd> for inserting `<kbd>`
247     tags.
249     <kbd>C-c C-s b</kbd> inserts a blockquote using the active region, if any,
250     or starts a new blockquote.  <kbd>C-c C-s C-b</kbd> is a variation which
251     always operates on the region, regardless of whether it is
252     active or not.  The appropriate amount of indentation, if any,
253     is calculated automatically given the surrounding context, but
254     may be adjusted later using the region indentation commands.
256     <kbd>C-c C-s p</kbd> behaves similarly for inserting preformatted code
257     blocks, with <kbd>C-c C-s C-p</kbd> being the region-only counterpart.
259   * Headings: <kbd>C-c C-t</kbd>
261     All heading insertion commands use the text in the active
262     region, if any, as the heading text.  Otherwise, if the current
263     line is not blank, they use the text on the current line.
264     Finally, the setext commands will prompt for heading text if
265     there is no active region and the current line is blank.
267     <kbd>C-c C-t h</kbd> inserts a heading with automatically chosen type and
268     level (both determined by the previous heading).  <kbd>C-c C-t H</kbd>
269     behaves similarly, but uses setext (underlined) headings when
270     possible, still calculating the level automatically.
271     In cases where the automatically-determined level is not what
272     you intended, the level can be quickly promoted or demoted
273     (as described below).  Alternatively, a <kbd>C-u</kbd> prefix can be
274     given to insert a heading promoted by one level or a <kbd>C-u C-u</kbd>
275     prefix can be given to insert a heading demoted by one level.
277     To insert a heading of a specific level and type, use <kbd>C-c C-t 1</kbd>
278     through <kbd>C-c C-t 6</kbd> for atx (hash mark) headings and <kbd>C-c C-t !</kbd> or
279     <kbd>C-c C-t @</kbd> for setext headings of level one or two, respectively.
280     Note that <kbd>!</kbd> is <kbd>S-1</kbd> and <kbd>@</kbd> is <kbd>S-2</kbd>.
282     If the point is at a heading, these commands will replace the
283     existing markup in order to update the level and/or type of the
284     heading.  To remove the markup of the heading at the point,
285     press <kbd>C-c C-k</kbd> to kill the heading and press <kbd>C-y</kbd> to yank the
286     heading text back into the buffer.
288   * Horizontal Rules: <kbd>C-c -</kbd>
290     <kbd>C-c -</kbd> inserts a horizontal rule.  By default, insert the
291     first string in the list `markdown-hr-strings` (the most
292     prominent rule).  With a <kbd>C-u</kbd> prefix, insert the last string.
293     With a numeric prefix <kbd>N</kbd>, insert the string in position <kbd>N</kbd>
294     (counting from 1).
296   * Markdown and Maintenance Commands: <kbd>C-c C-c</kbd>
298     *Compile:* <kbd>C-c C-c m</kbd> will run Markdown on the current buffer
299     and show the output in another buffer.  *Preview*: <kbd>C-c C-c p</kbd>
300     runs Markdown on the current buffer and previews, stores the
301     output in a temporary file, and displays the file in a browser.
302     *Export:* <kbd>C-c C-c e</kbd> will run Markdown on the current buffer
303     and save the result in the file `basename.html`, where
304     `basename` is the name of the Markdown file with the extension
305     removed.  *Export and View:* press <kbd>C-c C-c v</kbd> to export the
306     file and view it in a browser.  *Open:* <kbd>C-c C-c o</kbd> will open
307     the Markdown source file directly using `markdown-open-command`.
308     *Live Export*: Press <kbd>C-c C-c l</kbd> to turn on
309     `markdown-live-preview-mode` to view the exported output
310     side-by-side with the source Markdown. **For all export commands,
311     the output file will be overwritten without notice.**
312     `markdown-live-preview-window-function` can be customized to open
313     in a browser other than `eww`.  If you want to force the
314     preview window to appear at the bottom or right, you can
315     customize `markdown-split-window-direction`.
317     To summarize:
319       - <kbd>C-c C-c m</kbd>: `markdown-command` > `*markdown-output*` buffer.
320       - <kbd>C-c C-c p</kbd>: `markdown-command` > temporary file > browser.
321       - <kbd>C-c C-c e</kbd>: `markdown-command` > `basename.html`.
322       - <kbd>C-c C-c v</kbd>: `markdown-command` > `basename.html` > browser.
323       - <kbd>C-c C-c w</kbd>: `markdown-command` > kill ring.
324       - <kbd>C-c C-c o</kbd>: `markdown-open-command`.
325       - <kbd>C-c C-c l</kbd>: `markdown-live-preview-mode` > `*eww*` buffer.
327     <kbd>C-c C-c c</kbd> will check for undefined references.  If there are
328     any, a small buffer will open with a list of undefined
329     references and the line numbers on which they appear.  In Emacs
330     22 and greater, selecting a reference from this list and
331     pressing <kbd>RET</kbd> will insert an empty reference definition at the
332     end of the buffer.  Similarly, selecting the line number will
333     jump to the corresponding line.
335     <kbd>C-c C-c n</kbd> renumbers any ordered lists in the buffer that are
336     out of sequence.
338     <kbd>C-c C-c ]</kbd> completes all headings and normalizes all horizontal
339     rules in the buffer.
341   * Following Links: <kbd>C-c C-o</kbd>
343     Press <kbd>C-c C-o</kbd> when the point is on an inline or reference
344     link to open the URL in a browser.  When the point is at a
345     wiki link, open it in another buffer (in the current window,
346     or in the other window with the <kbd>C-u</kbd> prefix).  Use <kbd>M-p</kbd> and
347     <kbd>M-n</kbd> to quickly jump to the previous or next link of any type.
349   * Jumping: <kbd>C-c C-l</kbd>
351     Use <kbd>C-c C-l</kbd> to jump from the object at point to its counterpart
352     elsewhere in the text, when possible.  Jumps between reference
353     links and definitions; between footnote markers and footnote
354     text.  If more than one link uses the same reference name, a
355     new buffer will be created containing clickable buttons for jumping
356     to each link.  You may press <kbd>TAB</kbd> or <kbd>S-TAB</kbd> to jump between
357     buttons in this window.
359   * Promotion and Demotion: <kbd>C-c C--</kbd> and <kbd>C-c C-=</kbd>
361     Headings, horizontal rules, and list items can be promoted and
362     demoted, as well as bold and italic text.  For headings,
363     "promotion" means *decreasing* the level (i.e., moving from
364     `<h2>` to `<h1>`) while "demotion" means *increasing* the
365     level.  For horizontal rules, promotion and demotion means
366     moving backward or forward through the list of rule strings in
367     `markdown-hr-strings`.  For bold and italic text, promotion and
368     demotion means changing the markup from underscores to asterisks.
369     Press <kbd>C-c C--</kbd> or <kbd>M-LEFT</kbd> to promote the element at the point
370     if possible.
372     To remember these commands, note that <kbd>-</kbd> is for decreasing the
373     level (promoting), and <kbd>=</kbd> (on the same key as <kbd>+</kbd>) is for
374     increasing the level (demoting).  Similarly, the left and right
375     arrow keys indicate the direction that the atx heading markup
376     is moving in when promoting or demoting.
378   * Completion: <kbd>C-c C-]</kbd>
380     Complete markup is in normalized form, which means, for
381     example, that the underline portion of a setext header is the
382     same length as the heading text, or that the number of leading
383     and trailing hash marks of an atx header are equal and that
384     there is no extra whitespace in the header text.  <kbd>C-c C-]</kbd>
385     completes the markup at the point, if it is determined to be
386     incomplete.
388   * Editing Lists: <kbd>M-RET</kbd>, <kbd>M-UP</kbd>, <kbd>M-DOWN</kbd>, <kbd>M-LEFT</kbd>, and <kbd>M-RIGHT</kbd>
390     New list items can be inserted with <kbd>M-RET</kbd> or <kbd>C-c C-j</kbd>.  This
391     command determines the appropriate marker (one of the possible
392     unordered list markers or the next number in sequence for an
393     ordered list) and indentation level by examining nearby list
394     items.  If there is no list before or after the point, start a
395     new list.  Prefix this command by <kbd>C-u</kbd> to decrease the
396     indentation by one level.  Prefix this command by <kbd>C-u C-u</kbd> to
397     increase the indentation by one level.
399     Existing list items can be moved up or down with <kbd>M-UP</kbd> or
400     <kbd>M-DOWN</kbd> and indented or exdented with <kbd>M-RIGHT</kbd> or <kbd>M-LEFT</kbd>.
402   * Editing Subtrees: <kbd>M-S-UP</kbd>, <kbd>M-S-DOWN</kbd>, <kbd>M-S-LEFT</kbd>, and <kbd>M-S-RIGHT</kbd>
404     Entire subtrees of ATX headings can be promoted and demoted
405     with <kbd>M-S-LEFT</kbd> and <kbd>M-S-RIGHT</kbd>, which mirror the bindings
406     for promotion and demotion of list items. Similarly, subtrees
407     can be moved up and down with <kbd>M-S-UP</kbd> and <kbd>M-S-DOWN</kbd>.
409     Please note the following "boundary" behavior for promotion and
410     demotion.  Any level-six headings will not be demoted further
411     (i.e., they remain at level six, since Markdown and HTML define
412     only six levels) and any level-one headings will promoted away
413     entirely (i.e., heading markup will be removed, since a
414     level-zero heading is not defined).
416   * Shifting the Region: <kbd>C-c <</kbd> and <kbd>C-c ></kbd>
418     Text in the region can be indented or exdented as a group using
419     <kbd>C-c ></kbd> to indent to the next indentation point (calculated in
420     the current context), and <kbd>C-c <</kbd> to exdent to the previous
421     indentation point.  These keybindings are the same as those for
422     similar commands in `python-mode`.
424   * Killing Elements: <kbd>C-c C-k</kbd>
426     Press <kbd>C-c C-k</kbd> to kill the thing at point and add important
427     text, without markup, to the kill ring.  Possible things to
428     kill include (roughly in order of precedece): inline code,
429     headings, horizonal rules, links (add link text to kill ring),
430     images (add alt text to kill ring), angle URIs, email
431     addresses, bold, italics, reference definitions (add URI to
432     kill ring), footnote markers and text (kill both marker and
433     text, add text to kill ring), and list items.
435   * Outline Navigation: <kbd>C-c C-n</kbd>, <kbd>C-c C-p</kbd>, <kbd>C-c C-f</kbd>, <kbd>C-c C-b</kbd>, and <kbd>C-c C-u</kbd>
437     Navigation between headings is possible using `outline-mode`.
438     Use <kbd>C-c C-n</kbd> and <kbd>C-c C-p</kbd> to move between the next and previous
439     visible headings.  Similarly, <kbd>C-c C-f</kbd> and <kbd>C-c C-b</kbd> move to the
440     next and previous visible headings at the same level as the one
441     at the point.  Finally, <kbd>C-c C-u</kbd> will move up to a lower-level
442     (higher precedence) visible heading.
444   * Movement by Paragraph or Block: <kbd>M-{</kbd> and <kbd>M-}</kbd>
446     These keys are usually bound to `forward-paragraph` and
447     `backward-paragraph`, but those built-in Emacs functions are
448     based on simple regular expressions and can fail in Markdown.
449     Blocks in `markdown-mode` are code blocks, blockquotes, list
450     items, headings, horizontal rules, or plain text paragraphs
451     separated by whitespace.  Instead, they are bound to
452     `markdown-forward-block` and `markdown-backward-block`.
453     To mark or narrow to a block, you can use <kbd>M-h</kbd>
454     (`markdown-mark-block`) and <kbd>C-x n b</kbd>
455     (`markdown-narrow-to-block`).
457   * Movement by Defun: <kbd>C-M-a</kbd>, <kbd>C-M-e</kbd>, and <kbd>C-M-h</kbd>
459     The usual Emacs commands can be used to move by defuns
460     (top-level major definitions).  In markdown-mode, a defun is a
461     section.  As usual, <kbd>C-M-a</kbd> will move the point to the
462     beginning of the current or preceding defun, <kbd>C-M-e</kbd> will move
463     to the end of the current or following defun, and <kbd>C-M-h</kbd> will
464     put the region around the entire defun.
466 As noted, many of the commands above behave differently depending
467 on whether Transient Mark mode is enabled or not.  When it makes
468 sense, if Transient Mark mode is on and the region is active, the
469 command applies to the text in the region (e.g., <kbd>C-c C-s s</kbd> makes the
470 region bold).  For users who prefer to work outside of Transient
471 Mark mode, since Emacs 22 it can be enabled temporarily by pressing
472 <kbd>C-SPC C-SPC</kbd>.  When this is not the case, many commands then
473 proceed to look work with the word or line at the point.
475 When applicable, commands that specifically act on the region even
476 outside of Transient Mark mode have the same keybinding as their
477 standard counterpart, but the letter is uppercase.  For example,
478 `markdown-insert-blockquote` is bound to <kbd>C-c C-s b</kbd> and only acts on
479 the region in Transient Mark mode while `markdown-blockquote-region`
480 is bound to <kbd>C-c C-s B</kbd> and always applies to the region (when nonempty).
482 Note that these region-specific functions are useful in many
483 cases where it may not be obvious.  For example, yanking text from
484 the kill ring sets the mark at the beginning of the yanked text
485 and moves the point to the end.  Therefore, the (inactive) region
486 contains the yanked text.  So, <kbd>C-y</kbd> followed by <kbd>C-c C-s C-b</kbd> will
487 yank text and turn it into a blockquote.
489 markdown-mode attempts to be flexible in how it handles
490 indentation.  When you press <kbd>TAB</kbd> repeatedly, the point will cycle
491 through several possible indentation levels corresponding to things
492 you might have in mind when you press <kbd>RET</kbd> at the end of a line or
493 <kbd>TAB</kbd>.  For example, you may want to start a new list item,
494 continue a list item with hanging indentation, indent for a nested
495 pre block, and so on.  Exdention is handled similarly when backspace
496 is pressed at the beginning of the non-whitespace portion of a line.
498 markdown-mode supports outline-minor-mode as well as org-mode-style
499 visibility cycling for atx- or hash-style headings.  There are two
500 types of visibility cycling: Pressing <kbd>S-TAB</kbd> cycles globally between
501 the table of contents view (headings only), outline view (top-level
502 headings only), and the full document view.  Pressing <kbd>TAB</kbd> while the
503 point is at a heading will cycle through levels of visibility for the
504 subtree: completely folded, visible children, and fully visible.
505 Note that mixing hash and underline style headings will give undesired
506 results.
508 ## Customization
510 Although no configuration is *necessary* there are a few things
511 that can be customized.  The <kbd>M-x customize-mode</kbd> command
512 provides an interface to all of the possible customizations:
514   * `markdown-command` - the command used to run Markdown (default:
515     `markdown`).  This variable may be customized to pass
516     command-line options to your Markdown processor of choice.
518   * `markdown-command-needs-filename` - set to `t` if
519     `markdown-command` does not accept standard input (default:
520     `nil`).  When `nil`, `markdown-mode` will pass the Markdown
521     content to `markdown-command` using standard input (`stdin`).
522     When set to `t`, `markdown-mode` will pass the name of the file
523     as the final command-line argument to `markdown-command`.  Note
524     that in the latter case, you will only be able to run
525     `markdown-command` from buffers which are visiting a file.
527   * `markdown-open-command` - the command used for calling a standalone
528     Markdown previewer which is capable of opening Markdown source files
529     directly (default: `nil`).  This command will be called
530     with a single argument, the filename of the current buffer.
531     A representative program is the Mac app [Marked 2][], a
532     live-updating Markdown previewer which can be [called from a
533     simple shell script](http://jblevins.org/log/marked-2-command).
535   * `markdown-hr-strings` - list of strings to use when inserting
536     horizontal rules.  Different strings will not be distinguished
537     when converted to HTML--they will all be converted to
538     `<hr/>`--but they may add visual distinction and style to plain
539     text documents.  To maintain some notion of promotion and
540     demotion, keep these sorted from largest to smallest.
542   * `markdown-bold-underscore` - set to a non-nil value to use two
543     underscores when inserting bold text instead of two asterisks
544     (default: `nil`).
546   * `markdown-italic-underscore` - set to a non-nil value to use
547     underscores when inserting italic text instead of asterisks
548     (default: `nil`).
550   * `markdown-asymmetric-header` - set to a non-nil value to use
551     asymmetric header styling, placing header characters only on
552     the left of headers (default: `nil`).
554   * `markdown-header-scaling` - set to a non-nil value to use
555     a variable-pitch font for headings where the size corresponds
556     to the level of the heading (default: `nil`).
558   * `markdown-header-scaling-values` - list of scaling values,
559     relative to baseline, for headers of levels one through six,
560     used when `markdown-header-scaling` is non-nil
561     (default: `(1.8 1.4 1.2 1.0 1.0 1.0)`).
563   * `markdown-list-indent-width` - depth of indentation for lists
564     when inserting, promoting, and demoting list items (default: 4).
566   * `markdown-indent-function` - the function to use for automatic
567     indentation (default: `markdown-indent-line`).
569   * `markdown-indent-on-enter` - Set to a non-nil value to
570     automatically indent new lines when <kbd>RET</kbd> is pressed.
571     Set to `indent-and-new-item` to additionally continue lists
572     when <kbd>RET</kbd> is pressed (default: `t`).
574   * `markdown-enable-wiki-links` - syntax highlighting for wiki
575     links (default: `nil`).  Set this to a non-nil value to turn on
576     wiki link support by default.  Wiki link support can be toggled
577     later using the function `markdown-toggle-wiki-links`."
579   * `markdown-wiki-link-alias-first` - set to a non-nil value to
580     treat aliased wiki links like `[[link text|PageName]]`
581     (default: `t`).  When set to nil, they will be treated as
582     `[[PageName|link text]]`.
584   * `markdown-uri-types` - a list of protocol schemes (e.g., "http")
585     for URIs that `markdown-mode` should highlight.
587   * `markdown-enable-math` - syntax highlighting for LaTeX
588     fragments (default: `nil`).  Set this to `t` to turn on math
589     support by default.  Math support can be enabled, disabled, or
590     toggled later using the function `markdown-toggle-math`."
592   * `markdown-css-paths` - CSS files to link to in XHTML output
593     (default: `nil`).
595   * `markdown-content-type` - when set to a nonempty string, an
596     `http-equiv` attribute will be included in the XHTML `<head>`
597     block (default: `""`).  If needed, the suggested values are
598     `application/xhtml+xml` or `text/html`.  See also:
599     `markdown-coding-system`.
601   * `markdown-coding-system` - used for specifying the character
602     set identifier in the `http-equiv` attribute when included
603     (default: `nil`).  See `markdown-content-type`, which must
604     be set before this variable has any effect.  When set to `nil`,
605     `buffer-file-coding-system` will be used to automatically
606     determine the coding system string (falling back to
607     `iso-8859-1` when unavailable).  Common settings are `utf-8`
608     and `iso-latin-1`.
610   * `markdown-xhtml-header-content` - additional content to include
611     in the XHTML `<head>` block (default: `""`).
613   * `markdown-xhtml-standalone-regexp` - a regular expression which
614     `markdown-mode` uses to determine whether the output of
615     `markdown-command` is a standalone XHTML document or an XHTML
616     fragment (default: `"^\\(<\\?xml\\|<!DOCTYPE\\|<html\\)"`).  If
617     this regular expression not matched in the first five lines of
618     output, `markdown-mode` assumes the output is a fragment and
619     adds a header and footer.
621   * `markdown-link-space-sub-char` - a character to replace spaces
622     when mapping wiki links to filenames (default: `"_"`).
623     For example, use an underscore for compatibility with the
624     Python Markdown WikiLinks extension.  In `gfm-mode`, this is
625     set to `"-"` to conform with GitHub wiki links.
627   * `markdown-reference-location` - where to insert reference
628     definitions (default: `header`).  The possible locations are
629     the end of the document (`end`), after the current block
630     (`immediately`), before the next header (`header`).
632   * `markdown-footnote-location` - where to insert footnote text
633     (default: `end`).  The set of location options is the same as
634     for `markdown-reference-location`.
636   * `markdown-nested-imenu-heading-index` - Use nested imenu
637     heading instead of a flat index (default: `t`).  A nested
638     index may provide more natural browsing from the menu, but a
639     flat list may allow for faster keyboard navigation via tab
640     completion.
642   * `comment-auto-fill-only-comments` - variable is made
643     buffer-local and set to `nil` by default.  In programming
644     language modes, when this variable is non-nil, only comments
645     will be filled by auto-fill-mode.  However, comments in
646     Markdown documents are rare and the most users probably intend
647     for the actual content of the document to be filled.  Making
648     this variable buffer-local allows `markdown-mode` to override
649     the default behavior induced when the global variable is non-nil.
651   * `markdown-gfm-additional-languages`, - additional languages to
652     make available, aside from those predefined in
653     `markdown-gfm-recognized-languages`, when inserting GFM code
654     blocks (default: `nil`). Language strings must have be trimmed
655     of whitespace and not contain any curly braces. They may be of
656     arbitrary capitalization, though.
658   * `markdown-gfm-use-electric-backquote` - use
659     `markdown-electric-backquote` for interactive insertion of GFM
660     code blocks when backquote is pressed three times (default: `t`).
662   * `markdown-make-gfm-checkboxes-buttons` - Whether GitHub
663     Flavored Markdown style task lists (checkboxes) should be
664     turned into buttons that can be toggled with mouse-1 or RET. If
665     non-nil (default), then buttons are enabled.  This works in
666     `markdown-mode` as well as `gfm-mode`.
668 Additionally, the faces used for syntax highlighting can be modified to
669 your liking by issuing <kbd>M-x customize-group RET markdown-faces</kbd>
670 or by using the "Markdown Faces" link at the bottom of the mode
671 customization screen.
673 [Marked 2]: https://itunes.apple.com/us/app/marked-2/id890031187?mt=12&uo=4&at=11l5Vs&ct=mm
675 ## Extensions
677 Besides supporting the basic Markdown syntax, Markdown Mode also
678 includes syntax highlighting for `[[Wiki Links]]`.  This can be
679 enabled by setting `markdown-enable-wiki-links` to a non-nil value.
680 Wiki links may be followed by pressing <kbd>C-c C-o</kbd> when the point
681 is at a wiki link.  Use <kbd>M-p</kbd> and <kbd>M-n</kbd> to quickly jump to the
682 previous and next links (including links of other types).
683 Aliased or piped wiki links of the form `[[link text|PageName]]`
684 are also supported.  Since some wikis reverse these components, set
685 `markdown-wiki-link-alias-first` to nil to treat them as
686 `[[PageName|link text]]`.  If `markdown-wiki-link-fontify-missing`
687 is also non-nil, Markdown Mode will highlight wiki links with
688 missing target file in a different color.  By default, Markdown
689 Mode only searches for target files in the current directory.
690 Search in subdirectories can be enabled by setting
691 `markdown-wiki-link-search-subdirectories` to a non-nil value.
692 Sequential parent directory search (as in [Ikiwiki][]) can be
693 enabled by setting `markdown-wiki-link-search-parent-directories`
694 to a non-nil value.
696 [Ikiwiki]: https://ikiwiki.info
698 [SmartyPants][] support is possible by customizing `markdown-command`.
699 If you install `SmartyPants.pl` at, say, `/usr/local/bin/smartypants`,
700 then you can set `markdown-command` to `"markdown | smartypants"`.
701 You can do this either by using <kbd>M-x customize-group markdown</kbd>
702 or by placing the following in your `.emacs` file:
704 ```lisp
705 (setq markdown-command "markdown | smartypants")
708 [SmartyPants]: http://daringfireball.net/projects/smartypants/
710 Syntax highlighting for mathematical expressions written
711 in LaTeX (only expressions denoted by `$..$`, `$$..$$`, or `\[..\]`)
712 can be enabled by setting `markdown-enable-math` to a non-nil value,
713 either via customize or by placing `(setq markdown-enable-math t)`
714 in `.emacs`, and then restarting Emacs or calling
715 `markdown-reload-extensions`.
717 ## GitHub Flavored Markdown (GFM)
719 A [GitHub Flavored Markdown][GFM] mode, `gfm-mode`, is also
720 available.  The GitHub implementation differs slightly from
721 standard Markdown in that it supports things like different
722 behavior for underscores inside of words, automatic linking of
723 URLs, strikethrough text, and fenced code blocks with an optional
724 language keyword.
726 The GFM-specific features above apply to `README.md` files, wiki
727 pages, and other Markdown-formatted files in repositories on
728 GitHub.  GitHub also enables [additional features][GFM comments] for
729 writing on the site (for issues, pull requests, messages, etc.)
730 that are further extensions of GFM.  These features include task
731 lists (checkboxes), newlines corresponding to hard line breaks,
732 auto-linked references to issues and commits, wiki links, and so
733 on.  To make matters more confusing, although task lists are not
734 part of [GFM proper][GFM], [since 2014][] they are rendered (in a
735 read-only fashion) in all Markdown documents in repositories on the
736 site.  These additional extensions are supported to varying degrees
737 by `markdown-mode` and `gfm-mode` as described below.
739 * **URL autolinking:** Both `markdown-mode` and `gfm-mode` support
740   highlighting of URLs without angle brackets.
742 * **Multiple underscores in words:** You must enable `gfm-mode` to
743   toggle support for underscores inside of words. In this mode
744   variable names such as `a_test_variable` will not trigger
745   emphasis (italics).
747 * **Fenced code blocks:** Code blocks quoted with backquotes, with
748   optional programming language keywords, are highlighted in
749   both `markdown-mode` and `gfm-mode`.  They can be inserted with
750   <kbd>C-c C-s P</kbd>.  If there is an active region, the text in the
751   region will be placed inside the code block.  You will be
752   prompted for the name of the language, but may press enter to
753   continue without naming a language.
755 * **Strikethrough:** Strikethrough text is only supported in
756   `gfm-mode` and can be inserted (and toggled) using <kbd>C-c C-s d</kbd>.
757   Following the mnemonics for the other style keybindings, the
758   letter <kbd>d</kbd> coincides with the HTML tag `<del>`.
760 * **Task lists:** GFM task lists will be rendered as checkboxes
761   (Emacs buttons) in both `markdown-mode` and `gfm-mode` when
762   `markdown-make-gfm-checkboxes-buttons` is set to a non-nil value
763   (and it is set to t by default).  These checkboxes can be
764   toggled by clicking `mouse-1`, pressing <kbd>RET</kbd> over the button,
765   or by pressing <kbd>C-c C-x C-x</kbd> with the point anywhere in the task
766   list item.
768 * **Wiki links:** Generic wiki links are supported in
769   `markdown-mode`, but in `gfm-mode` specifically they will be
770   treated as they are on GitHub: spaces will be replaced by hyphens
771   in filenames and the first letter of the filename will be
772   capitalized.  For example, `[[wiki link]]` will map to a file
773   named `Wiki-link` with the same extension as the current file.
774   If a file with this name does not exist in the current directory,
775   the first match in a subdirectory, if any, will be used instead.
777 * **Newlines:** Neither `markdown-mode` nor `gfm-mode` do anything
778   specifically with respect to newline behavior.  If you use
779   `gfm-mode` mostly to write text for comments or issues on the
780   GitHub site--where newlines are significant and correspond to
781   hard line breaks--then you may want to enable `visual-line-mode`
782   for line wrapping in buffers.  You can do this with a
783   `gfm-mode-hook` as follows:
785     ```lisp
786     ;; Use visual-line-mode in gfm-mode
787     (defun my-gfm-mode-hook ()
788       (visual-line-mode 1))
789     (add-hook 'gfm-mode-hook 'my-gfm-mode-hook)
790     ```
792 * **Preview:** GFM-specific preview can be powered by setting
793   `markdown-command` to use [Docter][].  This may also be
794   configured to work with [Marked 2][] for `markdown-open-command`.
796 [GFM]: http://github.github.com/github-flavored-markdown/
797 [GFM comments]: https://help.github.com/articles/writing-on-github/
798 [since 2014]: https://github.com/blog/1825-task-lists-in-all-markdown-documents
799 [Docter]: https://github.com/alampros/Docter
801 ## Acknowledgments
803 markdown-mode has benefited greatly from the efforts of the many
804 volunteers who have sent patches, test cases, bug reports,
805 suggestions, helped with packaging, etc.  Thank you for your
806 contributions!  See the [contributors graph][contrib] for details.
808  [contrib]: https://github.com/jrblevin/markdown-mode/graphs/contributors
810 ## Bugs
812 markdown-mode is developed and tested primarily for compatibility
813 with GNU Emacs 24.3 and later.  If you find any bugs in
814 markdown-mode, please construct a test case or a patch and open a
815 ticket on the [GitHub issue tracker][issues].
817  [issues]: https://github.com/jrblevin/markdown-mode/issues
819 ## History
821 markdown-mode was written and is maintained by Jason Blevins.  The
822 first version was released on May 24, 2007.
824   * 2007-05-24: [Version 1.1][]
825   * 2007-05-25: [Version 1.2][]
826   * 2007-06-05: [Version 1.3][]
827   * 2007-06-29: [Version 1.4][]
828   * 2007-10-11: [Version 1.5][]
829   * 2008-06-04: [Version 1.6][]
830   * 2009-10-01: [Version 1.7][]
831   * 2011-08-12: [Version 1.8][]
832   * 2011-08-15: [Version 1.8.1][]
833   * 2013-01-25: [Version 1.9][]
834   * 2013-03-24: [Version 2.0][]
835   * 2016-01-09: [Version 2.1][]
836   * 2016-05-26: [Version 2.2][]
838 [Version 1.1]: http://jblevins.org/projects/markdown-mode/rev-1-1
839 [Version 1.2]: http://jblevins.org/projects/markdown-mode/rev-1-2
840 [Version 1.3]: http://jblevins.org/projects/markdown-mode/rev-1-3
841 [Version 1.4]: http://jblevins.org/projects/markdown-mode/rev-1-4
842 [Version 1.5]: http://jblevins.org/projects/markdown-mode/rev-1-5
843 [Version 1.6]: http://jblevins.org/projects/markdown-mode/rev-1-6
844 [Version 1.7]: http://jblevins.org/projects/markdown-mode/rev-1-7
845 [Version 1.8]: http://jblevins.org/projects/markdown-mode/rev-1-8
846 [Version 1.8.1]: http://jblevins.org/projects/markdown-mode/rev-1-8-1
847 [Version 1.9]: http://jblevins.org/projects/markdown-mode/rev-1-9
848 [Version 2.0]: http://jblevins.org/projects/markdown-mode/rev-2-0
849 [Version 2.1]: http://jblevins.org/projects/markdown-mode/rev-2-1
850 [Version 2.2]: http://jblevins.org/projects/markdown-mode/rev-2-2