You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Split docutils only functionality into separate package #347
If I had known previously about such an intention to ship Markdown in docutils, I would certainly have considered splitting the "docutils only" aspects in to a separate "myst-docutils" package (and have that as a dependency here), which I think would probably be a better solution than just moving dependencies to extras.
Indeed, if there was an agreement in principle with the docutils guys to include something like myst-docutils in docutils I would look into this.
Ah well that's a different proposition: I literally have myst_parser/docutils_renderer.py and myst_parser/sphinx_renderer.py as a sub-class, so that it is certainly possible to use myst-parser with "docutils only" functionality.
I think this would be great. The thing that's missing right now for convenient integration with docutils, I think (besides separating dependencies), is a version of sphinx_parser for docutils. It would allow this kind of code to work:
(and with that integration into a variety of other docutils-based pipelines; my use case is integrating with Alectryon for Coq proofs.)
As currently written, this code crashes:
Traceback (most recent call last):
File "minimyst.py", line 3, in <module>
print(publish_string(source="{math}`a^2 + b^2 = c^2`", parser=MystParser(), writer_name='html5'))
File "/home/clement/.local/lib/python3.8/site-packages/docutils/core.py", line 407, in publish_string
output, pub = publish_programmatically(
File "/home/clement/.local/lib/python3.8/site-packages/docutils/core.py", line 665, in publish_programmatically
output = pub.publish(enable_exit_status=enable_exit_status)
File "/home/clement/.local/lib/python3.8/site-packages/docutils/core.py", line 217, in publish
self.document = self.reader.read(self.source, self.parser,
File "/home/clement/.local/lib/python3.8/site-packages/docutils/readers/__init__.py", line 71, in read
self.parse()
File "/home/clement/.local/lib/python3.8/site-packages/docutils/readers/__init__.py", line 77, in parse
self.parser.parse(self.input, document)
File "/home/clement/.local/lib/python3.8/site-packages/myst_parser/sphinx_parser.py", line 55, in parse
config = document.settings.env.myst_config
AttributeError: 'Values' object has no attribute 'env'
This crash is due to parse taking an additional argument that docutils doesn't pass:
defparse(self, inputstring: str, document: nodes.document, renderer: str="sphinx") ->None:
ifrenderer=="sphinx":
config=document.settings.env.myst_config# Here, since docutils will call this function without specifying the rendererelse:
config=MdParserConfig()
It works fine if I use a subclass of MystParser that passes a dummy renderer string into super().parse instead of the default "sphinx":
… but it's no clear whether that's the right approach (?) So separating things out in a way that makes this works would be very very nice, especially setting MyST options works from the usual docutils.conf, etc.
Also nice would be some canonical way to register MyST's directives and roles: some function that clients can call to make the appropriate calls to docutils.directives.register_directive etc.
But am I correct to think that this requires extra work to also parse MyST's config, recreate its custom roles/directives (?) and make a Reader that's compatible with docutils?
In any case it looks like with very small changes (and independently of integrating with the official docutils package) applications like Alectryon that already depend on docutils but not necessarily sphinx could add support for MyST, which would be great!
@cpitclaudel has kindly made a PR to allow for controlling the configuration via docutils: #426, that I'm just trying to find time to circle round to and finalise the tests.
The only sticking point perhaps is myst-parser's pinned dependency on sphinx, creating a cylic dependency. I specifically added this, because changes in docutils/sphinx kept breaking myst-parser for users, so would have to think how this could be achieved
Reacted by Manuel Kaufmann and Juan Luis Cano Rodríguez
@gmilde, do you want me to open an issue on docutils, to move from
recommonmark to myst-docutils?
If the above works, Docutils can add `'myst': 'myst_parser.docutils_',`
to `docutils.parsers._parser_aliases` to provide a shorter parser name.
In future, the default "markdown" and "commonmark" parsers may switch to
"myst", but this is an API change which requires planning, advance warnings,
and tests.
Feel free to open an enhancement ticket or start a thread on
***@***.*** to discuss arising issues, a test
strategy and possible closer integration.
Although setup() supports a scripts keyword for pointing to pre-made scripts to install, the recommended approach to achieve cross-platform compatibility is to use console_scripts entry points
IMV, separate front end tools are not necessary
I felt this was easier for end users, and also inline with the separate
rst2xxx.py front end tools that docutils already ships with
Unfortunately, the approach of a separate front-end tool for every
reader-parser-writer combination doesn't scale well. This is why Docutils
0.17 introduced the generic "docutils-cli" front-end together with Markdown
support.
From the description at [MyST with Docutils](https://myst-parser--426.org.readthedocs.build/en/426/docutils.html),
I suppose that `docutils-cli.py --parser=`myst_parser.docutils_`
should do the trick.
(It should also enable the user to get output from writers not in the
myst2... set, e.g., ODT or LaTeX for processing with LuaTeX or XeTeX
engines).
The generic front-end has also command-line support for all
[Docutils configuration settings](https://docutils.sourceforge.io/docs/user/config.html).
For end users consistent configuration framework would help a lot.
If `myst_parser.docutils_.Parser.settings_spec` could
provide an interface to the relevant myst configuration options, this would
allow configuring reader, parser, and writer from the command line
or a common config file. A user would easily get help for all available
options with `docutils-cli --parser=myst_parser.docutils_ --help`.
Unfortunately, the approach of a separate front-end tool for every reader-parser-writer combination doesn't scale well.
Oh indeed, but also having to write the full parser path, etc, every time is not ideal.
Usually, if I am making a complex CLI I would use click.palletsprojects.com/
I suppose that docutils-cli.py --parser=myst_parser.docutils_` should do the trick.
Yes the parser is just a standard docutils parser.
Again here, I would suggest you use entry points to load parsers, rather than module paths
If myst_parser.docutils_.Parser.settings_spec could
provide an interface to the relevant myst configuration options, this would
allow configuring reader
Usage
=====
myst-docutils-<writer> [options] [<source> [<destination>]]
Options
=======
General Docutils Options
------------------------
--title=TITLE Specify the document title as metadata.
--generator, -g Include a "Generated by Docutils" credit and link.
--no-generator Do not include a generator credit.
--date, -d Include the date at the end of the document (UTC).
--time, -t Include the time & date (UTC).
--no-datestamp Do not include a datestamp of any kind.
--source-link, -s Include a "View document source" link.
--source-url=<URL> Use <URL> for a source link; implies --source-link.
--no-source-link Do not include a "View document source" link.
--toc-entry-backlinks Link from section headers to TOC entries. (default)
--toc-top-backlinks Link from section headers to the top of the TOC.
--no-toc-backlinks Disable backlinks to the table of contents.
--footnote-backlinks Link from footnotes/citations to references. (default)
--no-footnote-backlinks
Disable backlinks from footnotes and citations.
--section-numbering Enable section numbering by Docutils. (default)
--no-section-numbering Disable section numbering by Docutils.
--strip-comments Remove comment elements from the document tree.
--leave-comments Leave comment elements in the document tree. (default)
--strip-elements-with-class=<class>
Remove all elements with classes="<class>" from the
document tree. Warning: potentially dangerous; use
with caution. (Multiple-use option.)
--strip-class=<class> Remove all classes="<class>" attributes from elements
in the document tree. Warning: potentially dangerous;
use with caution. (Multiple-use option.)
--report=<level>, -r <level>
Report system messages at or higher than <level>:
"info" or "1", "warning"/"2" (default), "error"/"3",
"severe"/"4", "none"/"5"
--verbose, -v Report all system messages. (Same as "--report=1".)
--quiet, -q Report no system messages. (Same as "--report=5".)
--halt=<level> Halt execution at system messages at or above <level>.
Levels as in --report. Default: 4 (severe).
--strict Halt at the slightest problem. Same as "--halt=info".
--exit-status=<level> Enable a non-zero exit status for non-halting system
messages at or above <level>. Default: 5 (disabled).
--debug Enable debug-level system messages and diagnostics.
--no-debug Disable debug output. (default)
--warnings=<file> Send the output of system messages to <file>.
--traceback Enable Python tracebacks when Docutils is halted.
--no-traceback Disable Python tracebacks. (default)
--input-encoding=<name[:handler]>, -i <name[:handler]>
Specify the encoding and optionally the error handler
of input text. Default: <locale-dependent>:strict.
--input-encoding-error-handler=INPUT_ENCODING_ERROR_HANDLER
Specify the error handler for undecodable characters.
Choices: "strict" (default), "ignore", and "replace".
--output-encoding=<name[:handler]>, -o <name[:handler]>
Specify the text encoding and optionally the error
handler for output. Default: UTF-8:strict.
--output-encoding-error-handler=OUTPUT_ENCODING_ERROR_HANDLER
Specify error handler for unencodable output
characters; "strict" (default), "ignore", "replace",
"xmlcharrefreplace", "backslashreplace".
--error-encoding=<name[:handler]>, -e <name[:handler]>
Specify text encoding and error handler for error
output. Default: UTF-8:backslashreplace.
--error-encoding-error-handler=ERROR_ENCODING_ERROR_HANDLER
Specify the error handler for unencodable characters
in error output. Default: backslashreplace.
--language=<name>, -l <name>
Specify the language (as BCP 47 language tag).
Default: en.
--record-dependencies=<file>
Write output file dependencies to <file>.
--config=<file> Read configuration settings from <file>, if it exists.
--version, -V Show this program's version number and exit.
--help, -h Show this help message and exit.
reStructuredText Parser Options
-------------------------------
--pep-references Recognize and link to standalone PEP references (like
"PEP 258").
--pep-base-url=<URL> Base URL for PEP references (default
"http://www.python.org/dev/peps/").
--pep-file-url-template=<URL>
Template for PEP file part of URL. (default
"pep-%04d")
--rfc-references Recognize and link to standalone RFC references (like
"RFC 822").
--rfc-base-url=<URL> Base URL for RFC references (default
"http://tools.ietf.org/html/").
--tab-width=<width> Set number of spaces for tab expansion (default 8).
--trim-footnote-reference-space
Remove spaces before footnote references.
--leave-footnote-reference-space
Leave spaces before footnote references.
--no-file-insertion Disable directives that insert the contents of
external file ("include" & "raw"); replaced with a
"warning" system message.
--file-insertion-enabled
Enable directives that insert the contents of external
file ("include" & "raw"). Enabled by default.
--no-raw Disable the "raw" directives; replaced with a
"warning" system message.
--raw-enabled Enable the "raw" directive. Enabled by default.
--syntax-highlight=<format>
Token name set for parsing code with Pygments: one of
"long", "short", or "none (no parsing)". Default is
"long".
--smart-quotes=<yes/no/alt>
Change straight quotation marks to typographic form:
one of "yes", "no", "alt[ernative]" (default "no").
--smartquotes-locales=<language:quotes[,language:quotes,...]>
Characters to use as "smart quotes" for <language>.
--word-level-inline-markup
Inline markup recognized at word boundaries only
(adjacent to punctuation or whitespace). Force
character-level inline markup recognition with "\ "
(backslash + space). Default.
--character-level-inline-markup
Inline markup recognized anywhere, regardless of
surrounding characters. Backslash-escapes must be used
to avoid unwanted markup recognition. Useful for East
Asian languages. Experimental.
MyST options
------------
--myst-commonmark-only=MYST_COMMONMARK_ONLY
Use strict CommonMark parser (type: bool, default:
False)
--myst-enable-extensions=MYST_ENABLE_EXTENSIONS
Enable extensions (type: comma-delimited, default:
'dollarmath')
--myst-linkify-fuzzy-links=MYST_LINKIFY_FUZZY_LINKS
linkify: recognise URLs without schema prefixes (type:
bool, default: True)
--myst-dmath-allow-labels=MYST_DMATH_ALLOW_LABELS
Parse `$$...$$ (label)` (type: bool, default: True)
--myst-dmath-allow-space=MYST_DMATH_ALLOW_SPACE
dollarmath: allow initial/final spaces in `$ ... $`
(type: bool, default: True)
--myst-dmath-allow-digits=MYST_DMATH_ALLOW_DIGITS
dollarmath: allow initial/final digits `1$ ...$2`
(type: bool, default: True)
--myst-dmath-double-inline=MYST_DMATH_DOUBLE_INLINE
dollarmath: parse inline `$$ ... $$` (type: bool,
default: False)
--myst-disable-syntax=MYST_DISABLE_SYNTAX
Disable syntax elements (type: comma-delimited,
default: '')
--myst-url-schemes=MYST_URL_SCHEMES
URL schemes to allow in links (type: comma-delimited,
default: 'http,https,mailto,ftp')
--myst-footnote-transition=MYST_FOOTNOTE_TRANSITION
Place a transition before any footnotes (type: bool,
default: True)
--myst-words-per-minute=MYST_WORDS_PER_MINUTE
For reading speed calculations (type: int, default:
200)
Unfortunately, the approach of a separate front-end tool for every
reader-parser-writer combination doesn't scale well.
Oh indeed, but also having to write the full parser path, etc, every time is
not ideal.
This would be mitigated by a "myst" parser alias (implemented in
[r8916]). Now, `docutils-cli.py --parser=myst` should work just like
`myst-docutils-html5`. Different default components can be set in
[docutils.conf files](https://docutils.sourceforge.io/docs/user/config.html):
system-wide, user-wide and per directory.
Another option would be a common `myst-docutils` front-end (with a
`--writer` option) instead of a set of 5 (out of 12) front-ends. Again,
docutils.conf files would allow to set the preferred writer and reader.
I suppose that docutils-cli.py --parser=myst_parser.docutils_` should do
the trick.
Yes the parser is just a standard docutils parser.
I realized that docutils-cli.py restricted the `--parser` values to
"rst", "recommonmark" and "markdown". This is fixed in [r8915].
Again here, I would suggest you use entry points to load parsers,
rather than module paths.
I have been experimenting with a `docutils.parsers.myst_wrapper` module
(analogue to `docutils.parsers.recommonmark_wrapper`).
Currently, the only difference to the parser name alias is a more helpful
error message in case the upstream parser is missing.
A wrapper module may become necessary, if the import name changes
or to implement a "commonmark" parser that selects whichever of "myst" or
"recommonmark" is available.
If myst_parser.docutils_.Parser.settings_spec could provide an
interface to the relevant myst configuration options, [...]
Yep this already what happens, [...]
This is good news. From the documentation it was not clear to me, that this
means the `myst-…` options can be set also from a `docutils.conf` file,
nor that the `myst-doctuils-…` front-ends also feature the config settings
of the relevant writers.
...
BTW: Why do the `myst-doctuils-…` front-ends include rst parser settings?
Maybe some settings should move to a generic "parser options" section (and
"smart-quotes" to the generic options). But settings may also be defined in
several components (see, e.g. the "stylesheet…" settings in HTML and LaTeX).
BTW: Why do the myst-doctuils-… front-ends include rst parser settings?
myst-parser hooks in to the RST directive/role parsing mechanisms, I seem to recall some of these settings were required, and it was breaking without them being present.
Activity
cpitclaudel commentedon Jul 18, 2021
I think this would be great. The thing that's missing right now for convenient integration with docutils, I think (besides separating dependencies), is a version of
sphinx_parserfor docutils. It would allow this kind of code to work:(and with that integration into a variety of other docutils-based pipelines; my use case is integrating with Alectryon for Coq proofs.)
As currently written, this code crashes:
(in fact I see now that it's almost exactly the same example as in https://sourceforge.net/p/docutils/mailman/docutils-users/thread/rkv4nb%24139g%241%40ciao.gmane.io/#msg37118232)
This crash is due to
parsetaking an additional argument that docutils doesn't pass:It works fine if I use a subclass of
MystParserthat passes a dummyrendererstring intosuper().parseinstead of the default"sphinx":… but it's no clear whether that's the right approach (?) So separating things out in a way that makes this works would be very very nice, especially setting MyST options works from the usual
docutils.conf, etc.Also nice would be some canonical way to register MyST's directives and roles: some function that clients can call to make the appropriate calls to
docutils.directives.register_directiveetc.In #342 @astrojuanlu wrote:
and @choldgraf wrote
But am I correct to think that this requires extra work to also parse MyST's config, recreate its custom roles/directives (?) and make a
Readerthat's compatible with docutils?In any case it looks like with very small changes (and independently of integrating with the official docutils package) applications like Alectryon that already depend on docutils but not necessarily sphinx could add support for MyST, which would be great!
[draft] Remove option mathjax_classes
gmilde commentedon Oct 16, 2021
Given the end-of-life for recommonmark, is there a chance for a Docutils-only version of the MyST parser that can be utilised by Docutils?
chrisjsewell commentedon Oct 16, 2021
Heya,
DocutilsRendereris already a docutils-only renderer:MyST-Parser/myst_parser/docutils_renderer.py
Line 72 in a28e9b7
@cpitclaudel has kindly made a PR to allow for controlling the configuration via docutils: #426, that I'm just trying to find time to circle round to and finalise the tests.
The only sticking point perhaps is myst-parser's pinned dependency on sphinx, creating a cylic dependency. I specifically added this, because changes in docutils/sphinx kept breaking myst-parser for users, so would have to think how this could be achieved
chrisjsewell commentedon Dec 11, 2021
myst-parser v0.16.0 now introduces docutils-only functionality (https://myst-parser.readthedocs.io/en/latest/docutils.html) and https://pypi.org/project/myst-docutils/ release pipeline, which inlcudes no install dependencies on sphinx/docutils 😄
@gmilde, do you want me to open an issue on docutils, to move from recommonmark to myst-docutils?
gmilde commentedon Dec 16, 2021
chrisjsewell commentedon Dec 16, 2021
They don't need separate files, they use python entry points:
MyST-Parser/setup.cfg
Lines 50 to 57 in 11fb239
I feel this is the more modern approach for including CLI tools in python package distributions.
I felt this was easier for end users, and also inline with the separate
rst2xxx.pyfront end tools that docutils already ships withYep will do then 👍
chrisjsewell commentedon Dec 16, 2021
See https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/?highlight=console_scripts#scripts
chrisjsewell commentedon Dec 16, 2021
Also, just to note, there are now separate test jobs for basic testing of myst-docutils against docutils 0.16, 0.17, and 0.18 (on top of the full test suite): https://github.com/executablebooks/MyST-Parser/runs/4546203130?check_suite_focus=true
gmilde commentedon Dec 20, 2021
chrisjsewell commentedon Dec 20, 2021
Oh indeed, but also having to write the full parser path, etc, every time is not ideal.
Usually, if I am making a complex CLI I would use click.palletsprojects.com/
Yes the parser is just a standard docutils parser.
Again here, I would suggest you use entry points to load parsers, rather than module paths
Yep this is already what happens,
settings_specalready contains all the myst options, so when you use the CLI you get, e.g. (as shown in the drop down at https://myst-parser.readthedocs.io/en/latest/docutils.html)gmilde commentedon Dec 23, 2021
chrisjsewell commentedon Jan 2, 2022
yep that sounds good, although I would note, I do like the "inherent" tab-completion you get in the terminal with the
myst-docutils-commands:makes it very easy to use.
myst-parser hooks in to the RST directive/role parsing mechanisms, I seem to recall some of these settings were required, and it was breaking without them being present.
Anyhow, I have now opened https://sourceforge.net/p/docutils/feature-requests/86/ and created #487 for any parallel discussion here, so any more conversation can move to them cheers