Update CHANGES.md
[markdown-mode.git] / README.md
blob2ba8a3c07bdd167a78ee53cb161cc00509e8ee67
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 _Note:_ To use all of the features of `markdown-mode`, you'll need
51 to install the Emacs package itself and also have a local Markdown
52 processor installed (e.g., Markdown.pl, MultiMarkdown, or Pandoc).
53 The external processor is not required for editing, but will be
54 used for rendering HTML for preview and export. After installing
55 the Emacs package, be sure to configure `markdown-command` to point
56 to the preferred Markdown executable on your system.  See the
57 Customization section below for more details.
59 The recommended way to install `markdown-mode` is to install the package
60 from [MELPA Stable](https://stable.melpa.org/#/markdown-mode)
61 using `package.el`. First, configure `package.el` and the MELPA Stable
62 repository by adding the following to your `.emacs`, `init.el`,
63 or equivalent startup file:
65 ```lisp
66 (require 'package)
67 (add-to-list 'package-archives
68              '("melpa-stable" . "https://stable.melpa.org/packages/"))
69 (package-initialize)
70 ```
72 Then, after restarting Emacs or evaluating the above statements, issue
73 the following command: <kbd>M-x package-install RET markdown-mode RET</kbd>.
74 When installed this way, the major modes `markdown-mode` and `gfm-mode`
75 will be autoloaded and `markdown-mode` will be used for file names
76 ending in either `.md` or `.markdown`.
78 Alternatively, if you manage loading packages with [use-package][]
79 then you can automatically install and configure `markdown-mode` by
80 adding a declaration such as this one to your init file (as an
81 example; adjust settings as desired):
83 ```lisp
84 (use-package markdown-mode
85   :ensure t
86   :commands (markdown-mode gfm-mode)
87   :mode (("README\\.md\\'" . gfm-mode)
88          ("\\.md\\'" . markdown-mode)
89          ("\\.markdown\\'" . markdown-mode))
90   :init (setq markdown-command "multimarkdown"))
91 ```
93 [MELPA Stable]: http://stable.melpa.org/
94 [use-package]: https://github.com/jwiegley/use-package
96 **Direct Download**
98 Alternatively you can manually download and install markdown-mode.
99 First, download the [latest stable version][markdown-mode.el] and
100 save the file where Emacs can find it (i.e., a directory in your
101 `load-path`). You can then configure `markdown-mode` and `gfm-mode`
102 to load automatically by adding the following to your init file:
104 ```lisp
105 (autoload 'markdown-mode "markdown-mode"
106    "Major mode for editing Markdown files" t)
107 (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
108 (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
110 (autoload 'gfm-mode "markdown-mode"
111    "Major mode for editing GitHub Flavored Markdown files" t)
112 (add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode))
115 [markdown-mode.el]: http://jblevins.org/projects/markdown-mode/markdown-mode.el
117 **Development Version**
119 To follow or contribute to markdown-mode development, you can
120 browse or clone the Git repository
121 [on GitHub](https://github.com/jrblevin/markdown-mode):
124 git clone https://github.com/jrblevin/markdown-mode.git
127 If you prefer to install and use the development version, which may
128 become unstable at some times, you can either clone the Git
129 repository as above or install markdown-mode from
130 [MELPA](https://melpa.org/#/markdown-mode).
132 If you clone the repository directly, then make sure that Emacs can
133 find it by adding the following line to your startup file:
135 ```lisp
136 (add-to-list 'load-path "/path/to/markdown-mode/repository")
139 **Packaged Installation**
141 markdown-mode is also available in several package managers. You
142 may want to confirm that the package you install contains the
143 latest stable version first (and please notify the package
144 maintainer if not).
146    * Debian Linux: [elpa-markdown-mode][] and [emacs-goodies-el][]
147    * Ubuntu Linux: [elpa-markdown-mode][elpa-ubuntu] and [emacs-goodies-el][emacs-goodies-el-ubuntu]
148    * RedHat and Fedora Linux: [emacs-goodies][]
149    * NetBSD: [textproc/markdown-mode][]
150    * MacPorts: [markdown-mode.el][macports-package] ([pending][macports-ticket])
151    * FreeBSD: [textproc/markdown-mode.el][freebsd-port]
153  [elpa-markdown-mode]: https://packages.debian.org/sid/lisp/elpa-markdown-mode
154  [elpa-ubuntu]: http://packages.ubuntu.com/search?keywords=elpa-markdown-mode
155  [emacs-goodies-el]: http://packages.debian.org/emacs-goodies-el
156  [emacs-goodies-el-ubuntu]: http://packages.ubuntu.com/search?keywords=emacs-goodies-el
157  [emacs-goodies]: https://apps.fedoraproject.org/packages/emacs-goodies
158  [textproc/markdown-mode]: http://pkgsrc.se/textproc/markdown-mode
159  [macports-package]: https://trac.macports.org/browser/trunk/dports/editors/markdown-mode.el/Portfile
160  [macports-ticket]: http://trac.macports.org/ticket/35716
161  [freebsd-port]: http://svnweb.freebsd.org/ports/head/textproc/markdown-mode.el
163 **Dependencies**
165 To enable editing of code blocks in indirect buffers using <kbd>C-c </kbd>`,
166 you will need to install the [`edit-indirect`][ei] package.
168   [ei]: https://github.com/Fanael/edit-indirect/
170 ## Usage
172 Keybindings are grouped by prefixes based on their function.  For
173 example, the commands for styling text are grouped under <kbd>C-c C-s</kbd>
174 and commands dealing with headings begin with <kbd>C-c C-t</kbd> (mnemonic:
175 titling).  The primary commands in each group will are described
176 below.  You can obtain a list of all keybindings by pressing `C-c
177 C-h`.  Movement and shifting commands tend to be associated with
178 paired delimiters such as <kbd>M-{</kbd> and <kbd>M-}</kbd> or <kbd>C-c <</kbd> and <kbd>C-c ></kbd>.
179 Outline navigation keybindings the same as in `org-mode`.  Finally,
180 commands for running Markdown or doing maintenance on an open file
181 are grouped under the <kbd>C-c C-c</kbd> prefix.  The most commonly used
182 commands are described below.  You can obtain a list of all
183 keybindings by pressing <kbd>C-c C-h</kbd>.
185   * Links and Images: <kbd>C-c C-l</kbd> and <kbd>C-c C-i</kbd>
187     <kbd>C-c C-l</kbd> (`markdown-insert-link`) is a general command for
188     inserting new link markup or editing existing link markup. This
189     is especially useful when markup or URL hiding is enabled, so
190     that URLs can't easily be edited directly.  This command can be
191     used to insert links of any form: either inline links,
192     reference links, or plain URLs in angle brackets.  The URL or
193     `[reference]` label, link text, and optional title are entered
194     through a series of interactive prompts.  The type of link is
195     determined by which values are provided:
197     *   If both a URL and link text are given, insert an inline link:
198         `[text](url)`.
199     *   If both a `[reference]` label and link text are given, insert
200         a reference link: `[text][reference]`.
201     *   If only link text is given, insert an implicit reference link:
202         `[text][]`.
203     *   If only a URL is given, insert a plain URL link:
204         `<url>`.
206     Similarly, <kbd>C-c C-i</kbd> (`markdown-insert-image`) is a general
207     command for inserting or editing image markup.  As with the link
208     insertion command, through a series interactive prompts you can
209     insert either an inline or reference image:
211     *   If both a URL and alt text are given, insert an inline
212         image: `![alt text](url)`.
213     *   If both a `[reference]` label and alt text are given,
214         insert a reference link: `![alt text][reference]`.
216     If there is an existing link or image at the point, these
217     command will edit the existing markup rather than inserting new
218     markup.  Otherwise, if there is an active region, these commands
219     use the region as either the default URL (if it seems to be a
220     URL) or link text value otherwise.  In that case, the region
221     will be deleted and replaced by the link.
223     Note that these functions can be used to convert links and
224     images from one type to another (inline, reference, or plain
225     URL) by selectively adding or removing properties via the
226     interactive prompts.
228     If a reference label is given that is not yet defined, you
229     will be prompted for the URL and optional title and the
230     reference will be inserted according to the value of
231     `markdown-reference-location`.  If a title is given, it will be
232     added to the end of the reference definition and will be used
233     to populate the title attribute when converted to HTML.
235     Local images associated with image links may be displayed
236     inline in the buffer by pressing <kbd>C-c C-x C-i</kbd>
237     (`markdown-toggle-inline-images`). This is a toggle command, so
238     pressing this once again will remove inline images.
240   * Text Styles: <kbd>C-c C-s</kbd>
242     <kbd>C-c C-s i</kbd> inserts markup to make a region or word italic. If
243     there is an active region, make the region italic.  If the point
244     is at a non-italic word, make the word italic.  If the point is
245     at an italic word or phrase, remove the italic markup.
246     Otherwise, simply insert italic delimiters and place the cursor
247     in between them.  Similarly, use <kbd>C-c C-s b</kbd> for bold, <kbd>C-c C-s c</kbd>
248     for inline code, and <kbd>C-c C-s k</kbd> for inserting `<kbd>` tags.
250     <kbd>C-c C-s q</kbd> inserts a blockquote using the active region, if
251     any, or starts a new blockquote. <kbd>C-c C-s Q</kbd> is a variation
252     which always operates on the region, regardless of whether it
253     is active or not (i.e., when `transient-mark-mode` is off but
254     the mark is set).  The appropriate amount of indentation, if
255     any, is calculated automatically given the surrounding context,
256     but may be adjusted later using the region indentation
257     commands.
259     <kbd>C-c C-s p</kbd> behaves similarly for inserting preformatted code
260     blocks (with <kbd>C-c C-s P</kbd> being the region-only counterpart)
261     and <kbd>C-c C-s C</kbd> inserts a GFM style backquote fenced code block.
263   * Headings: <kbd>C-c C-s</kbd>
265     To insert or replace headings, there are two options.  You can
266     insert a specific level heading directly or you can have
267     `markdown-mode` determine the level for you based on the previous
268     heading.  As with the other markup commands, the heading
269     insertion commands use the text in the active region, if any,
270     as the heading text.  Otherwise, if the current line is not
271     blank, they use the text on the current line.  Finally, the
272     setext commands will prompt for heading text if there is no
273     active region and the current line is blank.
275     <kbd>C-c C-s h</kbd> inserts a heading with automatically chosen type and
276     level (both determined by the previous heading).  <kbd>C-c C-s H</kbd>
277     behaves similarly, but uses setext (underlined) headings when
278     possible, still calculating the level automatically.
279     In cases where the automatically-determined level is not what
280     you intended, the level can be quickly promoted or demoted
281     (as described below).  Alternatively, a <kbd>C-u</kbd> prefix can be
282     given to insert a heading _promoted_ (lower number) by one
283     level or a <kbd>C-u C-u</kbd> prefix can be given to insert a heading
284     demoted (higher number) by one level.
286     To insert a heading of a specific level and type, use <kbd>C-c C-s 1</kbd>
287     through <kbd>C-c C-s 6</kbd> for atx (hash mark) headings and <kbd>C-c C-s !</kbd> or
288     <kbd>C-c C-s @</kbd> for setext headings of level one or two, respectively.
289     Note that <kbd>!</kbd> is <kbd>S-1</kbd> and <kbd>@</kbd> is <kbd>S-2</kbd>.
291     If the point is at a heading, these commands will replace the
292     existing markup in order to update the level and/or type of the
293     heading.  To remove the markup of the heading at the point,
294     press <kbd>C-c C-k</kbd> to kill the heading and press <kbd>C-y</kbd> to yank the
295     heading text back into the buffer.
297   * Horizontal Rules: <kbd>C-c C-s -</kbd>
299     <kbd>C-c C-s -</kbd> inserts a horizontal rule.  By default, insert the
300     first string in the list `markdown-hr-strings` (the most
301     prominent rule).  With a <kbd>C-u</kbd> prefix, insert the last string.
302     With a numeric prefix <kbd>N</kbd>, insert the string in position <kbd>N</kbd>
303     (counting from 1).
305   * Footnotes: <kbd>C-c C-s f</kbd>
307     <kbd>C-c C-s f</kbd> inserts a footnote marker at the point, inserts a
308     footnote definition below, and positions the point for
309     inserting the footnote text.  Note that footnotes are an
310     extension to Markdown and are not supported by all processors.
312   * Wiki Links: <kbd>C-c C-s w</kbd>
314     <kbd>C-c C-s w</kbd> inserts a wiki link of the form `[[WikiLink]]`.  If
315     there is an active region, use the region as the link text.  If the
316     point is at a word, use the word as the link text.  If there is
317     no active region and the point is not at word, simply insert
318     link markup.  Note that wiki links are an extension to Markdown
319     and are not supported by all processors.
321   * Markdown and Maintenance Commands: <kbd>C-c C-c</kbd>
323     *Compile:* <kbd>C-c C-c m</kbd> will run Markdown on the current buffer
324     and show the output in another buffer.  *Preview*: <kbd>C-c C-c p</kbd>
325     runs Markdown on the current buffer and previews, stores the
326     output in a temporary file, and displays the file in a browser.
327     *Export:* <kbd>C-c C-c e</kbd> will run Markdown on the current buffer
328     and save the result in the file `basename.html`, where
329     `basename` is the name of the Markdown file with the extension
330     removed.  *Export and View:* press <kbd>C-c C-c v</kbd> to export the
331     file and view it in a browser.  *Open:* <kbd>C-c C-c o</kbd> will open
332     the Markdown source file directly using `markdown-open-command`.
333     *Live Export*: Press <kbd>C-c C-c l</kbd> to turn on
334     `markdown-live-preview-mode` to view the exported output
335     side-by-side with the source Markdown. **For all export commands,
336     the output file will be overwritten without notice.**
337     `markdown-live-preview-window-function` can be customized to open
338     in a browser other than `eww`.  If you want to force the
339     preview window to appear at the bottom or right, you can
340     customize `markdown-split-window-direction`.
342     To summarize:
344       - <kbd>C-c C-c m</kbd>: `markdown-command` > `*markdown-output*` buffer.
345       - <kbd>C-c C-c p</kbd>: `markdown-command` > temporary file > browser.
346       - <kbd>C-c C-c e</kbd>: `markdown-command` > `basename.html`.
347       - <kbd>C-c C-c v</kbd>: `markdown-command` > `basename.html` > browser.
348       - <kbd>C-c C-c w</kbd>: `markdown-command` > kill ring.
349       - <kbd>C-c C-c o</kbd>: `markdown-open-command`.
350       - <kbd>C-c C-c l</kbd>: `markdown-live-preview-mode` > `*eww*` buffer.
352     <kbd>C-c C-c c</kbd> will check for undefined references.  If there are
353     any, a small buffer will open with a list of undefined
354     references and the line numbers on which they appear.  In Emacs
355     22 and greater, selecting a reference from this list and
356     pressing <kbd>RET</kbd> will insert an empty reference definition at the
357     end of the buffer.  Similarly, selecting the line number will
358     jump to the corresponding line.
360     <kbd>C-c C-c n</kbd> renumbers any ordered lists in the buffer that are
361     out of sequence.
363     <kbd>C-c C-c ]</kbd> completes all headings and normalizes all horizontal
364     rules in the buffer.
366   * Following Links: <kbd>C-c C-o</kbd>
368     Press <kbd>C-c C-o</kbd> when the point is on an inline or reference
369     link to open the URL in a browser.  When the point is at a
370     wiki link, open it in another buffer (in the current window,
371     or in the other window with the <kbd>C-u</kbd> prefix).  Use <kbd>M-p</kbd> and
372     <kbd>M-n</kbd> to quickly jump to the previous or next link of any type.
374   * Doing Things: <kbd>C-c C-d</kbd>
376     Use <kbd>C-c C-d</kbd> to do something sensible with the object at the point:
378       - Jumps between reference links and reference definitions.
379         If more than one link uses the same reference label, a
380         window will be shown containing clickable buttons for
381         jumping to each link.  Pressing <kbd>TAB</kbd> or <kbd>S-TAB</kbd> cycles
382         between buttons in this window.
383       - Jumps between footnote markers and footnote text.
384       - Toggles the completion status of GFM task list items
385         (checkboxes).
387   * Promotion and Demotion: <kbd>C-c C--</kbd> and <kbd>C-c C-=</kbd>
389     Headings, horizontal rules, and list items can be promoted and
390     demoted, as well as bold and italic text.  For headings,
391     "promotion" means *decreasing* the level (i.e., moving from
392     `<h2>` to `<h1>`) while "demotion" means *increasing* the
393     level.  For horizontal rules, promotion and demotion means
394     moving backward or forward through the list of rule strings in
395     `markdown-hr-strings`.  For bold and italic text, promotion and
396     demotion means changing the markup from underscores to asterisks.
397     Press <kbd>C-c C--</kbd> or <kbd>C-c <left></kbd> to promote the element at the point
398     if possible.
400     To remember these commands, note that <kbd>-</kbd> is for decreasing the
401     level (promoting), and <kbd>=</kbd> (on the same key as <kbd>+</kbd>) is for
402     increasing the level (demoting).  Similarly, the left and right
403     arrow keys indicate the direction that the atx heading markup
404     is moving in when promoting or demoting.
406   * Completion: <kbd>C-c C-]</kbd>
408     Complete markup is in normalized form, which means, for
409     example, that the underline portion of a setext header is the
410     same length as the heading text, or that the number of leading
411     and trailing hash marks of an atx header are equal and that
412     there is no extra whitespace in the header text.  <kbd>C-c C-]</kbd>
413     completes the markup at the point, if it is determined to be
414     incomplete.
416   * Editing Lists: <kbd>M-RET</kbd>, <kbd>C-c <up></kbd>, <kbd>C-c <down></kbd>, <kbd>C-c <left></kbd>, and <kbd>C-c <right></kbd>
418     New list items can be inserted with <kbd>M-RET</kbd> or <kbd>C-c C-j</kbd>.  This
419     command determines the appropriate marker (one of the possible
420     unordered list markers or the next number in sequence for an
421     ordered list) and indentation level by examining nearby list
422     items.  If there is no list before or after the point, start a
423     new list.  As with heading insertion, you may prefix this
424     command by <kbd>C-u</kbd> to decrease the indentation by one level.
425     Prefix this command by <kbd>C-u C-u</kbd> to increase the indentation by
426     one level.
428     Existing list items (and their nested sub-items) can be moved
429     up or down with <kbd>C-c <up></kbd> or <kbd>C-c <down></kbd> and indented or
430     outdented with <kbd>C-c <right></kbd> or <kbd>C-c <left></kbd>.
432   * Editing Subtrees: <kbd>C-c <up></kbd>, <kbd>C-c <down></kbd>, <kbd>C-c <left></kbd>, and <kbd>C-c <right></kbd>
434     Entire subtrees of ATX headings can be promoted and demoted
435     with <kbd>C-c <left></kbd> and <kbd>C-c <right></kbd>, which are the same keybindings
436     used for promotion and demotion of list items.   If the point is in
437     a list item, the operate on the list item.  Otherwise, they operate
438     on the current heading subtree.  Similarly, subtrees can be
439     moved up and down with <kbd>C-c <up></kbd> and <kbd>C-c <down></kbd>.
441     These commands currently do not work properly if there are
442     Setext headings in the affected region.
444     Please note the following "boundary" behavior for promotion and
445     demotion.  Any level-six headings will not be demoted further
446     (i.e., they remain at level six, since Markdown and HTML define
447     only six levels) and any level-one headings will promoted away
448     entirely (i.e., heading markup will be removed, since a
449     level-zero heading is not defined).
451   * Shifting the Region: <kbd>C-c <</kbd> and <kbd>C-c ></kbd>
453     Text in the region can be indented or outdented as a group using
454     <kbd>C-c ></kbd> to indent to the next indentation point (calculated in
455     the current context), and <kbd>C-c <</kbd> to outdent to the previous
456     indentation point.  These keybindings are the same as those for
457     similar commands in `python-mode`.
459   * Killing Elements: <kbd>C-c C-k</kbd>
461     Press <kbd>C-c C-k</kbd> to kill the thing at point and add important
462     text, without markup, to the kill ring.  Possible things to
463     kill include (roughly in order of precedece): inline code,
464     headings, horizonal rules, links (add link text to kill ring),
465     images (add alt text to kill ring), angle URIs, email
466     addresses, bold, italics, reference definitions (add URI to
467     kill ring), footnote markers and text (kill both marker and
468     text, add text to kill ring), and list items.
470   * 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>
472     These keys are used for hierarchical navigation in lists and
473     headings.  When the point is in a list, they move between list
474     items.  Otherwise, they move between headings.  Use <kbd>C-c C-n</kbd> and
475     <kbd>C-c C-p</kbd> to move between the next and previous visible
476     headings or list items of any level.  Similarly, <kbd>C-c C-f</kbd> and
477     <kbd>C-c C-b</kbd> move to the next and previous visible headings or
478     list items at the same level as the one at the point.  Finally,
479     <kbd>C-c C-u</kbd> will move up to the parent heading or list item.
481   * Movement by Markdown paragraph: <kbd>M-{</kbd>, <kbd>M-}</kbd>, and <kbd>M-h</kbd>
483     Paragraphs in `markdown-mode` are regular paragraphs,
484     paragraphs inside blockquotes, individual list items, headings,
485     etc.  These keys are usually bound to `forward-paragraph` and
486     `backward-paragraph`, but the built-in Emacs functions are
487     based on simple regular expressions that fail in Markdown
488     files.  Instead, they are bound to `markdown-forward-paragraph`
489     and `markdown-backward-paragraph`.  To mark a paragraph,
490     you can use <kbd>M-h</kbd> (`markdown-mark-paragraph`).
492   * Movement by Markdown block: <kbd>C-M-{</kbd>, <kbd>C-M-}</kbd>, and <kbd>C-c M-h</kbd>
494     Markdown blocks are regular paragraphs in many cases, but
495     contain many paragraphs in other cases: blocks are considered
496     to be entire lists, entire code blocks, and entire blockquotes.
497     To move backward one block use <kbd>C-M-{</kbd>
498     (`markdown-beginning-block`) and to move forward use <kbd>C-M-}</kbd>
499     (`markdown-end-of-block`).  To mark a block, use <kbd>C-c M-h</kbd>
500     (`markdown-mark-block`).
502   * Movement by Defuns: <kbd>C-M-a</kbd>, <kbd>C-M-e</kbd>, and <kbd>C-M-h</kbd>
504     The usual Emacs commands can be used to move by defuns
505     (top-level major definitions).  In markdown-mode, a defun is a
506     section.  As usual, <kbd>C-M-a</kbd> will move the point to the
507     beginning of the current or preceding defun, <kbd>C-M-e</kbd> will move
508     to the end of the current or following defun, and <kbd>C-M-h</kbd> will
509     put the region around the entire defun.
511   * Miscellaneous Commands:
513     When the [`edit-indirect`][ei] package is installed, <kbd>C-c </kbd>`
514     (`markdown-edit-code-block`) can be used to edit a code block
515     in an indirect buffer in the native major mode. Press <kbd>C-c C-c</kbd>
516     to commit changes and return or <kbd>C-c C-k</kbd> to cancel.
518 As noted, many of the commands above behave differently depending
519 on whether Transient Mark mode is enabled or not.  When it makes
520 sense, if Transient Mark mode is on and the region is active, the
521 command applies to the text in the region (e.g., <kbd>C-c C-s b</kbd> makes the
522 region bold).  For users who prefer to work outside of Transient
523 Mark mode, since Emacs 22 it can be enabled temporarily by pressing
524 <kbd>C-SPC C-SPC</kbd>.  When this is not the case, many commands then
525 proceed to look work with the word or line at the point.
527 When applicable, commands that specifically act on the region even
528 outside of Transient Mark mode have the same keybinding as their
529 standard counterpart, but the letter is uppercase.  For example,
530 `markdown-insert-blockquote` is bound to <kbd>C-c C-s q</kbd> and only acts on
531 the region in Transient Mark mode while `markdown-blockquote-region`
532 is bound to <kbd>C-c C-s Q</kbd> and always applies to the region (when nonempty).
534 Note that these region-specific functions are useful in many
535 cases where it may not be obvious.  For example, yanking text from
536 the kill ring sets the mark at the beginning of the yanked text
537 and moves the point to the end.  Therefore, the (inactive) region
538 contains the yanked text.  So, <kbd>C-y</kbd> followed by <kbd>C-c C-s Q</kbd> will
539 yank text and turn it into a blockquote.
541 markdown-mode attempts to be flexible in how it handles
542 indentation.  When you press <kbd>TAB</kbd> repeatedly, the point will cycle
543 through several possible indentation levels corresponding to things
544 you might have in mind when you press <kbd>RET</kbd> at the end of a line or
545 <kbd>TAB</kbd>.  For example, you may want to start a new list item,
546 continue a list item with hanging indentation, indent for a nested
547 pre block, and so on.  Outdenting is handled similarly when backspace
548 is pressed at the beginning of the non-whitespace portion of a line.
550 markdown-mode supports outline-minor-mode as well as org-mode-style
551 visibility cycling for atx- or hash-style headings.  There are two
552 types of visibility cycling: Pressing <kbd>S-TAB</kbd> cycles globally between
553 the table of contents view (headings only), outline view (top-level
554 headings only), and the full document view.  Pressing <kbd>TAB</kbd> while the
555 point is at a heading will cycle through levels of visibility for the
556 subtree: completely folded, visible children, and fully visible.
557 Note that mixing hash and underline style headings will give undesired
558 results.
560 ## Customization
562 Although no configuration is *necessary* there are a few things
563 that can be customized.  The <kbd>M-x customize-mode</kbd> command
564 provides an interface to all of the possible customizations:
566   * `markdown-command` - the command used to run Markdown (default:
567     `markdown`).  This variable may be customized to pass
568     command-line options to your Markdown processor of choice.
570   * `markdown-command-needs-filename` - set to `t` if
571     `markdown-command` does not accept standard input (default:
572     `nil`).  When `nil`, `markdown-mode` will pass the Markdown
573     content to `markdown-command` using standard input (`stdin`).
574     When set to `t`, `markdown-mode` will pass the name of the file
575     as the final command-line argument to `markdown-command`.  Note
576     that in the latter case, you will only be able to run
577     `markdown-command` from buffers which are visiting a file.
579   * `markdown-open-command` - the command used for calling a standalone
580     Markdown previewer which is capable of opening Markdown source files
581     directly (default: `nil`).  This command will be called
582     with a single argument, the filename of the current buffer.
583     A representative program is the Mac app [Marked 2][], a
584     live-updating Markdown previewer which can be [called from a
585     simple shell script](http://jblevins.org/log/marked-2-command).
587   * `markdown-hr-strings` - list of strings to use when inserting
588     horizontal rules.  Different strings will not be distinguished
589     when converted to HTML--they will all be converted to
590     `<hr/>`--but they may add visual distinction and style to plain
591     text documents.  To maintain some notion of promotion and
592     demotion, keep these sorted from largest to smallest.
594   * `markdown-bold-underscore` - set to a non-nil value to use two
595     underscores when inserting bold text instead of two asterisks
596     (default: `nil`).
598   * `markdown-italic-underscore` - set to a non-nil value to use
599     underscores when inserting italic text instead of asterisks
600     (default: `nil`).
602   * `markdown-asymmetric-header` - set to a non-nil value to use
603     asymmetric header styling, placing header characters only on
604     the left of headers (default: `nil`).
606   * `markdown-header-scaling` - set to a non-nil value to use
607     a variable-pitch font for headings where the size corresponds
608     to the level of the heading (default: `nil`).
610   * `markdown-header-scaling-values` - list of scaling values,
611     relative to baseline, for headers of levels one through six,
612     used when `markdown-header-scaling` is non-nil
613     (default: `(2.0 1.7 1.4 1.1 1.0 1.0)`).
615   * `markdown-list-indent-width` - depth of indentation for lists
616     when inserting, promoting, and demoting list items (default: 4).
618   * `markdown-indent-function` - the function to use for automatic
619     indentation (default: `markdown-indent-line`).
621   * `markdown-indent-on-enter` - Set to a non-nil value to
622     automatically indent new lines when <kbd>RET</kbd> is pressed.
623     Set to `indent-and-new-item` to additionally continue lists
624     when <kbd>RET</kbd> is pressed (default: `t`).
626   * `markdown-enable-wiki-links` - syntax highlighting for wiki
627     links (default: `nil`).  Set this to a non-nil value to turn on
628     wiki link support by default.  Wiki link support can be toggled
629     later using the function `markdown-toggle-wiki-links`."
631   * `markdown-wiki-link-alias-first` - set to a non-nil value to
632     treat aliased wiki links like `[[link text|PageName]]`
633     (default: `t`).  When set to nil, they will be treated as
634     `[[PageName|link text]]`.
636   * `markdown-uri-types` - a list of protocol schemes (e.g., "http")
637     for URIs that `markdown-mode` should highlight.
639   * `markdown-enable-math` - font lock for inline and display LaTeX
640     math expressions (default: `nil`).  Set this to `t` to turn on
641     math support by default.  Math support can be toggled
642     interactively later using <kbd>C-c C-x C-e</kbd>
643     (`markdown-toggle-math`).
645   * `markdown-css-paths` - CSS files to link to in XHTML output
646     (default: `nil`).
648   * `markdown-content-type` - when set to a nonempty string, an
649     `http-equiv` attribute will be included in the XHTML `<head>`
650     block (default: `""`).  If needed, the suggested values are
651     `application/xhtml+xml` or `text/html`.  See also:
652     `markdown-coding-system`.
654   * `markdown-coding-system` - used for specifying the character
655     set identifier in the `http-equiv` attribute when included
656     (default: `nil`).  See `markdown-content-type`, which must
657     be set before this variable has any effect.  When set to `nil`,
658     `buffer-file-coding-system` will be used to automatically
659     determine the coding system string (falling back to
660     `iso-8859-1` when unavailable).  Common settings are `utf-8`
661     and `iso-latin-1`.
663   * `markdown-xhtml-header-content` - additional content to include
664     in the XHTML `<head>` block (default: `""`).
666   * `markdown-xhtml-standalone-regexp` - a regular expression which
667     `markdown-mode` uses to determine whether the output of
668     `markdown-command` is a standalone XHTML document or an XHTML
669     fragment (default: `"^\\(<\\?xml\\|<!DOCTYPE\\|<html\\)"`).  If
670     this regular expression not matched in the first five lines of
671     output, `markdown-mode` assumes the output is a fragment and
672     adds a header and footer.
674   * `markdown-link-space-sub-char` - a character to replace spaces
675     when mapping wiki links to filenames (default: `"_"`).
676     For example, use an underscore for compatibility with the
677     Python Markdown WikiLinks extension.  In `gfm-mode`, this is
678     set to `"-"` to conform with GitHub wiki links.
680   * `markdown-reference-location` - where to insert reference
681     definitions (default: `header`).  The possible locations are
682     the end of the document (`end`), after the current block
683     (`immediately`), the end of the current subtree (`subtree`),
684     or before the next header (`header`).
686   * `markdown-footnote-location` - where to insert footnote text
687     (default: `end`).  The set of location options is the same as
688     for `markdown-reference-location`.
690   * `markdown-nested-imenu-heading-index` - Use nested imenu
691     heading instead of a flat index (default: `t`).  A nested
692     index may provide more natural browsing from the menu, but a
693     flat list may allow for faster keyboard navigation via tab
694     completion.
696   * `comment-auto-fill-only-comments` - variable is made
697     buffer-local and set to `nil` by default.  In programming
698     language modes, when this variable is non-nil, only comments
699     will be filled by auto-fill-mode.  However, comments in
700     Markdown documents are rare and the most users probably intend
701     for the actual content of the document to be filled.  Making
702     this variable buffer-local allows `markdown-mode` to override
703     the default behavior induced when the global variable is non-nil.
705   * `markdown-gfm-additional-languages`, - additional languages to
706     make available, aside from those predefined in
707     `markdown-gfm-recognized-languages`, when inserting GFM code
708     blocks (default: `nil`). Language strings must have be trimmed
709     of whitespace and not contain any curly braces. They may be of
710     arbitrary capitalization, though.
712   * `markdown-gfm-use-electric-backquote` - use
713     `markdown-electric-backquote` for interactive insertion of GFM
714     code blocks when backquote is pressed three times (default: `t`).
716   * `markdown-make-gfm-checkboxes-buttons` - Whether GitHub
717     Flavored Markdown style task lists (checkboxes) should be
718     turned into buttons that can be toggled with mouse-1 or RET. If
719     non-nil (default), then buttons are enabled.  This works in
720     `markdown-mode` as well as `gfm-mode`.
722   * `markdown-hide-urls` - Determines whether URL and reference
723     labels are hidden for inline and reference links (default: `nil`).
724     When non-nil, inline links will appear in the buffer as
725     `[link](∞)` instead of
726     `[link](http://perhaps.a/very/long/url/)`.  To change the
727     placeholder (composition) character used, set the variable
728     `markdown-url-compose-char`.  URL hiding can be toggled
729     interactively using <kbd>C-c C-x C-l</kbd> (`markdown-toggle-url-hiding`)
730     or from the Markdown | Links & Images menu.
732   * `markdown-hide-markup` - Determines whether all possible markup
733     is hidden or otherwise beautified (default: `nil`).   The actual
734     buffer text remains unchanged, but the display will be altered.
735     Brackets and URLs for links will be hidden, asterisks and
736     underscores for italic and bold text will be hidden, text
737     bullets for unordered lists will be replaced by Unicode
738     bullets, and so on.  Since this includes URLs and reference
739     labels, when non-nil this setting supersedes `markdown-hide-urls`.
740     Markup hiding can be toggled using <kbd>C-c C-x C-m</kbd>
741     (`markdown-toggle-markup-hiding`) or from the Markdown | Show &
742     Hide menu.
744     Unicode bullets are used to replace ASCII list item markers.
745     The list of characters used, in order of list level, can be
746     specified by setting the variable `markdown-list-item-bullets`.
747     The placeholder characters used to replace other markup can
748     be changed by customizing the corresponding variables:
749     `markdown-blockquote-display-char`,
750     `markdown-hr-display-char`, and
751     `markdown-definition-display-char`.
753   * `markdown-fontify-code-blocks-natively` - Whether to fontify
754      code in code blocks using the native major mode.  This only
755      works for fenced code blocks where the language is specified
756      where we can automatically determine the appropriate mode to
757      use.  The language to mode mapping may be customized by setting
758      the variable `markdown-code-lang-modes`.  This can be toggled
759      interactively by pressing <kbd>C-c C-x C-f</kbd>
760      (`markdown-toggle-fontify-code-blocks-natively`).
762   * `markdown-gfm-uppercase-checkbox` - When non-nil, complete GFM
763     task list items with `[X]` instead of `[x]` (default: `nil`).
764     This is useful for compatibility with `org-mode`, which doesn't
765     recognize the lowercase variant.
767 Additionally, the faces used for syntax highlighting can be modified to
768 your liking by issuing <kbd>M-x customize-group RET markdown-faces</kbd>
769 or by using the "Markdown Faces" link at the bottom of the mode
770 customization screen.
772 [Marked 2]: https://itunes.apple.com/us/app/marked-2/id890031187?mt=12&uo=4&at=11l5Vs&ct=mm
774 ## Extensions
776 Besides supporting the basic Markdown syntax, Markdown Mode also
777 includes syntax highlighting for `[[Wiki Links]]`.  This can be
778 enabled by setting `markdown-enable-wiki-links` to a non-nil value.
779 Wiki links may be followed by pressing <kbd>C-c C-o</kbd> when the point
780 is at a wiki link.  Use <kbd>M-p</kbd> and <kbd>M-n</kbd> to quickly jump to the
781 previous and next links (including links of other types).
782 Aliased or piped wiki links of the form `[[link text|PageName]]`
783 are also supported.  Since some wikis reverse these components, set
784 `markdown-wiki-link-alias-first` to nil to treat them as
785 `[[PageName|link text]]`.  If `markdown-wiki-link-fontify-missing`
786 is also non-nil, Markdown Mode will highlight wiki links with
787 missing target file in a different color.  By default, Markdown
788 Mode only searches for target files in the current directory.
789 Search in subdirectories can be enabled by setting
790 `markdown-wiki-link-search-subdirectories` to a non-nil value.
791 Sequential parent directory search (as in [Ikiwiki][]) can be
792 enabled by setting `markdown-wiki-link-search-parent-directories`
793 to a non-nil value.
795 [Ikiwiki]: https://ikiwiki.info
797 [SmartyPants][] support is possible by customizing `markdown-command`.
798 If you install `SmartyPants.pl` at, say, `/usr/local/bin/smartypants`,
799 then you can set `markdown-command` to `"markdown | smartypants"`.
800 You can do this either by using <kbd>M-x customize-group markdown</kbd>
801 or by placing the following in your `.emacs` file:
803 ```lisp
804 (setq markdown-command "markdown | smartypants")
807 [SmartyPants]: http://daringfireball.net/projects/smartypants/
809 Syntax highlighting for mathematical expressions written
810 in LaTeX (only expressions denoted by `$..$`, `$$..$$`, or `\[..\]`)
811 can be enabled by setting `markdown-enable-math` to a non-nil value,
812 either via customize or by placing `(setq markdown-enable-math t)`
813 in `.emacs`, and then restarting Emacs or calling
814 `markdown-reload-extensions`.
816 ## GitHub Flavored Markdown (GFM)
818 A [GitHub Flavored Markdown][GFM] mode, `gfm-mode`, is also
819 available.  The GitHub implementation differs slightly from
820 standard Markdown in that it supports things like different
821 behavior for underscores inside of words, automatic linking of
822 URLs, strikethrough text, and fenced code blocks with an optional
823 language keyword.
825 The GFM-specific features above apply to `README.md` files, wiki
826 pages, and other Markdown-formatted files in repositories on
827 GitHub.  GitHub also enables [additional features][GFM comments] for
828 writing on the site (for issues, pull requests, messages, etc.)
829 that are further extensions of GFM.  These features include task
830 lists (checkboxes), newlines corresponding to hard line breaks,
831 auto-linked references to issues and commits, wiki links, and so
832 on.  To make matters more confusing, although task lists are not
833 part of [GFM proper][GFM], [since 2014][] they are rendered (in a
834 read-only fashion) in all Markdown documents in repositories on the
835 site.  These additional extensions are supported to varying degrees
836 by `markdown-mode` and `gfm-mode` as described below.
838 * **URL autolinking:** Both `markdown-mode` and `gfm-mode` support
839   highlighting of URLs without angle brackets.
841 * **Multiple underscores in words:** You must enable `gfm-mode` to
842   toggle support for underscores inside of words. In this mode
843   variable names such as `a_test_variable` will not trigger
844   emphasis (italics).
846 * **Fenced code blocks:** Code blocks quoted with backquotes, with
847   optional programming language keywords, are highlighted in
848   both `markdown-mode` and `gfm-mode`.  They can be inserted with
849   <kbd>C-c C-s C</kbd>.  If there is an active region, the text in the
850   region will be placed inside the code block.  You will be
851   prompted for the name of the language, but may press enter to
852   continue without naming a language.
854 * **Strikethrough:** Strikethrough text is supported in both
855   `markdown-mode` and `gfm-mode`.  It can be inserted (and toggled)
856   using <kbd>C-c C-s s</kbd>.
858 * **Task lists:** GFM task lists will be rendered as checkboxes
859   (Emacs buttons) in both `markdown-mode` and `gfm-mode` when
860   `markdown-make-gfm-checkboxes-buttons` is set to a non-nil value
861   (and it is set to t by default).  These checkboxes can be
862   toggled by clicking `mouse-1`, pressing <kbd>RET</kbd> over the button,
863   or by pressing <kbd>C-c C-d</kbd> (`markdown-do`) with the point anywhere
864   in the task list item.
866 * **Wiki links:** Generic wiki links are supported in
867   `markdown-mode`, but in `gfm-mode` specifically they will be
868   treated as they are on GitHub: spaces will be replaced by hyphens
869   in filenames and the first letter of the filename will be
870   capitalized.  For example, `[[wiki link]]` will map to a file
871   named `Wiki-link` with the same extension as the current file.
872   If a file with this name does not exist in the current directory,
873   the first match in a subdirectory, if any, will be used instead.
875 * **Newlines:** Neither `markdown-mode` nor `gfm-mode` do anything
876   specifically with respect to newline behavior.  If you use
877   `gfm-mode` mostly to write text for comments or issues on the
878   GitHub site--where newlines are significant and correspond to
879   hard line breaks--then you may want to enable `visual-line-mode`
880   for line wrapping in buffers.  You can do this with a
881   `gfm-mode-hook` as follows:
883     ```lisp
884     ;; Use visual-line-mode in gfm-mode
885     (defun my-gfm-mode-hook ()
886       (visual-line-mode 1))
887     (add-hook 'gfm-mode-hook 'my-gfm-mode-hook)
888     ```
890 * **Preview:** GFM-specific preview can be powered by setting
891   `markdown-command` to use [Docter][].  This may also be
892   configured to work with [Marked 2][] for `markdown-open-command`.
894 [GFM]: http://github.github.com/github-flavored-markdown/
895 [GFM comments]: https://help.github.com/articles/writing-on-github/
896 [since 2014]: https://github.com/blog/1825-task-lists-in-all-markdown-documents
897 [Docter]: https://github.com/alampros/Docter
899 ## Acknowledgments
901 markdown-mode has benefited greatly from the efforts of the many
902 volunteers who have sent patches, test cases, bug reports,
903 suggestions, helped with packaging, etc.  Thank you for your
904 contributions!  See the [contributors graph][contrib] for details.
906  [contrib]: https://github.com/jrblevin/markdown-mode/graphs/contributors
908 ## Bugs
910 markdown-mode is developed and tested primarily for compatibility
911 with GNU Emacs 24.3 and later.  If you find any bugs in
912 markdown-mode, please construct a test case or a patch and open a
913 ticket on the [GitHub issue tracker][issues].
915  [issues]: https://github.com/jrblevin/markdown-mode/issues
917 ## History
919 markdown-mode was written and is maintained by Jason Blevins.  The
920 first version was released on May 24, 2007.
922   * 2007-05-24: [Version 1.1][]
923   * 2007-05-25: [Version 1.2][]
924   * 2007-06-05: [Version 1.3][]
925   * 2007-06-29: [Version 1.4][]
926   * 2007-10-11: [Version 1.5][]
927   * 2008-06-04: [Version 1.6][]
928   * 2009-10-01: [Version 1.7][]
929   * 2011-08-12: [Version 1.8][]
930   * 2011-08-15: [Version 1.8.1][]
931   * 2013-01-25: [Version 1.9][]
932   * 2013-03-24: [Version 2.0][]
933   * 2016-01-09: [Version 2.1][]
934   * 2017-05-26: [Version 2.2][]
936 [Version 1.1]: http://jblevins.org/projects/markdown-mode/rev-1-1
937 [Version 1.2]: http://jblevins.org/projects/markdown-mode/rev-1-2
938 [Version 1.3]: http://jblevins.org/projects/markdown-mode/rev-1-3
939 [Version 1.4]: http://jblevins.org/projects/markdown-mode/rev-1-4
940 [Version 1.5]: http://jblevins.org/projects/markdown-mode/rev-1-5
941 [Version 1.6]: http://jblevins.org/projects/markdown-mode/rev-1-6
942 [Version 1.7]: http://jblevins.org/projects/markdown-mode/rev-1-7
943 [Version 1.8]: http://jblevins.org/projects/markdown-mode/rev-1-8
944 [Version 1.8.1]: http://jblevins.org/projects/markdown-mode/rev-1-8-1
945 [Version 1.9]: http://jblevins.org/projects/markdown-mode/rev-1-9
946 [Version 2.0]: http://jblevins.org/projects/markdown-mode/rev-2-0
947 [Version 2.1]: http://jblevins.org/projects/markdown-mode/rev-2-1
948 [Version 2.2]: http://jblevins.org/projects/markdown-mode/rev-2-2