question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Markdown syntax for roles and directives

See original GitHub issue

Last week we had a few nice conversations around “how to extend Markdown to support roles and directives from Sphinx”.

This is a quick issue to try an keep track of our thinking there.

What kinds syntax chunks are there?

  • operate on raw text and yield a block element
  • operate on raw text and yield an inline element
  • operate on commonmark block content and yield a block element
  • operate on commonmark inline content and yield an inline element

What we arrived at

After a few conversations, we arrived at a syntax that uses triple-backticks, followed by directive name, followed by configuration with two options (either using {key=val} or YAML front-matter inside the code block).

So something like (ignore the slashes, just for rendering purposes):

\```mydirective {key=val}
\```

And for in-line text, using single-backticks followed by an identifier in the traits associated w/ it:

This is `my role`{myrolename key=val}

This effectively treats everything as “raw text”, with the idea that this would degrade gracefully by just rendering as a raw blob if the directive didn’t exist.

How would this clash with current markdown or rST behavior?

Something like this:

  • If a triple-backtick block is found, check the language associated with it
  • See if the language exists in a list of directives in the current environment
    • If so, treat it as a directive block and not a language block. Anything in {} becomes configuration for the directive. Anything inside the backticks becomes content that is processed by the directive.
    • If not, treat it as a language block

Something similar could be done with in-line blocks

What others have found

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:23 (21 by maintainers)

github_iconTop GitHub Comments

4reactions
choldgrafcommented, Feb 11, 2020

4reactions
chrisjsewellcommented, Feb 11, 2020

Behold the first Markdown directive parser!

See the bottom of https://github.com/chrisjsewell/mistletoe/blob/myst/test.ipynb

Current format is:

````{note}
abcd *abc* [a](link)

```{warning}
xyz
```

````

which is transformed to docutils AST:

<document source="">
    <note>
        <paragraph>
            abcd 
            <emphasis>
                abc
             
            <pending_xref refdomain="True" refexplicit="True" reftarget="link" reftype="any" refwarn="True">
                <reference refuri="link">
                    a
        <warning>
            <paragraph>
                xyz

FYI for all the tests (which are extensive) see: https://travis-ci.org/chrisjsewell/mistletoe

Read more comments on GitHub >

github_iconTop Results From Across the Web

Roles and Directives - MyST-Parser - Read the Docs
Roles and directives provide a way to extend the syntax of MyST in an unbound manner, by interpreting a chuck of text as...
Read more >
Markdown Files — Física General
Roles and directives are two of the most powerful tools in Jupyter Book. They are kind of like functions, but written in a...
Read more >
MyST Markdown overview - Jupyter Book
Roles and directives are two of the most powerful tools in Jupyter Book. ... MyST supports all syntax of CommonMark Markdown (the kind...
Read more >
Markdown and ReST — Sphinx-lesson documentation
ReStructured Text has native support for roles and directives, which makes it a more structured language such as LaTeX, rather than HTML.
Read more >
Themes » Writing reST content - m.css
Contents · Basic syntax. Metadata fields; Directives; Interpreted text roles · Basic block elements · Basic inline elements · Essential directives · Essential ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found