Skip to content

Commit ce47cdf

Browse files
agoose77Rowan Cockett
andcommitted
feat: add angus as author
Co-authored-by: Rowan Cockett <[email protected]>>
1 parent 4c19816 commit ce47cdf

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

contributors.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ project:
4949
orcid: 0000-0002-0760-5497
5050
affiliation: Curvenote Inc.
5151
52+
- id: agoose77
53+
name: Angus Hollands
54+
github: agoose77
55+
orcid: 0000-0003-0788-3814
56+
affiliation: 2i2c

meps/mep-0003.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ title: Inline Options for Roles and Directives
66
date: 2025/01/27
77
authors:
88
- rowanc1
9+
- agoose77
910
short_title: Inline Options
1011
description: An inline syntax for setting options on roles and directives.
1112
data:
12-
discussion: 'https://github.com/jupyter-book/myst-enhancement-proposals/pull/28'
13+
discussion: "https://github.com/jupyter-book/myst-enhancement-proposals/pull/28"
1314
abbreviations:
1415
DSL: Domain Specific Language
1516
---
@@ -20,22 +21,26 @@ We propose an extension to the MyST Markdown syntax for roles and directives tha
2021

2122
## Context
2223

23-
There is currently no syntax support for parametrising role definitions[^def] in MyST Markdown. This limitation has led to workarounds such as postfix role name conventions that conceptually group together related roles (e.g. `cite:ps`, `cite:t`), or the use of DSLs in the role body for parsing multiple values (e.g. `` {doc}`title <document.md>` ``). Given that these approaches are both unstandardized and limited in their extensibility, the lack of proper syntax support imposes strong contraints on the utility of roles.
24+
There is currently no syntax support for parametrising role definitions[^def] in MyST Markdown. This limitation has led to workarounds such as postfix role name conventions that conceptually group together related roles (e.g. `cite:ps`, `cite:t`), or the use of DSLs in the role body for parsing multiple values (e.g. `` {doc}`title <document.md>` ``). Given that these approaches are both unstandardized and limited in their extensibility, the lack of proper syntax support imposes strong contraints on the utility of roles.
2425

2526
[^def]: Where a role _definition_ is the appearance of the role in a MyST document, rather than the role _declaration_ which specifies its behaviour and interface.
2627

2728
## Proposal
2829

2930
We propose extending the MyST Markdown syntax to support parametrisation of roles and directives. The existing syntax for defining a role and directive of the form
30-
````
31+
32+
```
3133
{ROLE-NAME}`ROLE-BODY`
32-
````
34+
```
35+
3336
and
37+
3438
````
3539
```{DIRECTIVE-NAME}
3640
DIRECTIVE-BODY
3741
```
3842
````
43+
3944
will be extended by replacing the `{NAME}` syntax of specifying role/directive names with a more general _inline attribute_ syntax of the form `{NAME .CLASS #ID KEY=VALUE}`. With this new syntax, it will be possible to directly define directive options in an inline manner, e.g. the following are equivalent:
4045

