Skip to content

Diagnose a language word followed by {attrs} on a code fence (Q-2-57) - #825

Draft
gordonwoodhull wants to merge 2 commits into
mainfrom
feature/bd-iv9zxs5y-word-attrs-fence-diagnostic
Draft

gordonwoodhull wants to merge 2 commits into
mainfrom
feature/bd-iv9zxs5y-word-attrs-fence-diagnostic

Conversation

@gordonwoodhull

@gordonwoodhull gordonwoodhull commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

A fenced code block like

```python {.marimo}
code
```

used to fail with an uncoded "Parse error … unexpected character or token here" pointing at the space after python. The grammar accepts either a single language word or one braced attribute list on the opening line, not both, but nothing said so. Pandoc does accept the combined form, so people write it.

It now reports Q-2-57 ("I didn't expect this after the code block's language.") with a hint built from the author's own attribute list, in the accepted order of identifier, then classes, then key-value pairs, with the language word folded in:

Error: [Q-2-57] Attribute List After Code Block Language
   ╭─[ t.qmd:6:11 ]
   │
 6 │ ```python {.marimo}
   │    ───┬── ────┬────
   │       ╰────────────── This is the code block's language. The opening line takes either one language word or one attribute list in braces, not both.
   │               │
   │               ╰────── I didn't expect this after the code block's language.
───╯
ℹ Put the language inside the braces: `{.python .marimo}` for a code block, or `{python .marimo}` for an executable cell.

1 error

The first form is a plain code block with the language as its first class. The second is an executable cell. Both python {…} and python{…} are covered.

The hint is only offered when a braced list follows the word. python .marimo, a list with two identifiers, and language names with punctuation (c++) keep the generic error.

The suggester reuses the attribute-order machinery from Q-2-55/56 (shared classification and ordering helpers, plus a new language-with-attributes suggester). The error is reported over the braced list, the text that wasn't expected, rather than the single character where the parser gave up; a suggester can now return a range along with its hint. The grammar is unchanged. Adds the Q-2-57 docs page and catalog entry.

A fence like ```python {.marimo} failed with an uncoded parse error. The
grammar takes one language word or one braced attribute list on the
opening line, not both. It now reports Q-2-57 with a hint built from the
author's own list in the accepted order, with the language folded in:
`{#id .python .cls key=val}` for a code block, or
`{python #id .cls key=val}` for an executable cell.

The hint is offered only when a braced list follows the word; a braceless
list, two identifiers, or a word with punctuation keep the generic error.
The new language-with-attributes suggester reuses the attribute-order
helpers from Q-2-55/56.
@posit-snyk-bot

posit-snyk-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

A suggester can now return a source range along with its hint. The
language-with-attributes suggester returns the braced list, the text the
parser did not expect, instead of the single character where it failed.
@gordonwoodhull
gordonwoodhull marked this pull request as draft October 13, 2026 17:59
@gordonwoodhull

Copy link
Copy Markdown
Member Author

Converting this to a draft. The Q-2-57 diagnostic itself works as intended. The question I want to settle first is what the hint should say about the executable-cell form.

The hint offers {python #id .cls key=val} as the cell form. In main, Q-2-36 rejects that shape when the only class is the language word and there are key-values ({python key=val} and {python #id key=val} are errors; {python .a key=val} passes only because of the extra class). So today the hint can suggest a header that a different diagnostic then rejects.

Separately, Q-2-36 started in January as a warning (Q-2-8) and became a hard error in #197. In Q1, {python echo=false} runs in Jupyter with the option ignored. In q2 it is an error.

That merits further discussion before this lands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants