diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 00000000..786be571
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,19 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for all configuration options:
+# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+
+version: 2
+updates:
+ - package-ecosystem: github-actions
+ directory: /
+ commit-message:
+ prefix: ⬆️
+ schedule:
+ interval: weekly
+ - package-ecosystem: pip
+ directory: /
+ commit-message:
+ prefix: ⬆️
+ schedule:
+ interval: weekly
diff --git a/.github/workflows/test-formats.yml b/.github/workflows/test-formats.yml
new file mode 100644
index 00000000..6b0bf594
--- /dev/null
+++ b/.github/workflows/test-formats.yml
@@ -0,0 +1,76 @@
+name: build-doc-formats
+
+on:
+ push:
+ branches: [master]
+ pull_request:
+
+jobs:
+
+ doc-builds:
+
+ name: Documentation builds
+ runs-on: ubuntu-latest
+
+ strategy:
+ fail-fast: false
+ matrix:
+ format: ["man", "text"]
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Python 3.9
+ uses: actions/setup-python@v4
+ with:
+ python-version: 3.9
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install -e .[linkify,rtd]
+ - name: Build docs
+ run: |
+ sphinx-build -nW --keep-going -b ${{ matrix.format }} docs/ docs/_build/${{ matrix.format }}
+
+ doc-builds-pdf:
+
+ name: Documentation builds
+ runs-on: ubuntu-latest
+
+ strategy:
+ fail-fast: false
+ matrix:
+ format: ["latex"]
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Python 3.9
+ uses: actions/setup-python@v4
+ with:
+ python-version: 3.9
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install -e .[linkify,rtd]
+ - name: Build docs
+ run: |
+ sphinx-build -nW --keep-going -b ${{ matrix.format }} docs/ docs/_build/${{ matrix.format }}
+
+ - name: Make PDF
+ uses: xu-cheng/latex-action@v2
+ with:
+ working_directory: docs/_build/latex
+ root_file: "mystparser.tex"
+ # https://github.com/marketplace/actions/github-action-for-latex#it-fails-due-to-xindy-cannot-be-found
+ pre_compile: |
+ ln -sf /opt/texlive/texdir/texmf-dist/scripts/xindy/xindy.pl /opt/texlive/texdir/bin/x86_64-linuxmusl/xindy
+ ln -sf /opt/texlive/texdir/texmf-dist/scripts/xindy/texindy.pl /opt/texlive/texdir/bin/x86_64-linuxmusl/texindy
+ wget https://sourceforge.net/projects/xindy/files/xindy-source-components/2.4/xindy-kernel-3.0.tar.gz
+ tar xf xindy-kernel-3.0.tar.gz
+ cd xindy-kernel-3.0/src
+ apk add make
+ apk add clisp --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
+ make
+ cp -f xindy.mem /opt/texlive/texdir/bin/x86_64-linuxmusl/
+ cd ../../
+ env:
+ XINDYOPTS: -L english -C utf8 -M sphinx.xdy
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index c05356e6..2429041f 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -13,49 +13,48 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
- name: Set up Python 3.8
- uses: actions/setup-python@v1
+ uses: actions/setup-python@v4
with:
python-version: "3.8"
- - uses: pre-commit/action@v2.0.0
+ - uses: pre-commit/action@v3.0.0
tests:
strategy:
fail-fast: false
matrix:
- python-version: ["3.7", "3.8", "3.9", "3.10"]
- sphinx: [">=5,<6"]
+ python-version: ["3.8", "3.9", "3.10", "3.11"]
+ sphinx: [">=6,<7"]
os: [ubuntu-latest]
include:
- os: ubuntu-latest
python-version: "3.8"
- sphinx: ">=4,<5"
+ sphinx: ">=5,<6"
- os: windows-latest
python-version: "3.8"
- sphinx: ">=4,<5"
+ sphinx: ">=5,<6"
runs-on: ${{ matrix.os }}
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v1
+ uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- pip install -e .[linkify,testing]
- pip install --upgrade-strategy "only-if-needed" "sphinx${{ matrix.sphinx }}"
+ pip install -e ".[linkify,testing]" "sphinx${{ matrix.sphinx }}"
- name: Run pytest
run: |
pytest --cov=myst_parser --cov-report=xml --cov-report=term-missing
coverage xml
- name: Upload to Codecov
- if: github.repository == 'executablebooks/MyST-Parser' && matrix.python-version == 3.8
- uses: codecov/codecov-action@v1
+ if: github.repository == 'executablebooks/MyST-Parser' && matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
+ uses: codecov/codecov-action@v3
with:
name: myst-parser-pytests
flags: pytests
@@ -74,9 +73,9 @@ jobs:
steps:
- name: Checkout source
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Set up Python 3.8
- uses: actions/setup-python@v1
+ uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install setup
@@ -87,8 +86,7 @@ jobs:
run: python .github/workflows/docutils_setup.py pyproject.toml README.md
- name: Install dependencies
run: |
- pip install .
- pip install pytest~=6.2 pytest-param-files~=0.3.3 pygments docutils==${{ matrix.docutils-version }}
+ pip install .[linkify,testing-docutils] docutils==${{ matrix.docutils-version }}
- name: ensure sphinx is not installed
run: |
python -c "\
@@ -99,7 +97,7 @@ jobs:
else:
raise AssertionError()"
- name: Run pytest for docutils-only tests
- run: pytest tests/test_docutils.py tests/test_renderers/test_fixtures_docutils.py tests/test_renderers/test_include_directive.py
+ run: pytest tests/test_docutils.py tests/test_renderers/test_fixtures_docutils.py tests/test_renderers/test_include_directive.py tests/test_renderers/test_myst_config.py
- name: Run docutils CLI
run: echo "test" | myst-docutils-html
@@ -111,9 +109,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Set up Python 3.8
- uses: actions/setup-python@v1
+ uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: install flit
@@ -134,9 +132,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Set up Python 3.8
- uses: actions/setup-python@v1
+ uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: install flit and tomlkit
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0fe72f45..70bd6e94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -363,7 +363,7 @@ In particular for users, this update alters the parsing of tables to be consiste
### New Features ✨
-- **Task lists** utilise the [markdown-it-py tasklists plugin](markdown_it:md/plugins), and are applied to Markdown list items starting with `[ ]` or `[x]`.
+- **Task lists** utilise the [markdown-it-py tasklists plugin](inv:markdown_it#md/plugins), and are applied to Markdown list items starting with `[ ]` or `[x]`.
```markdown
- [ ] An item that needs doing
@@ -437,7 +437,7 @@ A warning (of type `myst.nested_header`) is now emitted when this occurs.
- ✨ NEW: Add warning types `myst.subtype`:
All parsing warnings are assigned a type/subtype, and also the messages are appended with them.
These warning types can be suppressed with the sphinx `suppress_warnings` config option.
- See [How-to suppress warnings](howto/warnings) for more information.
+ See [How-to suppress warnings](myst-warnings) for more information.
## 0.13.3 - 2021-01-20
@@ -541,7 +541,7 @@ substitutions:
{{ key1 }}
```
-The substitutions are assessed as [jinja2 expressions](http://jinja.palletsprojects.com/) and includes the [Sphinx Environment](https://www.sphinx-doc.org/en/master/extdev/envapi.html) as `env`, so you can do powerful thinks like:
+The substitutions are assessed as [jinja2 expressions](http://jinja.palletsprojects.com/) and includes the [Sphinx Environment](inv:sphinx#extdev/envapi) as `env`, so you can do powerful thinks like:
```
{{ [key1, env.docname] | join('/') }}
diff --git a/docs/_static/custom.css b/docs/_static/local.css
similarity index 54%
rename from docs/_static/custom.css
rename to docs/_static/local.css
index f126fba7..2851864d 100644
--- a/docs/_static/custom.css
+++ b/docs/_static/local.css
@@ -22,3 +22,31 @@ h3::before {
.admonition > .admonition-title, div.admonition.no-icon > .admonition-title {
padding-left: .6rem;
}
+
+/* Live preview page */
+iframe.pyscript, textarea.pyscript {
+ width: 100%;
+ height: 400px;
+}
+iframe.pyscript {
+ padding: 4px;
+}
+textarea.pyscript {
+ padding: 30px 20px 20px;
+ border-radius: 8px;
+ resize: vertical;
+ font-size: 16px;
+ font-family: monospace;
+}
+.display-flex {
+ display: flex;
+}
+.display-inline-block {
+ display: inline-block;
+ margin-right: 1rem;
+ margin-bottom: 0;
+}
+span.label {
+ /* pyscript changes this and it messes up footnote labels */
+ all: unset;
+}
diff --git a/docs/conf.py b/docs/conf.py
index 199a32a4..69b4dae9 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -7,6 +7,7 @@
from datetime import date
from sphinx.application import Sphinx
+from sphinx.transforms.post_transforms import SphinxPostTransform
from myst_parser import __version__
@@ -34,6 +35,7 @@
"sphinxext.rediraffe",
"sphinxcontrib.mermaid",
"sphinxext.opengraph",
+ "sphinx_pyscript",
]
# Add any paths that contain templates here, relative to this directory.
@@ -44,12 +46,67 @@
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
+suppress_warnings = ["myst.strikethrough"]
-# -- Options for HTML output -------------------------------------------------
+intersphinx_mapping = {
+ "python": ("https://docs.python.org/3.7", None),
+ "sphinx": ("https://www.sphinx-doc.org/en/master", None),
+ "markdown_it": ("https://markdown-it-py.readthedocs.io/en/latest", None),
+}
+
+# -- Autodoc settings ---------------------------------------------------
+
+autodoc_member_order = "bysource"
+nitpicky = True
+nitpick_ignore = [
+ ("py:class", "docutils.nodes.document"),
+ ("py:class", "docutils.nodes.docinfo"),
+ ("py:class", "docutils.nodes.Element"),
+ ("py:class", "docutils.nodes.Node"),
+ ("py:class", "docutils.nodes.field_list"),
+ ("py:class", "docutils.nodes.problematic"),
+ ("py:class", "docutils.nodes.pending"),
+ ("py:class", "docutils.nodes.system_message"),
+ ("py:class", "docutils.statemachine.StringList"),
+ ("py:class", "docutils.parsers.rst.directives.misc.Include"),
+ ("py:class", "docutils.parsers.rst.Parser"),
+ ("py:class", "docutils.utils.Reporter"),
+ ("py:class", "nodes.Element"),
+ ("py:class", "nodes.Node"),
+ ("py:class", "nodes.system_message"),
+ ("py:class", "Directive"),
+ ("py:class", "Include"),
+ ("py:class", "StringList"),
+ ("py:class", "DocutilsRenderer"),
+ ("py:class", "MockStateMachine"),
+]
+
+# -- MyST settings ---------------------------------------------------
+
+myst_enable_extensions = [
+ "dollarmath",
+ "amsmath",
+ "deflist",
+ "fieldlist",
+ "html_admonition",
+ "html_image",
+ "colon_fence",
+ "smartquotes",
+ "replacements",
+ "linkify",
+ "strikethrough",
+ "substitution",
+ "tasklist",
+ "attrs_inline",
+ "inv_link",
+]
+myst_number_code_blocks = ["typescript"]
+myst_heading_anchors = 2
+myst_footnote_transition = True
+myst_dmath_double_inline = True
+
+# -- HTML output -------------------------------------------------
-# The theme to use for HTML and HTML Help pages. See the documentation for
-# a list of builtin themes.
-#
html_theme = "sphinx_book_theme"
html_logo = "_static/logo-wide.svg"
html_favicon = "_static/logo-square.svg"
@@ -76,27 +133,6 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
-myst_enable_extensions = [
- "dollarmath",
- "amsmath",
- "deflist",
- "fieldlist",
- "html_admonition",
- "html_image",
- "colon_fence",
- "smartquotes",
- "replacements",
- "linkify",
- "strikethrough",
- "substitution",
- "tasklist",
- "attrs_image",
-]
-myst_number_code_blocks = ["typescript"]
-myst_heading_anchors = 2
-myst_footnote_transition = True
-myst_dmath_double_inline = True
-
rediraffe_redirects = {
"using/intro.md": "sphinx/intro.md",
"sphinx/intro.md": "intro.md",
@@ -112,47 +148,28 @@
"explain/index.md": "develop/background.md",
}
-suppress_warnings = ["myst.strikethrough"]
+# -- LaTeX output -------------------------------------------------
+latex_engine = "xelatex"
-intersphinx_mapping = {
- "python": ("https://docs.python.org/3.7", None),
- "sphinx": ("https://www.sphinx-doc.org/en/master", None),
- "markdown_it": ("https://markdown-it-py.readthedocs.io/en/latest", None),
-}
+# -- Local Sphinx extensions -------------------------------------------------
-# autodoc_default_options = {
-# "show-inheritance": True,
-# "special-members": "__init__, __enter__, __exit__",
-# "members": True,
-# # 'exclude-members': '',
-# "undoc-members": True,
-# # 'inherited-members': True
-# }
-autodoc_member_order = "bysource"
-nitpicky = True
-nitpick_ignore = [
- ("py:class", "docutils.nodes.document"),
- ("py:class", "docutils.nodes.docinfo"),
- ("py:class", "docutils.nodes.Element"),
- ("py:class", "docutils.nodes.Node"),
- ("py:class", "docutils.nodes.field_list"),
- ("py:class", "docutils.nodes.problematic"),
- ("py:class", "docutils.nodes.pending"),
- ("py:class", "docutils.nodes.system_message"),
- ("py:class", "docutils.statemachine.StringList"),
- ("py:class", "docutils.parsers.rst.directives.misc.Include"),
- ("py:class", "docutils.parsers.rst.Parser"),
- ("py:class", "docutils.utils.Reporter"),
- ("py:class", "nodes.Element"),
- ("py:class", "nodes.Node"),
- ("py:class", "nodes.system_message"),
- ("py:class", "Directive"),
- ("py:class", "Include"),
- ("py:class", "StringList"),
- ("py:class", "DocutilsRenderer"),
- ("py:class", "MockStateMachine"),
-]
+
+class StripUnsupportedLatex(SphinxPostTransform):
+ """Remove unsupported nodes from the doctree."""
+
+ default_priority = 900
+
+ def run(self):
+ if not self.app.builder.format == "latex":
+ return
+ from docutils import nodes
+
+ for node in self.document.findall():
+ if node.tagname == "image" and node["uri"].endswith(".svg"):
+ node.parent.replace(node, nodes.inline("", "Removed SVG image"))
+ if node.tagname == "mermaid":
+ node.parent.replace(node, nodes.inline("", "Removed Mermaid diagram"))
def setup(app: Sphinx):
@@ -161,9 +178,12 @@ def setup(app: Sphinx):
DirectiveDoc,
DocutilsCliHelpDirective,
MystConfigDirective,
+ MystWarningsDirective,
)
- app.add_css_file("custom.css")
+ app.add_css_file("local.css")
app.add_directive("myst-config", MystConfigDirective)
app.add_directive("docutils-cli-help", DocutilsCliHelpDirective)
app.add_directive("doc-directive", DirectiveDoc)
+ app.add_directive("myst-warnings", MystWarningsDirective)
+ app.add_post_transform(StripUnsupportedLatex)
diff --git a/docs/configuration.md b/docs/configuration.md
index a87ce0bd..8125d9a5 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -69,6 +69,9 @@ Full details in the [](syntax/extensions) section.
amsmath
: enable direct parsing of [amsmath](https://ctan.org/pkg/amsmath) LaTeX equations
+attrs_inline
+: Enable inline attribute parsing, [see here](syntax/attributes) for details
+
colon_fence
: Enable code fences using `:::` delimiters, [see here](syntax/colon_fence) for details
@@ -87,6 +90,9 @@ html_admonition
html_image
: Convert HTML `` elements to sphinx image nodes, [see here](syntax/images) for details
+inv_link
+: Enable the `inv:` schema for Markdown link destinations, [see here](syntax/inv_links) for details
+
linkify
: Automatically identify "bare" web URLs and add hyperlinks
@@ -104,3 +110,26 @@ substitution
tasklist
: Add check-boxes to the start of list items, [see here](syntax/tasklists) for details
+
+(howto/warnings)=
+(myst-warnings)=
+## Build Warnings
+
+Below lists the MyST specific warnings that may be emitted during the build process. These will be prepended to the end of the warning message, e.g.
+
+```
+WARNING: Non-consecutive header level increase; H1 to H3 [myst.header]
+```
+
+**In general, if your build logs any warnings, you should either fix them or [raise an Issue](https://github.com/executablebooks/MyST-Parser/issues/new/choose) if you think the warning is erroneous.**
+
+However, in some circumstances if you wish to suppress the warning you can use the configuration option, e.g.
+
+```python
+suppress_warnings = ["myst.header"]
+```
+
+Or use `--myst-suppress-warnings="myst.header"` for the [docutils CLI](myst-docutils).
+
+```{myst-warnings}
+```
diff --git a/docs/docutils.md b/docs/docutils.md
index b4d04800..9ec4aa15 100644
--- a/docs/docutils.md
+++ b/docs/docutils.md
@@ -35,6 +35,10 @@ The commands are based on the [Docutils Front-End Tools](https://docutils.source
```
:::
+:::{versionadded} 0.19.0
+`myst-suppress-warnings` replicates the functionality of sphinx's for `myst.` warnings in the `docutils` CLI.
+:::
+
The CLI commands can also utilise the [`docutils.conf` configuration file](https://docutils.sourceforge.io/docs/user/config.html) to configure the behaviour of the CLI commands. For example:
```
@@ -42,6 +46,9 @@ The CLI commands can also utilise the [`docutils.conf` configuration file](https
[general]
myst-enable-extensions: deflist,linkify
myst-footnote-transition: no
+myst-substitutions:
+ key1: value1
+ key2: value2
# These entries affect specific HTML output:
[html writers]
diff --git a/docs/faq/index.md b/docs/faq/index.md
index e4d45815..902dde6b 100644
--- a/docs/faq/index.md
+++ b/docs/faq/index.md
@@ -102,7 +102,7 @@ If you encounter any issues with this feature, please don't hesitate to report i
(howto/autodoc)=
### Use `sphinx.ext.autodoc` in Markdown files
-The [Sphinx extension `autodoc`](sphinx:sphinx.ext.autodoc), which pulls in code documentation from docstrings, is currently hard-coded to parse reStructuredText.
+The [Sphinx extension `autodoc`](inv:sphinx#sphinx.ext.autodoc), which pulls in code documentation from docstrings, is currently hard-coded to parse reStructuredText.
It is therefore incompatible with MyST's Markdown parser.
However, the special [`eval-rst` directive](syntax/directives/parsing) can be used to "wrap" `autodoc` directives:
@@ -142,7 +142,7 @@ See the [](syntax/header-anchors) section of extended syntaxes.
:::
If you'd like to *automatically* generate targets for each of your section headers,
-check out the [`autosectionlabel`](https://www.sphinx-doc.org/en/master/usage/extensions/autosectionlabel.html)
+check out the [autosectionlabel](inv:sphinx#usage/*/autosectionlabel)
sphinx feature. You can activate it in your Sphinx site by adding the following to your
`conf.py` file:
@@ -172,33 +172,14 @@ like so:
{ref}`path/to/file_1:My Subtitle`
```
-(howto/warnings)=
### Suppress warnings
-In general, if your build logs any warnings, you should either fix them or [raise an Issue](https://github.com/executablebooks/MyST-Parser/issues/new/choose) if you think the warning is erroneous.
-However, in some circumstances if you wish to suppress the warning you can use the [`suppress_warnings`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-suppress_warnings) configuration option.
-All myst-parser warnings are prepended by their type, e.g. to suppress:
-
-```md
-# Title
-### Subtitle
-```
-
-```
-WARNING: Non-consecutive header level increase; H1 to H3 [myst.header]
-```
-
-Add to your `conf.py`:
-
-```python
-suppress_warnings = ["myst.header"]
-```
-
+Moved to [](myst-warnings)
### Sphinx-specific page front matter
Sphinx intercepts front matter and stores them within the global environment
-(as discussed [in the deflists documentation](https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html)).
+(as discussed in the [sphinx documentation](inv:sphinx#usage/*/field-lists)).
There are certain front-matter keys (or their translations) that are also recognised specifically by docutils and parsed to inline Markdown:
- `author`
@@ -247,7 +228,7 @@ emphasis syntax will now be disabled. For example, the following will be rendere
*emphasis is now disabled*
```
-For a list of all the syntax elements you can disable, see the [markdown-it parser guide](markdown_it:using).
+For a list of all the syntax elements you can disable, see the [markdown-it parser guide](inv:markdown_it#using).
## Common errors and questions
diff --git a/docs/index.md b/docs/index.md
index 36c0cd05..642b352d 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -30,14 +30,24 @@ sd_hide_title: true
A Sphinx and Docutils extension to parse MyST,
a rich and extensible flavour of Markdown for authoring technical and scientific documentation.
+````{div} sd-d-flex-row
```{button-ref} intro
:ref-type: doc
:color: primary
-:class: sd-rounded-pill
+:class: sd-rounded-pill sd-mr-3
Get Started
```
+```{button-ref} live-preview
+:ref-type: doc
+:color: secondary
+:class: sd-rounded-pill
+
+Live Demo
+```
+````
+
:::
::::
@@ -115,6 +125,7 @@ The MyST markdown language and MyST parser are both supported by the open commun
```{toctree}
:hidden:
intro.md
+live-preview.md
```
```{toctree}
diff --git a/docs/intro.md b/docs/intro.md
index dc657284..c4884960 100644
--- a/docs/intro.md
+++ b/docs/intro.md
@@ -28,7 +28,7 @@ conda install -c conda-forge myst-parser
(intro/sphinx)=
## Enable MyST in Sphinx
-To get started with Sphinx, see their [Quickstart Guide](https://www.sphinx-doc.org/en/master/usage/quickstart.html).
+To get started with Sphinx, see their [quick-start guide](inv:sphinx#usage/quickstart).
To use the MyST parser in Sphinx, simply add the following to your `conf.py` file:
@@ -46,7 +46,7 @@ To parse single documents, see the [](docutils.md) section
## Write a CommonMark document
MyST is an extension of [CommonMark Markdown](https://commonmark.org/),
-that includes [additional syntax](../syntax/syntax.md) for technical authoring,
+that includes [additional syntax](syntax/syntax.md) for technical authoring,
which integrates with Docutils and Sphinx.
To start off, create an empty file called `myfile.md` and give it a markdown title and text.
@@ -80,7 +80,7 @@ $ myst-docutils-html5 --stylesheet= myfile.md
```
To include this document within a Sphinx project,
-include `myfile.md` in a [`toctree` directive](sphinx:toctree-directive) on an index page.
+include `myfile.md` in a [`toctree` directive](inv:sphinx#toctree-directive) on an index page.
## Extend CommonMark with roles and directives
diff --git a/docs/live-preview.md b/docs/live-preview.md
new file mode 100644
index 00000000..095e5340
--- /dev/null
+++ b/docs/live-preview.md
@@ -0,0 +1,110 @@
+---
+py-config:
+ splashscreen:
+ autoclose: true
+ packages:
+ - myst-docutils
+ - docutils==0.19
+ - pygments
+---
+
+# Live Preview
+
+This is a live preview of the MyST Markdown [docutils renderer](docutils.md).
+You can edit the text/configuration below and see the live output.[^note]
+
+[^note]: Additional styling is usually provided by Sphinx themes.
+
+```{py-script}
+:file: live_preview.py
+```
+
+::::::::{grid} 1 1 1 2
+
+:::::::{grid-item}
+:child-align: end
+
+```{raw} html
+
+```
+
+:::::{tab-set}
+::::{tab-item} Input text
+````{raw} html
+
+````
+
+::::
+::::{tab-item} Configuration (YAML)
+
+::::
+:::::
+
+:::::::
+:::::::{grid-item}
+:child-align: end
+
+```{raw} html
+
+
+
+
+```
+
+::::{tab-set}
+:::{tab-item} HTML Render
+
+:::
+:::{tab-item} Raw Output
+
+:::
+:::{tab-item} Warnings
+
+:::
+::::
+:::::::
+::::::::
diff --git a/docs/live_preview.py b/docs/live_preview.py
new file mode 100644
index 00000000..474a624f
--- /dev/null
+++ b/docs/live_preview.py
@@ -0,0 +1,63 @@
+from io import StringIO
+
+import yaml
+from docutils.core import publish_string
+from js import document
+
+from myst_parser import __version__
+from myst_parser.parsers.docutils_ import Parser
+
+
+def convert(input_config: str, input_myst: str, writer_name: str) -> dict:
+ warning_stream = StringIO()
+ try:
+ settings = yaml.safe_load(input_config) if input_config else {}
+ assert isinstance(settings, dict), "not a dictionary"
+ except Exception as exc:
+ warning_stream.write(f"ERROR: config load: {exc}\n")
+ settings = {}
+ settings.update(
+ {
+ "output_encoding": "unicode",
+ "warning_stream": warning_stream,
+ }
+ )
+ try:
+ output = publish_string(
+ input_myst,
+ parser=Parser(),
+ writer_name=writer_name,
+ settings_overrides=settings,
+ )
+ except Exception as exc:
+ output = f"ERROR: conversion:\n{exc}"
+ return {"output": output, "warnings": warning_stream.getvalue()}
+
+
+version_label = document.querySelector("span#myst-version")
+config_textarea = document.querySelector("textarea#input_config")
+input_textarea = document.querySelector("textarea#input_myst")
+output_iframe = document.querySelector("iframe#output_html")
+output_raw = document.querySelector("textarea#output_raw")
+warnings_textarea = document.querySelector("textarea#output_warnings")
+oformat_select = document.querySelector("select#output_format")
+
+
+def do_convert(event=None):
+ result = convert(config_textarea.value, input_textarea.value, oformat_select.value)
+ output_raw.value = result["output"]
+ if "html" in oformat_select.value:
+ output_iframe.contentDocument.body.innerHTML = result["output"]
+ else:
+ output_iframe.contentDocument.body.innerHTML = (
+ "Change output format to HTML to see output"
+ )
+ warnings_textarea.value = result["warnings"]
+
+
+version_label.textContent = f"myst-parser v{__version__}"
+config_textarea.oninput = do_convert
+input_textarea.oninput = do_convert
+oformat_select.onchange = do_convert
+
+do_convert()
diff --git a/docs/syntax/optional.md b/docs/syntax/optional.md
index c5ee44ed..f9efca74 100644
--- a/docs/syntax/optional.md
+++ b/docs/syntax/optional.md
@@ -13,27 +13,30 @@ myst:
:width: 200px
```
key4: example
+ confpy: sphinx `conf.py` [configuration file](inv:sphinx#usage/configuration)
---
(syntax/extensions)=
# Syntax Extensions
-MyST-Parser is highly configurable, utilising the inherent "plugability" of the [markdown-it-py](markdown_it:index) parser.
+MyST-Parser is highly configurable, utilising the inherent "plugability" of the [markdown-it-py](inv:markdown_it#index) parser.
The following syntaxes are optional (disabled by default) and can be enabled *via* the sphinx `conf.py` (see also [](sphinx/config-options)).
-Their goal is generally to add more *Markdown friendly* syntaxes; often enabling and rendering [markdown-it-py plugins](markdown_it:md/plugins) that extend the [CommonMark specification](https://commonmark.org/).
+Their goal is generally to add more *Markdown friendly* syntaxes; often enabling and rendering [markdown-it-py plugins](inv:markdown_it#md/plugins) that extend the [CommonMark specification](https://commonmark.org/).
To enable all the syntaxes explained below:
```python
myst_enable_extensions = [
"amsmath",
+ "attrs_inline",
"colon_fence",
"deflist",
"dollarmath",
"fieldlist",
"html_admonition",
"html_image",
+ "inv_link",
"linkify",
"replacements",
"smartquotes",
@@ -43,7 +46,7 @@ myst_enable_extensions = [
]
```
-:::{important}
+:::{versionchanged} 0.13.0
`myst_enable_extensions` replaces previous configuration options:
`admonition_enable`, `figure_enable`, `dmath_enable`, `amsmath_enable`, `deflist_enable`, `html_img_enable`
:::
@@ -52,12 +55,12 @@ myst_enable_extensions = [
## Typography
-Adding `"smartquotes"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)) will automatically convert standard quotations to their opening/closing variants:
+Adding `"smartquotes"` to `myst_enable_extensions` (in the {{ confpy }}) will automatically convert standard quotations to their opening/closing variants:
- `'single quotes'`: 'single quotes'
- `"double quotes"`: "double quotes"
-Adding `"replacements"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)) will automatically convert some common typographic texts
+Adding `"replacements"` to `myst_enable_extensions` (in the {{ confpy }}) will automatically convert some common typographic texts
text | converted
----- | ----------
@@ -88,20 +91,20 @@ For example, `~~strikethrough with *emphasis*~~` renders as: ~~strikethrough wit
:::{warning}
This extension is currently only supported for HTML output,
and you will need to suppress the `myst.strikethrough` warning
-(see [](howto/warnings))
+(see [](myst-warnings))
:::
(syntax/math)=
## Math shortcuts
-Math is parsed by adding to the `myst_enable_extensions` list option, in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html) one or both of:
+Math is parsed by adding to the `myst_enable_extensions` list option, in the {{ confpy }} one or both of:
- `"dollarmath"` for parsing of dollar `$` and `$$` encapsulated math.
- `"amsmath"` for direct parsing of [amsmath LaTeX environments](https://ctan.org/pkg/amsmath).
-These options enable their respective Markdown parser plugins, as detailed in the [markdown-it plugin guide](markdown_it:md/plugins).
+These options enable their respective Markdown parser plugins, as detailed in the [markdown-it plugin guide](inv:markdown_it#md/plugins).
-:::{important}
+:::{versionchanged} 0.13.0
`myst_dmath_enable=True` and `myst_amsmath_enable=True` are deprecated, and replaced by `myst_enable_extensions = ["dollarmath", "amsmath"]`
:::
@@ -137,30 +140,24 @@ For example:
```latex
$$
- \begin{eqnarray}
- y & = & ax^2 + bx + c \\
- f(x) & = & x^2 + 2xy + y^2
- \end{eqnarray}
+ y & = ax^2 + bx + c \\
+ f(x) & = x^2 + 2xy + y^2
$$
```
becomes
$$
- \begin{eqnarray}
- y & = & ax^2 + bx + c \\
- f(x) & = & x^2 + 2xy + y^2
- \end{eqnarray}
+ y & = ax^2 + bx + c \\
+ f(x) & = x^2 + 2xy + y^2
$$
This is equivalent to the following directive:
````md
```{math}
- \begin{eqnarray}
- y & = & ax^2 + bx + c \\
- f(x) & = & x^2 + 2xy + y^2
- \end{eqnarray}
+ y & = ax^2 + bx + c \\
+ f(x) & = x^2 + 2xy + y^2
```
````
@@ -235,7 +232,7 @@ See [the extended syntax option](syntax/amsmath).
(syntax/mathjax)=
### Mathjax and math parsing
-When building HTML using the [sphinx.ext.mathjax](https://www.sphinx-doc.org/en/master/usage/extensions/math.html#module-sphinx.ext.mathjax) extension (enabled by default),
+When building HTML using the extension (enabled by default),
If `dollarmath` is enabled, Myst-Parser injects the `tex2jax_ignore` (MathJax v2) and `mathjax_ignore` (MathJax v3) classes in to the top-level section of each MyST document, and adds the following default MathJax configuration:
MathJax version 2 (see [the tex2jax preprocessor](https://docs.mathjax.org/en/v2.7-latest/options/preprocessors/tex2jax.html#configure-tex2jax):
@@ -257,7 +254,7 @@ To change this behaviour, set a custom regex, for identifying HTML classes to pr
(syntax/linkify)=
## Linkify
-Adding `"linkify"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)) will automatically identify "bare" web URLs and add hyperlinks:
+Adding `"linkify"` to `myst_enable_extensions` (in the {{ confpy }}) will automatically identify "bare" web URLs and add hyperlinks:
`www.example.com` -> www.example.com
@@ -272,7 +269,7 @@ Either directly; `pip install linkify-it-py` or *via* `pip install myst-parser[l
## Substitutions (with Jinja2)
-Adding `"substitution"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)) will allow you to add substitutions, added in either the `conf.py` using `myst_substitutions`:
+Adding `"substitution"` to `myst_enable_extensions` (in the {{ confpy }}) will allow you to add substitutions, added in either the `conf.py` using `myst_substitutions`:
```python
myst_substitutions = {
@@ -357,7 +354,7 @@ This may lead to unexpected outcomes.
:::
-Substitution references are assessed as [Jinja2 expressions](http://jinja.palletsprojects.com) which can use [filters](https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-builtin-filters), and also contains the [Sphinx Environment](https://www.sphinx-doc.org/en/master/extdev/envapi.html) in the context (as `env`).
+Substitution references are assessed as [Jinja2 expressions](http://jinja.palletsprojects.com) which can use [filters](https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-builtin-filters), and also contains the [Sphinx Environment](inv:sphinx#extdev/envapi) in the context (as `env`).
Therefore you can do things like:
```md
@@ -405,7 +402,7 @@ However, since Jinja2 substitutions allow for Python methods to be used, you can
## Code fences using colons
-By adding `"colon_fence"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)),
+By adding `"colon_fence"` to `myst_enable_extensions` (in the {{ confpy }}),
you can also use `:::` delimiters to denote code fences, instead of ```` ``` ````.
Using colons instead of back-ticks has the benefit of allowing the content to be rendered correctly, when you are working in any standard Markdown editor.
@@ -484,7 +481,7 @@ This text is **standard** _Markdown_
## Admonition directives
-:::{important}
+:::{versionchanged} 0.13.0
`myst_admonition_enable` is deprecated and replaced by `myst_enable_extensions = ["colon_fence"]` (see above).
Also, classes should now be set with the `:class: myclass` option.
@@ -542,9 +539,9 @@ $ myst-anchors -l 2 docs/syntax/optional.md
## Definition Lists
-By adding `"deflist"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)),
+By adding `"deflist"` to `myst_enable_extensions` (in the {{ confpy }}),
you will be able to utilise definition lists.
-Definition lists utilise the [markdown-it-py deflist plugin](markdown_it:md/plugins), which itself is based on the [Pandoc definition list specification](http://johnmacfarlane.net/pandoc/README.html#definition-lists).
+Definition lists utilise the [markdown-it-py deflist plugin](inv:markdown_it#md/plugins), which itself is based on the [Pandoc definition list specification](http://johnmacfarlane.net/pandoc/README.html#definition-lists).
This syntax can be useful, for example, as an alternative to nested bullet-lists:
@@ -621,9 +618,9 @@ Term 3
(syntax/tasklists)=
## Task Lists
-By adding `"tasklist"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)),
+By adding `"tasklist"` to `myst_enable_extensions` (in the {{ confpy }}),
you will be able to utilise task lists.
-Task lists utilise the [markdown-it-py tasklists plugin](markdown_it:md/plugins),
+Task lists utilise the [markdown-it-py tasklists plugin](inv:markdown_it#md/plugins),
and are applied to markdown list items starting with `[ ]` or `[x]`:
```markdown
@@ -695,7 +692,7 @@ based on the [reStructureText syntax](https://docutils.sourceforge.io/docs/ref/r
print("Hello, world!")
```
-A prominent use case of field lists is for use in API docstrings, as used in [Sphinx's docstring renderers](sphinx:python-domain):
+A prominent use case of field lists is for use in API docstrings, as used in [Sphinx's docstring renderers](inv:sphinx#python-domain):
````md
```{py:function} send_message(sender, priority)
@@ -727,9 +724,90 @@ Send a message to a recipient
Currently `sphinx.ext.autodoc` does not support MyST, see [](howto/autodoc).
:::
+(syntax/attributes)=
+## Inline attributes
+
+:::{versionadded} 0.19
+This feature is in *beta*, and may change in future versions.
+It replace the previous `attrs_image` extension, which is now deprecated.
+:::
+
+By adding `"attrs_inline"` to `myst_enable_extensions` (in the {{ confpy }}),
+you can enable parsing of inline attributes after certain inline syntaxes.
+This is adapted from [djot inline attributes](https://htmlpreview.github.io/?https://github.com/jgm/djot/blob/master/doc/syntax.html#inline-attributes),
+and also related to [pandoc bracketed spans](https://pandoc.org/MANUAL.html#extension-bracketed_spans).
+
+Attributes are specified in curly braces after the inline syntax.
+Inside the curly braces, the following syntax is recognised:
+
+- `.foo` specifies `foo` as a class.
+ Multiple classes may be given in this way; they will be combined.
+- `#foo` specifies `foo` as an identifier.
+ An element may have only one identifier;
+ if multiple identifiers are given, the last one is used.
+- `key="value"` or `key=value` specifies a key-value attribute.
+ Quotes are not needed when the value consists entirely of
+ ASCII alphanumeric characters or `_` or `:` or `-`.
+ Backslash escapes may be used inside quoted values.
+ **Note** only certain keys are supported, see below.
+- `%` begins a comment, which ends with the next `%` or the end of the attribute (`}`).
+
+For example, the following Markdown:
+
+```md
+
+- [A span of text with attributes]{#spanid .bg-warning},
+ {ref}`a reference to the span `
+
+- `A literal with attributes`{#literalid .bg-warning},
+ {ref}`a reference to the literal
+
+- An autolink with attributes: {.bg-warning title="a title"}
+
+- [A link with attributes](syntax/attributes){#linkid .bg-warning},
+ {ref}`a reference to the link `
+
+- ![An image with attribute](img/fun-fish.png){#imgid .bg-warning w=100px align=center}
+ {ref}`a reference to the image `
+
+```
+
+will be parsed as:
+
+- [A span of text with attributes]{#spanid .bg-warning},
+ {ref}`a reference to the span `
+
+- `A literal with attributes`{#literalid .bg-warning},
+ {ref}`a reference to the literal `
+
+- An autolink with attributes: {.bg-warning title="a title"}
+
+- [A link with attributes](syntax/attributes){#linkid .bg-warning},
+ {ref}`a reference to the link `
+
+- ![An image with attribute](img/fun-fish.png){#imgid .bg-warning w="100px" align=center}
+ {ref}`a reference to the image `
+
+### key-value attributes
+
+`id` and `class` are supported for all inline syntaxes,
+but only certain key-value attributes are supported for each syntax.
+
+For **literals**, the following attributes are supported:
+
+- `language`/`lexer`/`l` defines the syntax lexer,
+ e.g. `` `a = "b"`{l=python} `` is displayed as `a = "b"`{l=python}.
+ Note, this is only supported in `sphinx >= 5`.
+
+For **images**, the following attributes are supported (equivalent to the `image` directive):
+
+- `width`/`w` defines the width of the image (in `%`, `px`, `em`, `cm`, etc)
+- `height`/`h` defines the height of the image (in `px`, `em`, `cm`, etc)
+- `align`/`a` defines the scale of the image (`left`, `center`, or `right`)
+
(syntax/images)=
-## Images
+## HTML Images
MyST provides a few different syntaxes for including images in your documentation, as explained below.
@@ -768,7 +846,7 @@ This is usually a bad option, because the HTML is treated as raw text during the
HTML parsing to the rescue!
-By adding `"html_image"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)),
+By adding `"html_image"` to `myst_enable_extensions` (in the {{ confpy }}),
MySt-Parser will attempt to convert any isolated `img` tags (i.e. not wrapped in any other HTML) to the internal representation used in sphinx.
```html
@@ -786,51 +864,15 @@ HTML image can also be used inline!
I'm an inline image:
-### Inline attributes
-
-:::{warning}
-This extension is currently experimental, and may change in future versions.
-:::
-
-By adding `"attrs_image"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)),
-you can enable parsing of inline attributes for images.
-
-For example, the following Markdown:
-
-```md
-![image attrs](img/fun-fish.png){#imgattr .bg-primary width="100px" align=center}
-
-{ref}`a reference to the image `
-```
-
-will be parsed as:
-
-![image attrs](img/fun-fish.png){#imgattr .bg-primary width="100px" align=center}
-
-{ref}`a reference to the image `
-
-Inside the curly braces, the following syntax is possible:
-
-- `.foo` specifies `foo` as a class.
- Multiple classes may be given in this way; they will be combined.
-- `#foo` specifies `foo` as an identifier.
- An element may have only one identifier;
- if multiple identifiers are given, the last one is used.
-- `key="value"` or `key=value` specifies a key-value attribute.
- Quotes are not needed when the value consists entirely of
- ASCII alphanumeric characters or `_` or `:` or `-`.
- Backslash escapes may be used inside quoted values.
-- `%` begins a comment, which ends with the next `%` or the end of the attribute (`}`).
-
(syntax/figures)=
## Markdown Figures
-By adding `"colon_fence"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)),
+By adding `"colon_fence"` to `myst_enable_extensions` (in the {{ confpy }}),
we can combine the above two extended syntaxes,
to create a fully Markdown compliant version of the `figure` directive named `figure-md`.
-:::{important}
+:::{versionchanged} 0.13.0
`myst_figure_enable` with the `figure` directive is deprecated and replaced by `myst_enable_extensions = ["colon_fence"]` and `figure-md`.
:::
@@ -868,7 +910,7 @@ As we see here, the target we set can be referenced:
## HTML Admonitions
-By adding `"html_admonition"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)),
+By adding `"html_admonition"` to `myst_enable_extensions` (in the {{ confpy }}),
you can enable parsing of `
-
+
text
diff --git a/tests/test_sphinx/test_sphinx_builds/test_includes.xml b/tests/test_sphinx/test_sphinx_builds/test_includes.xml
index 1e8779c5..64ff16ab 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_includes.xml
+++ b/tests/test_sphinx/test_sphinx_builds/test_includes.xml
@@ -7,14 +7,14 @@
A Sub-Heading in Include
- Some text with
+ Some text with
syntax
A Sub-Heading in Nested Include
- Some other text with
+ Some other text with
syntax
@@ -24,7 +24,7 @@
Caption
- This absolute path will refer to the project root (where the
+ This absolute path will refer to the project root (where the
conf.py
is):
@@ -37,7 +37,7 @@
-
+
text
@@ -47,7 +47,7 @@
def
-
+
a_func
@@ -56,8 +56,8 @@
param
):
-
-
+
+
print
@@ -68,10 +68,10 @@
)
- 0
+ 0
def
-
+
a_func
@@ -80,10 +80,10 @@
param
):
-
+
- 1
-
+ 1
+
print
@@ -94,20 +94,20 @@
)
This should be *literal*
-
+
Lots
of
lines
so we can select some
- 0
+ 0
Lots
- 1
+ 1
of
A Sub-sub-Heading
- some more text
+ some more text
\ No newline at end of file
diff --git a/tests/test_sphinx/test_sphinx_builds/test_references.html b/tests/test_sphinx/test_sphinx_builds/test_references.html
index a6d4036f..63297b93 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_references.html
+++ b/tests/test_sphinx/test_sphinx_builds/test_references.html
@@ -59,21 +59,21 @@