4146
````
@@ -54,16 +59,19 @@ Content of the tip directive.
5459
Content of the tip directive.
5560
```
5661
````
62+
5763
where [](#new-syntax-example) is the new inline attribute syntax.
5864

5965
### Inline Attribute Syntax
6066

61-
The internal inline syntax for specifying content will follow existing standards in [Pandoc](https://pandoc.org/chunkedhtml-demo/8.18-divs-and-spans.html)/[djot](https://htmlpreview.github.io/?https://github.com/jgm/djot/blob/master/doc/syntax.html#inline-attributes), with the addition of the role/directive name that already exists in MyST Markdown.
67+
The internal inline syntax for specifying content will follow existing standards in [Pandoc](https://pandoc.org/chunkedhtml-demo/8.18-divs-and-spans.html)/[djot](https://htmlpreview.github.io/?https://github.com/jgm/djot/blob/master/doc/syntax.html#inline-attributes), with the addition of the role/directive name that already exists in MyST Markdown.
68+
69+
In pseudo-grammar, the new inline attribute syntax may be expressed as
6270

63-
In pseudo-grammar, the new inline attribute syntax may be expressed as
6471
```
6572
{NAME .CLASS #ID KEY=VALUE}
6673
```
74+
6775
where `NAME`, `.CLASS`, `#ID`, and `KEY=VALUE` are unique types of attribute definitions as follows:
6876

6977
`NAME`
@@ -73,19 +81,17 @@ where `NAME`, `.CLASS`, `#ID`, and `KEY=VALUE` are unique types of attribute def
7381
: The name of a class to annotate the AST with. This **may** be (repeatedly) defined. Each defined class will be combined into a single whitespace-separated string and passed to the role or directive as the `class` option
7482

7583
`#ID`
76-
: A unique label which will be passed to the role or directive as the `label` option. This **may** be defined **once**. If it is repeated, only the final label will be used and a warning will be raised.
84+
: A unique label which will be passed to the role or directive as the `label` option. This **may** be defined **once**. If it is repeated, only the final label will be used and a warning will be raised.
7785

7886
`KEY=VALUE`
7987
: A key-value pair to set as named options. A `KEY` **must** be defined **once** if the role definition marks the it as required, otherwise these **may** be defined **once**. Quotes are not needed when the`VALUE` consists entirely of ASCII alphanumeric characters or `_` or `:` or `-`. Backslash escapes may be used inside quoted values. These values are parsed according to the directive options (e.g. string, markup, number, etc.)
8088

81-
8289
Below is an example showing syntax that includes all extensions proposed here (this could apply to either a role or a directive):
8390

8491
```
8592
{name .classname #uniqueid key="value"}`some body markup`
8693
```
8794

88-
8995
## Examples
9096

9197
### Roles
@@ -132,7 +138,7 @@ Each of the above is useful and will continue to be supported. For example, the
132138

133139
## UX implications & migration
134140

135-
The proposed syntax is an addition to existing role and directive patterns. It is a stricly non-breaking enhancement; existing MyST documents that use this syntax are currently considered invalid and should not successfully parse. It does not invalidate or change the behavior of any existing workflows.
141+
The proposed syntax is an addition to existing role and directive patterns. It is a stricly non-breaking enhancement; existing MyST documents that use this syntax are currently considered invalid and should not successfully parse. It does not invalidate or change the behavior of any existing workflows.
136142

137143
The inline attribute syntax adopts the same inline attribute syntax used by Pandoc, Quarto, and djot, with the exception that the inline attribute must start with the role/directive name. This change follows from adapting the reference syntax to MyST Markdown, which already implements extensibilty through nominal types (directives and roles) rather than compositional types (i.e. class names).
138144

@@ -141,29 +147,35 @@ The inline attribute syntax adopts the same inline attribute syntax used by Pand
141147
We considered other approaches in this proposal and in discussion over several years. Including:
142148

143149
1. extending the patterns used in Sphinx internal to the role content (`` {name}`content <argument .class1 key="value">` ``)
144-
2. attributes specified _after_ a role in addition to the name (`` {name}`content`{.class1 key="value"} ``); and
150+
2. attributes specified _after_ a role in addition to the name (``{name}`content`{.class1 key="value"}``); and
145151
3. bracketed spans `[content]{.class}`
146152

147153
We chose the current approach to (a) separate the options and content clearly (i.e. not 1); (b) to keep role names and options close together (i.e. not 2); and \(c) to leave future syntax options open (i.e. 3 is a possible future addition).
148154

149155
### Future Syntax Possibilities
150156

151157
#### Parameterising Other Syntax Constructs
158+
152159
This syntax is a stepping stone to other possible variants or additions to MyST, to be defined in future MEPs. For example, inline attributes for headers (e.g. `## My Header {#id .red}`), block attributes (e.g. preceding a block element with `{#id .red}=` (with or without the `=`), similar to the current `(label)=` syntax), or labelled spans/images/elements (e.g. `[content]{.red}` or `![](image.png){width="300px"}`).
153160

154161
#### Short-hand Boolean Attibutes
162+
155163
In certain markup languages, such as React JSX, it is possible to pass boolean `true` values simply by name, e.g.
164+
156165
```
157166
<FooComponent myProp />
158167
```
168+
159169
where `props.myProp` will be `true`. We might consider extending this syntax such that:
170+
160171
````
161172
```{code .linenos}
162173
Numbered code directive
163174
164175
Another line
165176
```
166177
````
178+
167179
sets the `linenos` option to `true`.
168180

169181
## Questions or Objections Considered
@@ -179,4 +191,3 @@ We drew on prior art for inspiration and alignment, including:
179191
- Pandoc [bracketed spans](https://pandoc.org/MANUAL.html#extension-bracketed_spans)
180192
- MyST Python implementation [myst-parser](https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#attributes)
181193
- https://michelf.ca/projects/php-markdown/extra/
182-

0 commit comments

Comments
 (0)