-
Notifications
You must be signed in to change notification settings - Fork 291
Add YAML frontmatter support to transcripts #5824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This adds a set of behaviors (currently `autoupdate` and `getHidden`) as well as a transcript `type` that allows setting multiple behaviors at once (which can then be overridden). This also adds a `:show` info tag, which can be used to override the default `:hide` that’s enabled by the tutorial type.
929a259 to
cd70a7b
Compare
This makes two additional changes: - Use 5 (instead of 3) `-` for the horizontal rules in docs/branchless.md, because opening with `---` triggers the frontmatter parser (and [cmark](https://hackage.haskell.org/package/cmark-0.6.1) outputs 5 `-` in the output anyway). - The output of .github/ISSUE_TEMPLATE/bug_report.md had previously incorrectly included the frontmatter (interpreting the separators as horizontal rules). Now that frontmatter is removed (although it could alternatively be preserved if we decide to preserve unknown frontmatter contents).
Unfortunately, since the `getHidden` behavior is a function, we can’t represent it in YAML, so it’s not configurable outside of a transcript type (like “tutorial”).
cd70a7b to
8cb361e
Compare
| foo = () | ||
| ``` | ||
|
|
||
| but this should succeed, because the tutorial’s `autoupdate` behavior has been overridden by the explicit `autoupdate` setting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. So order doesn't matter; it's ok that type: tutorial came after autoupdate: false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right – we don’t currently have anything where that would be helpful. If you’re setting an individual value, it either overrides the type or is useless.
I could see a future where there are more overlapping things, and something like type: [tutorial, verbose] would be different from type: [verbose, tutorial] because tutorial and verbose each set different values for some of the same behaviors.
unison-src/transcripts/project-outputs/.github/ISSUE_TEMPLATE/bug_report.output.md
Show resolved
Hide resolved
|
Oh man... Safari threw away my long draft comment when I changed SPA tabs, sad 😞 |
I think I sometimes type 3 hyphens... does it give an okay error message if one does that? Otherwise I can learn to not do that.
I think we probably want to preserve it, in case we're creating markdown output to feed into something else, like a blog? It's not urgent at the moment though.
Yeah this has bitten us before, and I don't remember why it wasn't currently an issue. One idea off the top of my head would be to add an or just redact it when running a transcript, without exposing an explicit option.
I didn't understand what this one refers to? |
It’s only a problem if
Otherwise, it’s fine. If you do hit that particular case (which I’m not sure that docs/branchless.md even does, because I don’t think I had implemented the third condition when I changed that), then that block will just disappear from the output, as the ISSUE_TEMPLATE/bug_report.md case does. Basically, frontmatter never errors – if it’s not valid YAML, we assume it’s markdown; if it is valid YAML, we either process it as transcript settings or discard it (we’re a bit lax – if you have transcript settings mixed with other stuff, we’ll handle the transcript settings and discard the rest).
Yeah, that’s reasonable. I think it’s easy enough to change. We’ll just hold
Yeah, this seems reasonable.
So, in the Haskell, we have a type like data Behaviors = {
autoupdate :: Bool,
getHidden :: ProcessedBlock -> Hidden,
}
Internally, it’s easy to define the And while ---
autoupdate: true
---in the frontmatter, we can’t put ---
getHidden: \stanza -> if type stanza == "unison" then HideOutput else Shown
---and expect anything reasonable to happen. So, maybe |
cd6149d to
4a2fa22
Compare
We now preserve all valid JSON frontmatter (except for `null`), so it can be used for multiple purposes (e.g., a transcript could also be a Jekyll post).
4a2fa22 to
cc5ba67
Compare
I fixed this, and then when merging trunk, I noticed that @ChrisPenner solved the same issue on the MCP side of things, so I unified the two. |
Ah, ok I think I get it. Honestly I don't think we'll find we want to configure the defaults all of these; but if we do, then I think splitting it into three settings would make sense. Auto-hiding the For auto-hiding the And then for auto-hiding tl;dr: I think this is good as-is for now. (: |
| labels: bug | ||
| name: Bug report | ||
| title: '' | ||
| --- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, did it reorder and alphabetize these? I guess that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed that. I don’t know if yaml supports preserving ordering, but I do know that YAML doesn’t allow ordering to be significant. So, while it would be nice to preserve what people wrote, it isn’t allowed to affect the behavior.
Ah, that’s a good point. We could expose a single Footnotes
|
Overview
The frontmatter supports various settings, like
autoupdate(which causes allunisoncode blocks to update the codebase, without needing to do so in aucmblock) andtypewhich is an aggregate setting (e.g.,tutorial, will enableautoupdateand also defaultunisoncode blocks to:hideinstead of:show).This is a step toward #5792.
Implementation notes
This makes a few adjacent changes:
There is now a
:showinfo tag (alongside:hideand:hide-all). This is normally the default (which is why it wasn’t needed before), but nowtype: tutorialin the frontmatter will make:hidethe default forunisoncode blocks.docs/branchless.md has had its leading horizontal rules changed from 3 to 5 hyphens, to avoid triggering the frontmatter parser. 5 hyphens is what cmark outputs anyway, so it’s slightly more consistent, too.
The output of .github/ISSUE_TEMPLATE/bug_report.md had previously incorrectly included the frontmatter (interpreting the separators as horizontal rules). Now, that frontmatter is removed (although it could alternatively be preserved if we decide to preserve unknown frontmatter contents).
Test coverage
There are new transcripts covering various frontmatter settings.
Loose ends
One major loose end: two of the new transcripts cause a CI failure (due to diffing the transcript outputs), because the output includes a path to a temporary directory, which changes on every run. Do we have any way to manage that currently … or any suggestions on how we should?
And one minor loose end: since the
getHiddenbehavior is represented as a function (to be able to change the handling only for certain stanzas), we can’t represent it in YAML. So it’s not configurable directly, but only as part of a transcript type (like “tutorial”).