In addition to Jupyter Notebook Markdown,Jupyter Book also supports a special flavour of Markdown called MyST (orMarkedly Structured Text).It was designed to make it easier to create publishable computational documents written with Markdown notation.It is a superset of CommonMark Markdown and draws heavy inspiration from the fantastic RMarkdown language from RStudio.
Sphinx with Markdown walkthrough for HTML and PDF output This walkthrough installs Sphinx and configures it to output HTML and PDF from.md. If you install it on a VM, allocate over 25GB storage and multiple processors. You'll need Ubuntu 16.04 LTS, an internet connection, and sudo rights.
Sphinx-markdown-parser A docutils -compatibility bridge to MarkdownParser and CommonMark. This allows you to write markdown inside of docutils & sphinx projects. This was built due to limitations of the existing markdown parsers supported by sphinx, specifically recommonmark. As of version 0.2.0, markdown (rather than only reStructuredText) can be included inside directives as nested content. While markdown is much easier to write, please note that it is also less powerful. Sphinx-markdown-parser A docutils -compatibility bridge to MarkdownParser and CommonMark. This allows you to write markdown inside of docutils & sphinx projects. This was built due to limitations of the existing markdown parsers supported by sphinx, specifically recommonmark.
Whether you write your book’s content in Jupyter notebooks (.ipynb
) or in regular Markdown files (.md
),you’ll write in the same flavour of MyST Markdown. Jupyter Book will know how to parse both of them.
This page contains a few pieces of information about MyST Markdown and how it relates to Jupyter Book.You can find much more information about this flavour of Markdown atthe Myst Parser documentation.
Want to use RMarkdown directly?
See Custom notebook formats and Jupytext
Directives and roles¶
Roles and directives are two of the most powerful tools in Jupyter Book.They are kind of like functions, but written in a markup language.They both serve a similar purpose, but roles are written in one line whereas directives span many lines.They both accept different kinds of inputs, and what they do with those inputs depends on the specific role or directive being used.
Directives¶
Directives customize the look, feel, and behaviour of your book.They are kind of like functions, and come in a variety of names with different behaviour.This section covers how to structure and use them.
At its simplest, you can use directives in your book like so:
This will only work if a directive with name mydirectivename
already exists (which it doesn’t).There are many pre-defined directives associated with Jupyter Book.For example, to insert a note box into your content, you can use the following directive:
This results in:
Note
Here is a note
being inserted in your built book.
For more information on using directives, see the MyST documentation.
More arguments and metadata in directives¶
Many directives allow you to control their behaviour with extra pieces ofinformation. In addition to the directive name and the directive content,directives allow two other configuration points:
directive arguments - a list of words that come just after the {directivename}
.
Here’s an example usage of directive arguments:
directive keywords - a collection of flags or key/value pairsthat come just underneath {directivename}
.
There are two ways to write directive keywords, either as :key:val
pairs, oras key:val
pairs enclosed by ---
lines. They both work the same way:
Here’s an example of directive keywords using the :key:val
syntax:
and here’s an example of directive keywords using the enclosing ---
syntax:
Tip
Remember, specifying directive keywords with :key:
or ---
will make no difference.We recommend using ---
if you have many keywords you wish to specify, or if some valueswill span multiple lines. Use the :key:val
syntax as a shorthand for just one or twokeywords.
For examples of how this is used, see the sections below.
Roles¶
Roles are very similar to directives, but they are less complex and writtenentirely in one line. You can use a role in your book withthis syntax:
Again, roles will only work if rolename
is a valid role name.For example, the doc
role can be used to refer to another page in your book.You can refer directly to another page by its relative path.For example, the syntax {doc}`../intro`
will result in: Books with Jupyter.
Warning
It is currently a requirement for roles to be on the same line in your source file. It willnot be parsed correctly if it spans more than one line. Progress towards supporting rolesthat span multiple lines can be tracked by this issue
For more information on using roles, see the MyST documentation.
What roles and directives are available?¶
There is currently no single list of roles / directives to use as a reference, but thissection tries to give as much as information as possible. For those who are familiarwith the Sphinx ecosystem, you may use any directive / role that is available in Sphinx.This is because Jupyter Book uses Sphinx to build your book, and MyST Markdown supportsall syntax that Sphinx supports (think of it as a Markdown version of reStructuredText).
Caution
If you search the internet (and the links below) for information about roles and directives,the documentation will generally be written with reStructuredText in mind. MyST Markdownis different from reStructuredText, but all of the functionality should be the same.See the MyST Sphinx parser documentation for more information about the differences between MyST and rST.
For a list of directives that are available to you, there are three places to check:
The Sphinx directives pagehas a list of directives that are available by default in Sphinx.
The reStructuredText directives pagehas a list of directives in the Python “docutils” module.
This documentation has several additional directives that are specific to Jupyter Book.
What if it exists in rST but not MyST?
In some unusual cases, MyST may be incompatible with a certain role or directive.In this case, you can use the special eval-rst
directive, to directly parse reStructuredText:
which produces
Note
A note written in reStructuredText.
See also
The MyST-Parser documentation on how directives parse content, and its use for including rST files into a Markdown file, and using sphinx.ext.autodoc
in Markdown files.
Nesting content blocks in Markdown¶
If you’d like to nest content blocks inside one another in Markdown (forexample, to put a {note}
inside of a {margin}
), you may do so by addingextra backticks (`
) to the outer-most block. This works for literalcode blocks as well.
For example, the following syntax:
yields
Thus, if you’d like to nest directives inside one another, you can take the sameapproach. For example, the following syntax:
produces:
Other MyST Markdown syntax¶
In addition to roles and directives, there are numerous other kinds of syntaxthat MyST Markdown supports.MyST supports all syntax of CommonMark Markdown (the kind of Markdown that Jupyter notebooks use), as well as an extended syntax that is used for scientific publishing.
The MyST-Parser is the tool that Jupyter Book uses to allow you to write your book content in MyST.It is also a good source of information about the MyST syntax.Here are some links you can use as a reference:
See also
For information about enabling extended MyST syntax, see MyST syntax extensions.In addition, see other examples of this extended syntax (and how to enable each) throughout this documentation.
What can I create with MyST Markdown?¶
See Special content blocks for an introduction to what you can do with MyST Markdownin Jupyter Book.In addition, the other pages in this site cover many more use-cases for how to use directives with MyST.
Tools for writing MyST Markdown¶
There is some support for MyST Markdown in tools across the community. Here we includea few prominent ones.
Jupyter interfaces¶
While MyST Markdown does not (yet) render in traditional Jupyter interfaces, mostof its syntax should “gracefully degrade”, meaning that you can still work withMyST in Jupyter, and then build your book with Jupyter Book.
Jupytext and text sync¶
For working with Jupyter notebook and Markdown files, we recommend jupytext,an open source tool for two-way conversion between .ipynb
and text files.Jupytext supports the MyST Markdown format.
Note
For full compatibility with myst-parser
, it is necessary to use jupytext>=1.6.0
.
See also Convert a Jupytext file into a MyST notebook.
VS Code¶
If editing the Markdown files using VS Code, theVS Code MyST Markdown extensionprovides syntax highlighting and other features.
Latest versionReleased:
A docutils-compatibility bridge to markdown, enabling you to write markdown with support for tables inside of docutils & sphinx projects.
Project description
A docutils
-compatibility bridge to MarkdownParser and CommonMark.
This allows you to write markdown inside of docutils & sphinx projects.
This was built due to limitations of the existing markdown parserssupported by sphinx, specifically recommonmark. Features such as supportfor tables have been added to this extension.
Contents
Recommended Projects
- sphinx-markdown-builder - sphinx builder that outputs markdown files
Parsers
The MarkdownParser
is the recommonend parser for the following reasons.
- It has more features such as tables and extensions
- It is the parser officially supported by this project
If you insist on using the CommonMarkParser
I recommnend using recommonmark directly since we do not officially support that parser.
Parser | Source |
---|---|
MarkdownParser | https://github.com/Python-Markdown/markdown |
CommonMarkParser | https://github.com/readthedocs/recommonmark |
Getting Started
To use sphinx-markdown-parser
inside of Sphinx only takes 2 steps.First you install it:
If using MarkdownParser, you may also want to install some extensions for it:
Then add this to your Sphinx conf.py:
In order to use reStructuredText in Markdown (for enable_eval_rst
to work properly), you must add AutoStructify in conf.py
This allows you to write both .md
and .rst
files inside of the same project.
Links
For all links in commonmark that aren't explicit URLs, they are treated as cross references with the :any:
role. This allows referencing a lot of things including files, labels, and even objects in the loaded domain.
AutoStructify
AutoStructify makes it possible to write your documentation in Markdown, and automatically convert thisinto rST at build time. See the AutoStructify Documentationfor more information about configuration and usage.
To use the advanced markdown to rst transformations you must add AutoStructify
to your Sphinx conf.py.
See https://github.com/rtfd/recommonmark/blob/master/docs/conf.py for a full example.
AutoStructify comes with the following options. See http://recommonmark.readthedocs.org/en/latest/auto_structify.html for more information about the specific features.
- enable_auto_toc_tree: enable the Auto Toc Tree feature.
- auto_toc_tree_section: when True, Auto Toc Tree will only be enabled on section that matches the title.
- enable_auto_doc_ref: enable the Auto Doc Ref feature. Deprecated
- enable_math: enable the Math Formula feature.
- enable_inline_math: enable the Inline Math feature.
- enable_eval_rst: enable the evaluate embedded reStructuredText feature.
- url_resolver: a function that maps a existing relative position in the document to a http link
Development
You can run the tests by running tox
in the top-level of the project.
We are working to expand test coverage,but this will at least test basic Python 2 and 3 compatability.
Why a bridge?
Sphinx Markdown Math
Many python tools (mostly for documentation creation) rely on docutils
.But docutils only supports a ReStructuredText syntax.
For instance this issue and this StackOverflowquestion show that there is an interest in allowing docutils
to use markdown as an alternative syntax.
Why another bridge to docutils?
recommonmark uses the python implementation of CommonMark whileremarkdown implements a stand-alone parser leveraging parsley.
Both output a docutils
document tree and provide scriptsthat leverage docutils
for generation of different types of documents.
Acknowledgement
recommonmark is mainly derived from remarkdown by Steve Genoud andleverages the python CommonMark implementation.
It was originally created by Luca Barbato,and is now maintained in the Read the Docs (rtfd) GitHub organization.
Release historyRelease notifications | RSS feed
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
Sphinx Make Markdown
0.1.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size sphinx_markdown_parser-0.2.4-py2.py3-none-any.whl (19.2 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes |
Filename, size sphinx_markdown_parser-0.2.4.tar.gz (43.2 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for sphinx_markdown_parser-0.2.4-py2.py3-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | c9df4ab10d38d00e142ecb5542764b3470caa7f2339de33398df55b3a22b6a12 |
MD5 | 009b107a248723ddc1fa6644e8124d99 |
BLAKE2-256 | 7a0e63e90ae67eeeb6a5969deeccf0ac0d0c8d3252b9ce2eca7bd0a53aa3a651 |
Hashes for sphinx_markdown_parser-0.2.4.tar.gz
Sphinx Markdown Files
Algorithm | Hash digest |
---|---|
SHA256 | d91ac6f1db28bcc5d9061502f6fc2f6a23cc929d432b728acf4f64cdaa260bb3 |
MD5 | 3acf994f8006f50d22b4e42d75af9227 |
BLAKE2-256 | bbfa83b286f823513a9ca3cfea4e04c8709083a308734bf1f7535a94a7f96df8 |
Comments are closed.