Replies: 1 comment 7 replies
-
|
to clarify your goal is to write something that executes the code AND displays it as a "standard" markdown code block... e.g. ```js [some-id]
const foo = 'bar';
```should result in something like this (simplified) <script type="module">
const foo = 'bar';
</script>
<code><pre>
const foo = 'bar';
</pre></code> |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Use case
Often I need to show the setup code to the users, because it's important for the demos underneath.
This setup code doesn't contain demos, just some JS or CSS which needs to be executed, without any direct visuals, so I want to avoid rendering it in a story wrapper.
I also reason about this in the following manner:
js preview-story)js story)js script)js, just standard Markdown)Examples
Show and execute setup JS code, e.g. how to register custom elements in preparation for the demos below with code.
Live: https://backlight.dev/edit/xS11aQmjMLIvr5PU5Mru/flipper/doc/flipper.md?p=doc
I have to duplicate the setup code in
js scriptand in thejscode block.Show and render setup CSS code, e.g. classes which I then use in the demos underneath, so users need to read this CSS code first to understand the follow-up demos code.
Live: https://backlight.dev/edit/4BeMe20hqOWTkdUL2NuJ/box/doc/box.md?branch=feature-request-show-setup-code%4044v7XI9EE5hzBwU7oxi8dbGjKz03&p=doc
I use a workaround here not to duplicate the code, but I had to add a paragraph to invite to read it, although I want to just show the code block immediately without this fancy wrapper around it and not hide it behind a button-click.
Proposals
All proposal are also applicable to
htmlcode blocks, but I'm usingjs smthfor readability.js preview-scriptGiven
js preview-storydiffers fromjs storyin the fact that it does show the code.We can make
js preview-scriptto differ fromjs scriptin the same way.Important remark: such block can return smth to render (not really a story though) or can just be some JS to execute.
Pros:
Cons:
html preview-scriptreads weird, because it's not really a script 🤷js scriptis not designed for rendering, while this feature assumes rendering is needed (not always, but if the store is returned), just without extra UI wrapperExample 1 with this proposal:
js preview-scriptExample 2 with this proposal:
html preview-scriptjs story no-ui,js story no-ui no-renderNot a big fan of this, but just sharing for completeness.
The idea is to control if the story UI wrapper is shown and if the code needs to be rendered in the DOM.
Cons:
js storyis not designed forjs scripttojs setup, add newjs preview-setupfor executable JS blocks andjs/html preview-render-setupfor rendered blocksThis combines best of previous two and takes into account their limitations.
js scriptcan be left for backwards compatibility, but I think it's good to rename it given it's kinda the same thing semantically.But you can also argue it's unrelated, and that makes it just a few new ones.
Example 1 with this proposal:
js preview-setupExample 2 with this proposal (given version with both js and html for clarity)
js preview-render-setuphtml preview-render-setupGlad to discuss other proposals, certainly there is space for better API ideas.
Beta Was this translation helpful? Give feedback.
All reactions