-
Notifications
You must be signed in to change notification settings - Fork 509
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
(Auto)EmbedLiveSample #3973
(Auto)EmbedLiveSample #3973
Conversation
I'm not sure what this is. That code, which I'm not afraid of, is not something you eat for breakfast. |
Forgot to create this as a draft until I have filled all the details in. It's something I started working on with Ryan and it is needed for the Markdown conversion. Will's comment over here is good context for how it should work: mdn/content#3548 (comment) |
@Gregoor lemme know if there's any specific testing or code reviewing that you want me to look at. |
I could use some help indeed, thanks Peter. The way @escattone and I implemented it is change the EmbedLiveSample rendering to operate on the renderedHTML, which is both more Markdown-proof and allows us to skip parsing and instead just use cheerio to find the embed. Now the problem is that we DO need the source location of the macro for flaws. Which makes me think we need to go back to reading the source and not the rendered HTML. Does anyone see a way around that? |
Haven't forgotten about this @Gregoor, but I don't think I'll get to it until tomorrow. Excited to take a look! |
306aa7f
to
8d2ee63
Compare
@@ -14,7 +14,7 @@ | |||
// | |||
// See also : LiveSampleLink | |||
|
|||
var sampleId = $0; | |||
var sampleId = $0 || $token.location.start.offset; |
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 like how you decided to pass the token
as part of the macro's execution context.
Restrict the live-sample page builds to iframes referencing live-samples on the current page.
Okay from the fact that the amount of passing tests varies, pending on the timeout and that it passes on our local beefy machines, leads me to conclude that our tests are ACCIDENTAL BENCHMARKS. But I am not gonna blame them for being more than they set out to be but will try to rise to the challenge next week and do less slow stuff and see if I can make them pass that way. |
I am going into the timeouting testing hypothesis again after all. I only found one straightforward speed-up, which was using generators. Now I'm going to see if I can even pass one of the failing tests pass with increased timeouts before I build up a whole narrative on that assumption. |
Another way to trigger the crash is:
|
See http://localhost:3000/fr/docs/Learn/CSS/Styling_text/Fundamentals#_flaws
there which we know gets messed up because of the
...to...
(and do the same with the In fact, it's a nice feature we already have in This useful additional error message hint seems to be broken now :( |
Thanks for the digging, Peter!
That I just fixed, I was erroneously using the rendered HTML instead of the document's rawBody. Now that part looks good to me. The ASCII thing I had not an idea about, but I'll focus my remaining time on getting the build command to run through for these translated-docs. So I think I might not get to solving the other thing! |
Alrighty, that one is fixed. The only outstanding one should be the ASCII correction but I won't get to it anymore during my mozilla time. Pardon me! |
What @escattone and I did was that we kinda gave up on the ASCII bugs. We couldn't solve it for various reasons because; reasons. That's why we desperately chickened out and just threw in a slightly more informative error message. <h2 id="ëclair">Heading</h2>
{{EmbedLiveSample('ëclair')}} What do you think Ryan? |
If the macro is "EmbedLiveSample", there are cases when the same call signatures yield different results. For example, when the live-sample ID provided as the first argument can't be found or is not provided at all, the result depends on the macro's location in the document.
@shapkarin deserves most of the credit for this fix
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.
Just so we don't accidentally merge this just because CI is green.
TypeError: Cannot read property 'includes' of undefined
at Node.<anonymous> (/Users/peterbe/dev/MOZILLA/MDN/yari/kumascript/src/live-sample.js:74:49)
at /Users/peterbe/dev/MOZILLA/MDN/yari/node_modules/cheerio/lib/api/traversing.js:588:20
at Array.filter (<anonymous>)
at initialize.exports.filter (/Users/peterbe/dev/MOZILLA/MDN/yari/node_modules/cheerio/lib/api/traversing.js:634:18)
at Object.buildLiveSamplePages (/Users/peterbe/dev/MOZILLA/MDN/yari/kumascript/src/live-sample.js:74:6)
at buildDocument (/Users/peterbe/dev/MOZILLA/MDN/yari/build/index.js:329:38)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async buildDocumentInteractive (/Users/peterbe/dev/MOZILLA/MDN/yari/build/cli.js:50:29)
at async buildDocuments (/Users/peterbe/dev/MOZILLA/MDN/yari/build/cli.js:130:9)
at async Se._action (/Users/peterbe/dev/MOZILLA/MDN/yari/build/cli.js:343:60)
error: Cannot read property 'includes' of undefined
I found another error (after waiting a looooong time):
But note. I was hacking on testing a solution to ASCII-non-escaping and perhaps that broke things for the worse. |
Congrats. It's important improvement. @escattone thanks to adding my code. |
This adds a fallback algorithm to how EmbedLiveSamples gather code to be included inside of the iframe. It is outlined in this issue by Will:
mdn/content#3548 (comment)