diff --git a/.changeset/healthy-kangaroos-applaud.md b/.changeset/healthy-kangaroos-applaud.md new file mode 100644 index 000000000..7121b4ce2 --- /dev/null +++ b/.changeset/healthy-kangaroos-applaud.md @@ -0,0 +1,5 @@ +--- +"markdown-it-myst": patch +--- + +Add inline options diff --git a/.changeset/pink-birds-join.md b/.changeset/pink-birds-join.md new file mode 100644 index 000000000..e39481903 --- /dev/null +++ b/.changeset/pink-birds-join.md @@ -0,0 +1,6 @@ +--- +"myst-directives": patch +"myst-transforms": patch +--- + +Move QMD admonition recognition to a transform diff --git a/.changeset/small-paws-suffer.md b/.changeset/small-paws-suffer.md new file mode 100644 index 000000000..db61233a3 --- /dev/null +++ b/.changeset/small-paws-suffer.md @@ -0,0 +1,5 @@ +--- +"myst-directives": patch +--- + +div node does not require a body diff --git a/.changeset/tough-terms-push.md b/.changeset/tough-terms-push.md new file mode 100644 index 000000000..0786edf6e --- /dev/null +++ b/.changeset/tough-terms-push.md @@ -0,0 +1,5 @@ +--- +"myst-roles": patch +--- + +Introduce a span role diff --git a/docs/inline-options.md b/docs/inline-options.md new file mode 100644 index 000000000..57cb374b0 --- /dev/null +++ b/docs/inline-options.md @@ -0,0 +1,54 @@ +--- +title: Inline Options +subtitle: Concise specification of CSS classes, IDs, and attributes +description: MyST Markdown has support for inline attributes for both roles and directives, allowing concise specification of CSS classes, IDs, and attributes. This complements other methods for defining options, making markup more expressive and flexible. +# thumbnail: thumbnails/inline-options.png +--- + +:::{warning} Inline Options are in Beta +The support for inline attributes is in beta and may have some bugs or limitations. +Please give feedback on [GitHub](https://github.com/orgs/jupyter-book/discussions). +::: + +MyST Markdown has support for inline attributes for both roles and directives, allowing concise specification of CSS classes, IDs, and attributes. This complements other methods for defining options, making markup more expressive and flexible. + +```markdown +:::{tip .dropdown open="true"} Title +Tip Content +::: +``` + +This can also be used for roles: + +`` {span .text-red-500}`Red text` `` + +{span .text-red-500}`Red text` + +## Syntax Overview + +The inline attribute syntax follows this pattern: + +````text +{role #id .class key="value" key=value}`content` + +```{directive #id .class key="value" key=value} +content +``` +```` + +Name (e.g. `tip` or `cite:p`) +: The directive or role name must come first. There must only be a single "bare" token. + +ID (`#id`) +: Defines the label/identifier of the node + +Class (`.class`) +: Adds CSS class(es). + +Quoted Attributes (`key="value"`) +: Supports attributes containing spaces or special characters. + +Unquoted Attributes (`key=value` or `key=123`) +: Allows simpler attribute values when there are no spaces. + +For directives, these can be mixed with other ways to define options on directives, classes are combined in a single space-separated string; other repeated directive options will raise a duplicate option warning. diff --git a/docs/myst.yml b/docs/myst.yml index 36d397c9d..250106d2d 100644 --- a/docs/myst.yml +++ b/docs/myst.yml @@ -101,6 +101,7 @@ project: - file: glossaries-and-terms.md - file: writing-in-latex.md - file: table-of-contents.md + - file: inline-options.md - title: Executable Content children: - file: notebooks-with-markdown.md diff --git a/docs/syntax-overview.md b/docs/syntax-overview.md index 401939c3d..44f9109c1 100644 --- a/docs/syntax-overview.md +++ b/docs/syntax-overview.md @@ -63,7 +63,7 @@ My directive content. 2\) **directive options** - a collection of flags or key/value pairs that come just underneath `{directivename}`. -There are two ways to write directive options, as `:key: value` or as a YAML block. +There are three ways to write directive options: as `:key: value`, as a YAML block, or directly inline. ``````{tab-set} `````{tab-item} Key value pairs @@ -89,6 +89,14 @@ key1: metadata1 key2: metadata2 --- +My directive content. +``` +```` +````` +`````{tab-item} Inline Options +Options can be included inline. See [](./inline-options.md) for more information. +````markdown +```{directivename .class-name #label key="value"} My directive content. ``` ```` @@ -117,6 +125,12 @@ Roles are defined inline, with an identifier and input. There are a number of ro Here is an {abc}`unknown role`. ``` +Options for roles can be included inline. See [](./inline-options.md) for more information. + +```markdown +Here is my {span #label .class-name key="value"}`custom span`. +``` + (nesting-content)= ## Nesting content blocks in Markdown diff --git a/packages/markdown-it-myst/src/directives.ts b/packages/markdown-it-myst/src/directives.ts index e5477adfe..01abf8362 100644 --- a/packages/markdown-it-myst/src/directives.ts +++ b/packages/markdown-it-myst/src/directives.ts @@ -5,6 +5,7 @@ import type MarkdownIt from 'markdown-it/lib'; import type StateCore from 'markdown-it/lib/rules_core/state_core.js'; import { nestedPartToTokens } from './nestedParse.js'; import { stateError, stateWarn } from './utils.js'; +import { inlineOptionsToTokens } from './inlineAttributes.js'; const COLON_OPTION_REGEX = /^:(?