github.com/jbramsden/hugo@v0.47.1/docs/content/en/content-management/formats.md (about)

     1  ---
     2  title: Supported Content Formats
     3  linktitle: Supported Content Formats
     4  description: Markdown and Emacs Org-Mode have native support, and additional formats (e.g. Asciidoc) come via external helpers.
     5  date: 2017-01-10
     6  publishdate: 2017-01-10
     7  lastmod: 2017-04-06
     8  categories: [content management]
     9  keywords: [markdown,asciidoc,mmark,pandoc,content format]
    10  menu:
    11    docs:
    12      parent: "content-management"
    13      weight: 20
    14  weight: 20	#rem
    15  draft: false
    16  aliases: [/content/markdown-extras/,/content/supported-formats/,/doc/supported-formats/,/tutorials/mathjax/]
    17  toc: true
    18  ---
    19  
    20  **Markdown is the main content format** and comes in two flavours:  The excellent [Blackfriday project][blackfriday] (name your files `*.md` or set `markup = "markdown"` in front matter) or its fork [Mmark][mmark] (name your files `*.mmark` or set `markup = "mmark"` in front matter), both very fast markdown engines written in Go.
    21  
    22  For Emacs users, [goorgeous](https://github.com/chaseadamsio/goorgeous) provides built-in native support for Org-mode  (name your files `*.org` or set `markup = "org"` in front matter) 
    23  
    24  {{% note "Deeply Nested Lists" %}}
    25  Before you begin writing your content in markdown, Blackfriday has a known issue [(#329)](https://github.com/russross/blackfriday/issues/329) with handling deeply nested lists. Luckily, there is an easy workaround. Use 4-spaces (i.e., <kbd>tab</kbd>) rather than 2-space indentations.
    26  {{% /note %}}
    27  
    28  ## Configure BlackFriday Markdown Rendering
    29  
    30  You can configure multiple aspects of Blackfriday as show in the following list. See the docs on [Configuration][config] for the full list of explicit directions you can give to Hugo when rendering your site.
    31  
    32  {{< readfile file="/content/en/readfiles/bfconfig.md" markdown="true" >}}
    33  
    34  ## Extend Markdown
    35  
    36  Hugo provides some convenient methods for extending markdown.
    37  
    38  ### Task Lists
    39  
    40  Hugo supports [GitHub-styled task lists (i.e., TODO lists)][gfmtasks] for the Blackfriday markdown renderer. If you do not want to use this feature, you can disable it in your configuration.
    41  
    42  #### Example Task List Input
    43  
    44  {{< code file="content/my-to-do-list.md" >}}
    45  - [ ] a task list item
    46  - [ ] list syntax required
    47  - [ ] incomplete
    48  - [x] completed
    49  {{< /code >}}
    50  
    51  #### Example Task List Output
    52  
    53  The preceding markdown produces the following HTML in your rendered website:
    54  
    55  ```
    56  <ul class="task-list">
    57      <li><input type="checkbox" disabled="" class="task-list-item"> a task list item</li>
    58      <li><input type="checkbox" disabled="" class="task-list-item"> list syntax required</li>
    59      <li><input type="checkbox" disabled="" class="task-list-item"> incomplete</li>
    60      <li><input type="checkbox" checked="" disabled="" class="task-list-item"> completed</li>
    61  </ul>
    62  ```
    63  
    64  #### Example Task List Display
    65  
    66  The following shows how the example task list will look to the end users of your website. Note that visual styling of lists is up to you. This list has been styled according to [the Hugo Docs stylesheet][hugocss].
    67  
    68  - [ ] a task list item
    69  - [ ] list syntax required
    70  - [ ] incomplete
    71  - [x] completed
    72  
    73  ### Emojis
    74  
    75  To add emojis directly to content, set `enableEmoji` to `true` in your [site configuration][config]. To use emojis in templates or shortcodes, see [`emojify` function][].
    76  
    77  For a full list of emojis, see the [Emoji cheat sheet][emojis].
    78  
    79  ### Shortcodes
    80  
    81  If you write in Markdown and find yourself frequently embedding your content with raw HTML, Hugo provides built-in shortcodes functionality. This is one of the most powerful features in Hugo and allows you to create your own Markdown extensions very quickly.
    82  
    83  See [Shortcodes][sc] for usage, particularly for the built-in shortcodes that ship with Hugo, and [Shortcode Templating][sct] to learn how to build your own.
    84  
    85  ### Code Blocks
    86  
    87  Hugo supports GitHub-flavored markdown's use of triple back ticks, as well as provides a special [`highlight` shortcode][hlsc], and syntax highlights those code blocks natively using *Chroma*. Users also have an option to use *Pygments* instead. See the [Syntax Highlighting][hl] section for details.
    88  
    89  ## Mmark
    90  
    91  Mmark is a [fork of BlackFriday][mmark] and markdown superset that is well suited for writing [IETF documentation][ietf]. You can see examples of the syntax in the [Mmark GitHub repository][mmarkgh] or the full syntax on [Miek Gieben's website][].
    92  
    93  ### Use Mmark
    94  
    95  As Hugo ships with Mmark, using the syntax is as easy as changing the extension of your content files from `.md` to `.mmark`.
    96  
    97  In the event that you want to only use Mmark in specific files, you can also define the Mmark syntax in your content's front matter:
    98  
    99  ```
   100  ---
   101  title: My Post
   102  date: 2017-04-01
   103  markup: mmark
   104  ---
   105  ```
   106  
   107  {{% warning %}}
   108  Thare are some features not available in Mmark; one example being that shortcodes are not translated when used in an included `.mmark` file ([#3131](https://github.com/gohugoio/hugo/issues/3137)), and `EXTENSION_ABBREVIATION` ([#1970](https://github.com/gohugoio/hugo/issues/1970)) and the aforementioned GFM todo lists ([#2270](https://github.com/gohugoio/hugo/issues/2270)) are not fully supported. Contributions are welcome.
   109  {{% /warning %}}
   110  
   111  ## MathJax with Hugo
   112  
   113  [MathJax](http://www.mathjax.org/) is a JavaScript library that allows the display of mathematical expressions described via a LaTeX-style syntax in the HTML (or Markdown) source of a web page. As it is a pure a JavaScript library, getting it to work within Hugo is fairly straightforward, but does have some oddities that will be discussed here.
   114  
   115  This is not an introduction into actually using MathJax to render typeset mathematics on your website. Instead, this page is a collection of tips and hints for one way to get MathJax working on a website built with Hugo.
   116  
   117  ### Enable MathJax
   118  
   119  The first step is to enable MathJax on pages that you would like to have typeset math. There are multiple ways to do this (adventurous readers can consult the [Loading and Configuring](http://docs.mathjax.org/en/latest/configuration.html) section of the MathJax documentation for additional methods of including MathJax), but the easiest way is to use the secure MathJax CDN by include a `<script>` tag for the officially recommended secure CDN ([cdn.js.com](https://cdnjs.com)):
   120  
   121  {{< code file="add-mathjax-to-page.html" >}}
   122  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
   123  </script>
   124  {{< /code >}}
   125  
   126  One way to ensure that this code is included in all pages is to put it in one of the templates that live in the `layouts/partials/` directory. For example, I have included this in the bottom of my template `footer.html` because I know that the footer will be included in every page of my website.
   127  
   128  ### Options and Features
   129  
   130  MathJax is a stable open-source library with many features. I encourage the interested reader to view the [MathJax Documentation](http://docs.mathjax.org/en/latest/index.html), specifically the sections on [Basic Usage](http://docs.mathjax.org/en/latest/index.html#basic-usage) and [MathJax Configuration Options](http://docs.mathjax.org/en/latest/index.html#mathjax-configuration-options).
   131  
   132  ### Issues with Markdown
   133  
   134  {{% note %}}
   135  The following issues with Markdown assume you are using `.md` for content and BlackFriday for parsing. Using [Mmark](#mmark) as your content format will obviate the need for the following workarounds.
   136  
   137  When using Mmark with MathJax, use `displayMath: [['$$','$$'], ['\\[','\\]']]`. See the [Mmark `README.md`](https://github.com/miekg/mmark/wiki/Syntax#math-blocks) for more information. In addition to MathJax, Mmark has been shown to work well with [KaTeX](https://github.com/Khan/KaTeX). See this [related blog post from a Hugo user](http://nosubstance.me/post/a-great-toolset-for-static-blogging/).
   138  {{% /note %}}
   139  
   140  After enabling MathJax, any math entered between proper markers (see the [MathJax documentation][mathjaxdocs]) will be processed and typeset in the web page. One issue that comes up, however, with Markdown is that the underscore character (`_`) is interpreted by Markdown as a way to wrap text in `emph` blocks while LaTeX (MathJax) interprets the underscore as a way to create a subscript. This "double speak" of the underscore can result in some unexpected and unwanted behavior.
   141  
   142  ### Solution
   143  
   144  There are multiple ways to remedy this problem. One solution is to simply escape each underscore in your math code by entering `\_` instead of `_`. This can become quite tedious if the equations you are entering are full of subscripts.
   145  
   146  Another option is to tell Markdown to treat the MathJax code as verbatim code and not process it. One way to do this is to wrap the math expression inside a `<div>` `</div>` block. Markdown would ignore these sections and they would get passed directly on to MathJax and processed correctly. This works great for display style mathematics, but for inline math expressions the line break induced by the `<div>` is not acceptable. The syntax for instructing Markdown to treat inline text as verbatim is by wrapping it in backticks (`` ` ``). You might have noticed, however, that the text included in between backticks is rendered differently than standard text (on this site these are items highlighted in red). To get around this problem, we could create a new CSS entry that would apply standard styling to all inline verbatim text that includes MathJax code. Below I will show the HTML and CSS source that would accomplish this (note this solution was adapted from [this blog post](http://doswa.com/2011/07/20/mathjax-in-markdown.html)---all credit goes to the original author).
   147  
   148  {{< code file="mathjax-markdown-solution.html" >}}
   149  <script type="text/x-mathjax-config">
   150  MathJax.Hub.Config({
   151    tex2jax: {
   152      inlineMath: [['$','$'], ['\\(','\\)']],
   153      displayMath: [['$$','$$'], ['\[','\]']],
   154      processEscapes: true,
   155      processEnvironments: true,
   156      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
   157      TeX: { equationNumbers: { autoNumber: "AMS" },
   158           extensions: ["AMSmath.js", "AMSsymbols.js"] }
   159    }
   160  });
   161  </script>
   162  
   163  <script type="text/x-mathjax-config">
   164    MathJax.Hub.Queue(function() {
   165      // Fix <code> tags after MathJax finishes running. This is a
   166      // hack to overcome a shortcoming of Markdown. Discussion at
   167      // https://github.com/mojombo/jekyll/issues/199
   168      var all = MathJax.Hub.getAllJax(), i;
   169      for(i = 0; i < all.length; i += 1) {
   170          all[i].SourceElement().parentNode.className += ' has-jax';
   171      }
   172  });
   173  </script>
   174  {{< /code >}}
   175  
   176  
   177  
   178  As before, this content should be included in the HTML source of each page that will be using MathJax. The next code snippet contains the CSS that is used to have verbatim MathJax blocks render with the same font style as the body of the page.
   179  
   180  {{< code file="mathjax-style.css" >}}
   181  code.has-jax {
   182      font: inherit;
   183      font-size: 100%;
   184      background: inherit;
   185      border: inherit;
   186      color: #515151;
   187  }
   188  {{< /code >}}
   189  
   190  In the CSS snippet, notice the line `color: #515151;`. `#515151` is the value assigned to the `color` attribute of the `body` class in my CSS. In order for the equations to fit in with the body of a web page, this value should be the same as the color of the body.
   191  
   192  ### Usage
   193  
   194  With this setup, everything is in place for a natural usage of MathJax on pages generated using Hugo. In order to include inline mathematics, just put LaTeX code in between `` `$ TeX Code $` `` or `` `\( TeX Code \)` ``. To include display style mathematics, just put LaTeX code in between `<div>$$TeX Code$$</div>`. All the math will be properly typeset and displayed within your Hugo generated web page!
   195  
   196  ## Additional Formats Through External Helpers
   197  
   198  Hugo has a new concept called _external helpers_. It means that you can write your content using [Asciidoc][ascii], [reStructuredText][rest], or [pandoc]. If you have files with associated extensions, Hugo will call external commands to generate the content. ([See the Hugo source code for external helpers][helperssource].)
   199  
   200  For example, for Asciidoc files, Hugo will try to call the `asciidoctor` or `asciidoc` command. This means that you will have to install the associated tool on your machine to be able to use these formats. ([See the Asciidoctor docs for installation instructions](http://asciidoctor.org/docs/install-toolchain/)).
   201  
   202  To use these formats, just use the standard extension and the front matter exactly as you would do with natively supported `.md` files.
   203  
   204  Hugo passes reasonable default arguments to these external helpers by default:
   205  
   206  - `asciidoc`: `--no-header-footer --safe -`
   207  - `asciidoctor`: `--no-header-footer --safe --trace -`
   208  - `rst2html`: `--leave-comments --initial-header-level=2`
   209  - `pandoc`: `--mathjax`
   210  
   211  {{% warning "Performance of External Helpers" %}}
   212  Because additional formats are external commands generation performance will rely heavily on the performance of the external tool you are using. As this feature is still in its infancy, feedback is welcome.
   213  {{% /warning %}}
   214  
   215  ## Learn Markdown
   216  
   217  Markdown syntax is simple enough to learn in a single sitting. The following are excellent resources to get you up and running:
   218  
   219  * [Daring Fireball: Markdown, John Gruber (Creator of Markdown)][fireball]
   220  * [Markdown Cheatsheet, Adam Pritchard][mdcheatsheet]
   221  * [Markdown Tutorial (Interactive), Garen Torikian][mdtutorial]
   222  * [The Markdown Guide, Matt Cone][mdguide]
   223  
   224  [`emojify` function]: /functions/emojify/
   225  [ascii]: http://asciidoctor.org/
   226  [bfconfig]: /getting-started/configuration/#configuring-blackfriday-rendering
   227  [blackfriday]: https://github.com/russross/blackfriday
   228  [mmark]: https://github.com/miekg/mmark
   229  [config]: /getting-started/configuration/
   230  [developer tools]: /tools/
   231  [emojis]: https://www.webpagefx.com/tools/emoji-cheat-sheet/
   232  [fireball]: https://daringfireball.net/projects/markdown/
   233  [gfmtasks]: https://guides.github.com/features/mastering-markdown/#syntax
   234  [helperssource]: https://github.com/gohugoio/hugo/blob/77c60a3440806067109347d04eb5368b65ea0fe8/helpers/general.go#L65
   235  [hl]: /content-management/syntax-highlighting/
   236  [hlsc]: /content-management/shortcodes/#highlight
   237  [hugocss]: /css/style.css
   238  [ietf]: https://tools.ietf.org/html/
   239  [mathjaxdocs]: https://docs.mathjax.org/en/latest/
   240  [mdcheatsheet]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
   241  [mdguide]: https://www.markdownguide.org/
   242  [mdtutorial]: http://www.markdowntutorial.com/
   243  [Miek Gieben's website]: https://miek.nl/2016/March/05/mmark-syntax-document/
   244  [mmark]: https://github.com/miekg/mmark
   245  [mmarkgh]: https://github.com/miekg/mmark/wiki/Syntax
   246  [org]: http://orgmode.org/
   247  [pandoc]: http://www.pandoc.org/
   248  [Pygments]: http://pygments.org/
   249  [rest]: http://docutils.sourceforge.net/rst.html
   250  [sc]: /content-management/shortcodes/
   251  [sct]: /templates/shortcode-templates/