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
@@ -20,22 +21,26 @@ We propose an extension to the MyST Markdown syntax for roles and directives tha
20
21
21
22
## Context
22
23
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.
24
25
25
26
[^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.
26
27
27
28
## Proposal
28
29
29
30
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
+
```
31
33
{ROLE-NAME}`ROLE-BODY`
32
-
````
34
+
```
35
+
33
36
and
37
+
34
38
````
35
39
```{DIRECTIVE-NAME}
36
40
DIRECTIVE-BODY
37
41
```
38
42
````
43
+
39
44
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:
40
45
41
46
````
@@ -54,16 +59,19 @@ Content of the tip directive.
54
59
Content of the tip directive.
55
60
```
56
61
````
62
+
57
63
where [](#new-syntax-example) is the new inline attribute syntax.
58
64
59
65
### Inline Attribute Syntax
60
66
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
62
70
63
-
In pseudo-grammar, the new inline attribute syntax may be expressed as
64
71
```
65
72
{NAME .CLASS #ID KEY=VALUE}
66
73
```
74
+
67
75
where `NAME`, `.CLASS`, `#ID`, and `KEY=VALUE` are unique types of attribute definitions as follows:
68
76
69
77
`NAME`
@@ -73,19 +81,17 @@ where `NAME`, `.CLASS`, `#ID`, and `KEY=VALUE` are unique types of attribute def
73
81
: 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
74
82
75
83
`#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.
77
85
78
86
`KEY=VALUE`
79
87
: 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.)
80
88
81
-
82
89
Below is an example showing syntax that includes all extensions proposed here (this could apply to either a role or a directive):
83
90
84
91
```
85
92
{name .classname #uniqueid key="value"}`some body markup`
86
93
```
87
94
88
-
89
95
## Examples
90
96
91
97
### Roles
@@ -132,7 +138,7 @@ Each of the above is useful and will continue to be supported. For example, the
132
138
133
139
## UX implications & migration
134
140
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.
136
142
137
143
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).
138
144
@@ -141,29 +147,35 @@ The inline attribute syntax adopts the same inline attribute syntax used by Pand
141
147
We considered other approaches in this proposal and in discussion over several years. Including:
142
148
143
149
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
145
151
3. bracketed spans `[content]{.class}`
146
152
147
153
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).
148
154
149
155
### Future Syntax Possibilities
150
156
151
157
#### Parameterising Other Syntax Constructs
158
+
152
159
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 `{width="300px"}`).
153
160
154
161
#### Short-hand Boolean Attibutes
162
+
155
163
In certain markup languages, such as React JSX, it is possible to pass boolean `true` values simply by name, e.g.
164
+
156
165
```
157
166
<FooComponent myProp />
158
167
```
168
+
159
169
where `props.myProp` will be `true`. We might consider extending this syntax such that:
170
+
160
171
````
161
172
```{code .linenos}
162
173
Numbered code directive
163
174
164
175
Another line
165
176
```
166
177
````
178
+
167
179
sets the `linenos` option to `true`.
168
180
169
181
## Questions or Objections Considered
@@ -179,4 +191,3 @@ We drew on prior art for inspiration and alignment, including:
0 commit comments