-
Notifications
You must be signed in to change notification settings - Fork 503
-
Notifications
You must be signed in to change notification settings - Fork 503
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
[kumascript] Display error on invalid Live Sample #6577
Comments
I think this is a good idea. For your "better solution", we could run it as a CI check in mdn/content - we already do this for various things like uncompressed image files. One issue is that technically the ID argument is now optional in live samples, although there are some unresolved issues with this (#5005, #5006) so it's not widely used. But we could at least validate the places where the ID argument is used. @OnkarRuikar , you've done a lot of stuff in this area lately, wdyt? |
The issue mentioned in OP is no longer valid because, now if the id is not found then the live sample generator goes one level up and collects all css, html, and js code blocks. There other issues related to the macro. To be on the same page here are some issues: ## Example 1
### HTML
```html
<h1>one</h1>
```
Works fine shows "one".
{{EmbedLiveSample('Old title', '100', '100')}}
---------------------------------------------------------------------
## Examples 2
```html
<h1>2</h1>
```
This shows "2" but "two" is ignored
{{EmbedLiveSample('b', '100', '100')}}
### HTML
```html
<h1>two</h1>
```
---------------------------------------------------------------------
## Examples 3
### Html
```html
<h1>three</h1>
```
This shows "one".
{{EmbedLiveSample('html', '100', '100')}}
---------------------------------------------------------------------
## Example 4
```js
let let a = 3;
```
Logs syntax error in user's browser.
{{EmbedLiveSample('Example 4', '100', '100')}}
To reproduce the issues, paste this entire section in a content page.
For contributors using
How about we add flaw cheeking for these issues? ID checking can be done in the macros. And for syntax errors we can have dedicated flaw checker in mdn/yari/tree/main/build/flaws |
Seems also fine to me 👍 (although I'm not experienced with the codebase / processes) |
@karlhorky I believe the original issue has been fixed by #2490/#3973/#4940 and potentially other PRs, so I'm marking this issue as not planned (aka "can't repro"). @OnkarRuikar Feel free to open an issue for the edge cases you may have found, even though we would really only act if it impacts content/translated-content. I had a quick look, but didn't see what's wrong. FYI The algorithm for extracting the live samples can be found here, if you would like to dig: yari/kumascript/src/api/util.js Lines 280 to 320 in 6d493e4
yari/kumascript/src/api/util.js Lines 120 to 140 in 6d493e4
|
Summary
Originally reported in mdn/kumascript#1214, which was just recently closed by @schalkneethling
Hi there! First of all, thanks for all of the work that is done as part of MDN and the Learn Web Development documentation. It is an invaluable resource for developers of all skill levels.
Live samples can be invalidated if the matching id does not exist (see @SphinxKnight's tweet):
As mentioned in my tweet, it would be awesome if an error was displayed when an invalid live sample was saved:
One solution proposed by @SphinxKnight was to edit macros/EmbedLiveSample.ejs and macros/LiveSampleURL.ejs:
Although not completely preventing these errors from happening, this would at least be a step in the right direction.
Better, more complex solution: Validate live samples as they are saved and do not allow saving an invalid document state.
Although, as Julien G mentioned:
URL
https://developer.mozilla.org/en-US/docs/Learn
Reproduction steps
Expected behavior
Some notice should be displayed during authorship / usage of the website
Actual behavior
It's broken without any notice to the author or user
Device
Other (specify below)
Browser
Other (specify below)
Browser version
Other version (specify below)
Operating system
Other (specify below)
Screenshot
No response
Anything else?
Not browser or operating-system specific
Validations
The text was updated successfully, but these errors were encountered: