This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Settle a specification for "examples" structures #54
base: master
Are you sure you want to change the base?
Settle a specification for "examples" structures #54
Changes from 3 commits
5de9000
8991a36
ed7c117
f0a30fd
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Why?
Wait, hold on. Let me make sure I understand the distinctions between examples here:
It's not clear to me what distinction is being made between descriptive and static. It's also not clear to me what makes interactive examples a special case.
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.
Yes.
Well yes this is a bit tenuous. The only point I was trying to make is that examples don't have to contain actual example code. But I could remove it as a separate category and just say that instead.
Well... interactive examples are specified very differently[1], they live in a different bit of the MDN page, currently there should only be one in the page, and there are quite specific rules for the content they should contain, which is different from other examples.
It might be better to include them in here anyway, but it seemed more natural to list them separately.
[1] this might change: I don't very much like the way the interactive examples editor and sources are completely separate from MDN. We explored using CodePen as the editor for Web API examples, and in that case the examples would start to appear much more like "live samples" from the authoring point of view. But that work has stalled, and I don't know when if ever we will look at it again.
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.
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.
Not in this proposal, no, because you can have examples that are not live (have no output iframe) but that still want to present blocks of code, and they are expected to use separate example.* files for those blocks of code. In this doc these are called static examples.
The reason for that is the desire to treat code as code, whether it's executable in an iframe or not - so e.g. for linting it seems more convenient to separate the code from the descriptive text[1]. And also perhaps it's good to present static and live samples in a consistent way.
But perhaps these are not very strong reasons, and we should change this proposal to say: "if you want a live sample, use separate example.* files. If you just want a static example just use fenced code blocks in your description.md".
Writing this document is an attempt to get clarity on questions such as this :).
[1] Of course there will still exist code blocks embedded in Markdown, in other sections of the documentation (for example).
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.
It would be nice to be able to type
../shared-examples/some-example
since it's something you'd just expect to work.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.
This is a bit convoluted. As an author, I'd prefer something like, "title is always required" with the understanding that not all consumers will use all titles all the time (e.g., render titles if and only if there is more than one example) or "title is always optional" with the understanding that a title will be generated if not provided (e.g., "Example 2").
As written, if there are three examples for an item and I want to write a fourth, then I have to look at three files to find out whether I need to specify a title or not (or wait on the linter to complain, I guess). That's not great.
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.
I agree with Daniel. It got complex. Perhaps, in the renderer we can simply be smarter about turning them into IDs because that's what sparked a lot of this discussion. Ie. tack on '-2' if a title is not distinct.
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.
It's not really about IDs. It's about providing options to authors and deciding which options are worth the complexity.
As I say, this would make people invent titles when they naturally wouldn't, in cases like
<b>
for example.This will prevent us from supporting cases like
<bdi>
where the author (me in this case :) wanted to use multiple live samples, but didn't want titles, because they should flow together.These rules are the result of me looking through a bunch of pages to understand how people currently use the examples systems in MDN, and then making some choices about which usages we should continue to support in the future. I'm of course happy to change these choices but we ought to understand which usages we are excluding by doing so.
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.
Now that is interesting! It seems to me it'd be very nice to represent that as a single unit that happens to contain a few successive examples internally.
Maybe we could be slightly clever and embed the code in Markdown fenced code blocks and use the info string to alert our tooling to which is the example and what's just an ordinary code block:
(imagine that I'm not fighting the Markdown parser here):
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.
I don't understand this, can you elaborate? In the
<bdi>
case, I do want to render all three sections as separate live samples. I just don't want headings.Perhaps it might be better, as you imply, to allow authors to create a single "example" that can contain multiple "live samples" - that is to break the 1-1 relationship between abstract things called examples and concrete live sample code blocks+iframes. But that might be hard to express and to understand, for the sake of a rather niche usage.
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.
I tried making a Markdown example of your original
<bdi>
example. Take a look here: https://gist.github.com/ddbeck/39d348b2561593955be4051fb8a1b72aThe idea here is that you'd capture the simple case—some explanatory text and some snippets of HTML, CSS, and JavaScript—in a single Markdown file. But it also works for the niche usage of successive, related examples.
For authors, this is pretty tidy. No requirement for an extra directory, since everything is contained in a Markdown file. Because we're using expected annotations on code fences, it plays nicely with GitHub and editor syntax highlighting. And if you want successive, closely-related examples (as in
<bdi>
) then you can have a single unit for authoring.This is good for consumers too. In the case of
<bdi>
, the successive examples are really one single illustration of the tag taken together. If we had to break these up in Stumptown, then consumers would need to treat the full set of examples as a single unit. In my proposed formulation, any one example stands alone. This would let us do some interesting things with examples, too, like a code sample gallery, filterable by tag.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.
Thank you for the details!
Then it sounds as if in this proposal we're not (ever?) having separate source files for examples. Instead we have a single Markdown file (or presumably a single section in prose.md) that embeds fenced code blocks, with extra directives to tell stumptown/the renderer when the code blocks should be treated as live samples.
What's the operation of stumptown here? Is it something like:
when you parse Examples, check every code block for a code block containing the "I'm a live sample" directive. If you find it, keep looking for code blocks containing the directive, until you find something else (like a
<p>
, say, or a code block that doesn't contain the directive.then all the code blocks you found constitute a single live sample. The result iframe containing those code blocks is to be embedded immediately after the last code block found
if any of the code blocks don't also have the "show me" directive, don't include the code block in the rendered output.
Is that about right? I think if we were going to do this we should make things more explicit, and make the "I'm a live sample" directive embed an ID for the particular live sample, instead of relying on the order we encounter things.
and
What is the JSON output like in this case? I guess it must be structured, to have separate items for the descriptions and the example sources, as it is now, and the build-json takes care of slicing the Markdown into the bits.
What about headings? Are they just supplied by the author now in the overall Markdown, and stumptown/the renderer don't represent any titles or add any headings? It's hard to see in this model how the renderer could insert headings, because it doesn't really know the heading context in the place it's adding the result iframe (I mean, the author could have
H2 Examples
/H3 Multiple audio tracks
, then the example, or just haveH2 Examples
). Or is stumptown/the renderer supposed to keep track of the outline so it can create headings of the appropriate level? That seems quite complicated.I'm not very happy about having authors supply headings for these things, as we get inconsistency: "JS" and "JavaScript", "Result" and "Output", different orders, headings sometimes present and sometimes not, and so on. This is the kind of mess that stumptown is supposed to help with.
Well... when I write live samples, I always write them as web pages first, because they have to work. It's only after I've got them working properly as web pages that I copy all the pieces into the Wiki.
So as an author I quite like the explicitness of separate source files for examples - when those examples are supposed to be executable instead of just illustrative.
But this is a thing we can and I hope will experiment with :).
Then it sounds like you're saying that this bdi example is represented as a single example in the stumptown JSON. What would the data structures look like? I assume it wouldn't be a single blob of HTML, or would it?
In general I feel like this approach is much closer to the old Wiki way of "write a big blob of content with some directives embedded in it" so I'd probably need some convincing that it is a better approach, especially if it is only really intended to solve a relatively niche case that has other possible solutions.
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.
First, I appreciate this is long and getting a big digressive. Should we take this to a separate issue along the lines of "Expressing examples in Markdown"? I don't want to hold up the whole PR over this tangent from whether or not examples must have a title.
We could still have separate source files. Maybe some examples require fifty lines of (hidden) JS or something to work—in that case it might be cumbersome to have that code in a Markdown file. I was trying to capture the (hopefully simple and common) case of "here are ten lines of code that I want to show to the reader and also render in an iframe".
No, I'm -1 on this. I still think it's a good idea to separate the examples from other prose. Examples are special: they will contain potentially executable code and will have lots of special considerations above and beyond ordinary prose because of that.
Yeah, pretty much how you described it. Though now that I've had it described back to me I'd probably tweak this or that to strengthen the defaults. For example, I'd probably show code blocks by default and use a flag to hide them and I'd probably rely on a
type
in the front matter to make all the code in the example live, unless a code block is explicitly suppressed (i.e., we could rely on the language identifier itself instead of anexample-body
flag). We're writing in the examples directory, so it should probably require special intention to get something other than a real live example.Yep, that's a reasonable idea. As a matter of style, I'd want to disallow blocks of non-consecutive IDs (e.g., no putting parts of example 1 after example 2), but I'm OK with making the relationship between blocks explicit, when there's more than one.
I thought it'd be mostly like what we're building now (I assume that we'd have slight variations for our different example types): some metadata about the example (e.g. title, size info if relevant, etc.) and a blob of HTML (containing the Markdown and example code converted to a single unit of HTML). I stuffed the iframe sources into data URIs to avoid dealing with multiple files in the final Markdown output, but I don't know if that's a terrible idea.
Again, I think it's good to separate this stuff from the prose. For any example , I'd expect there would be a title in the front matter that becomes that example's
title
attribute (in thedescription
object) and we wouldn't use a top-level heading in the Markdown content. In a case like<bdi>
, we never even used a heading internal to the example (I think it wouldn't be outrageous to ban headings in examples outright). If we did want to allow headings in example Markdown, we could impose some sort of style that would be tractable for consumers to modify automatically (e.g., we'll only ever give you<h3>
s).That's fair. Admittedly, my proposal only really works if previewing stumptown content is pretty easy (eventually we'll want a tool that provides a more human-readable view of stumptown content as parsed by our tooling). It's definitely not easy yet, but that's a whole separate issue.
I get this. And that's where getting the subtleties around default behavior right will make a big difference (e.g., writing code in an example file in an examples directory should lead to a rendered example, rather than having to explicitly flag code to be rendered). But I also think that things which are closely related ought to be close together—if structuring content requires us to grind it to bits then immediately glue them back together with a configuration file, then we need to rethink the content or the structure or both.
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.
Well this PR is (perhaps unwisely :) called "Settle a specification" so this is in scope. However I think it's very hard to get to a conclusion remotely on issues like this.
Currently the JSON output is something like:
As I understand it, in this proposal the source blocks live inline in the description, and are also duplicated as explicit
sources
so the renderer can initialize the iframe. And then I guess in thebdi
case, there are three examples, with three separate prose blocks, that are split according to slightly subtle implicit rules:Is that basically right? So in the
bdi
case we are still modelling this as three examples?It feels like part of the difference between this proposal and the original is about how explicit we want to be at communicating structure. In this proposal it's a lot more implicit: writers write something that looks like free flowing prose, and the tools reveal a structure in that.
Another part of the difference is how much control authors have over the way examples look in the rendered page. In the current proposal, the renderer could easily build live samples that look a lot like interactive examples, or like embedded CodePens, but in this proposal it feels more like each author controls how the text and code blocks will appear in the rendered page.
I think this has pros and cons: being too restrictive for authors could be annoying, but means we can make the pages more consistent (for example, in BCD authors have no control on how a compat table will look, and this is a good thing for everyone). I'm not sure yet where the balance ought to be here.
Well... we pretty much have to have it in bits in order to make live samples out of it. Currently in KumaScript we grind it into bits so we can do this. The main difference I can see here is that in the current proposal the writer supplies it in bits, and in this proposal the writer supplies it in a more unitary way and the JSON builder does more dismembering.
As I said before: I think it's really hard to get to a conclusion on questions like this when you have to do it all asynchronously and in writing. (again, it's very unfortunate you couldn't be with us last week).
This is especially true because we haven't tested the specification on a lot of pages or with real writers. Maybe there will be lots of cases where we need the extra flexibility of this approach, or writers will hate the shackles of the current one (and prefer less visible shackles :).
So unless I've missed something important here, I think I'd like to suggest we keep what we have for now and reconsider it (1) the next time we can discuss it face to face and (2) if any concrete experience suggests that the current proposal is not going to work very well.
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.
OK, a few last words in this topic then. First the actual issue here, then the meta stuff:
Ah, maybe this is we're getting a bit sidetracked. I did not mean for an example-in-Markdown to produce more than one example-in-JSON (the way
prose.md
produces multiple sections); I meant that an example-in-Markdown stood for one and only one example-in-JSON.It was my sense that the bdi example was, semantically, one example that happens to contain three separate chunks of code internally. If you split the bdi example in three, the first two parts aren't independently meaningful (they don't even contain the
<bdi>
tag). I figured that if we could solve the problem of representing an indivisible sequence like bdi, then we'd also answer the question of whether titles should be required or optional (plus get ourselves some nice authoring bonuses).And titles are what provoked this thread, after all. To speak directly to that issue: I still think we should require titles for all examples. If we're not solving this sequence-of-examples problem, then I'd prefer to push the challenge of deciding whether to show titles onto the renderer rather than putting the burden on authors. That said, this is not the hill I'm going to die on. If we're sticking with the original rule, then let the record show I didn't like it. 😄
Meta stuff: yes, sorry about the length of this discussion. I wish I had a good guideline for "this async discussion is going on too long, we should just have a call to sort it out quickly." Also, yes, I share your dissatisfaction with not getting to join you last week—in fact, I'm more agitated about it this week than I was last week (last week I was in the dark, but this week I'm in the dark with consequences).
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.
I interpret this as "setting a width or height declares this example to be live". That seems kinda cryptic. Sufficiently cryptic to answer the question of "Should we have an explicit indicator for 'I'm a live example'?"
I'd much rather have a front matter field to make this type intent explicit:
type: live
ortype: static
ortype: interactive
and then the linter can provide more helpful error messages ("This static example should not have a width value").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.
Actually, I can't imagine authoring an iframe with anything but "full fluid width". Like with textareas, they're almost always block displays and the width is as much as possible but the "rows" is a very interesting thing to be able to control.
In other words, switch to 'type: interactive' to determine if the renderer should use an iframe. And make the 'height' optional and say that the default height depends on the renderer's discretion.
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.
Agree on width but I'm not sure height should be optional. The renderer has no idea what would be a good height for a particular example, the author does. The height is optional in EmbedLiveSample, and as a result many examples don't fit properly. As an author I pretty much always give a height to EmbedLiveSample, because I care about how my example will look.
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.
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.
It could mention that they're all optional. Right?
But what if none of them are present?
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.
That's already mentioned just above: https://github.com/wbamberg/stumptown-experiment/blob/document-structures/docs/structures/examples.md#example-syntax
If it's a live example, that's an error. We could say that.
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.
Can we avoid the word "stumptown" here?
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.
If we're going to write this up, that's fine, I understand why we're doing it. But I do like making the split between stumptown and consumers explicit. With that in mind, I'd characterize this as "rendering suggestions"
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.
You've already written it now but I think the documentation would be easier to maintain and easier to write if we stay away from saying too much about rendering. It would also send a nice signal that the content is just the content.