-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
feat: interactive examples #5330
Conversation
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #5330 +/- ##
============================================
- Coverage 76.47% 43.37% -33.11%
============================================
Files 160 23 -137
Lines 14014 5130 -8884
Branches 820 23 -797
============================================
- Hits 10717 2225 -8492
+ Misses 3118 2904 -214
+ Partials 179 1 -178
Flags with carried forward coverage won't be shown. Click here to find out more. |
The build fails, but the error does not seem to be related to my changes in any way: git clone --single-branch https://github.com/mermaid-js/mermaid-live-editor.git
cd mermaid-live-editor
npm install
Tried to build
|
@sidharthv96 any comments? |
@nalgeon, I don't see any major blockers, will try it out locally once I get 10.9.0 out. A bit busy with that now. |
@sidharthv96 10.9.0 is out, so could you please take a look at this PR? |
I wish you had told me this before I spent a full day preparing the PR. I opened issue #5311 with a Mermaid demo specifically for this purpose, so you can decide if the suggested approach fits your project or not. |
Ctrl/Cmd + Enter and a run button is added. The feature was first implemented in #5330. This is a simplified version without introducing additional dependencies. Co-authored-by: Anton <m@antonz.org>
Ctrl/Cmd + Enter and a run button is added. The feature was first implemented in #5330. This is a simplified version without introducing additional dependencies. Co-authored-by: Anton <m@antonz.org>
Ctrl/Cmd + Enter and a run button is added. The feature was first implemented in #5330. This is a simplified version without introducing additional dependencies. Co-authored-by: Anton <m@antonz.org>
The idea of having interactive documentation was really great. I had pointed out in #5311 (comment) itself that we need the examples to run without clicking a button. It was only after you raised this PR that I could see the actual implementation, and the complexity it would add. But, as the idea was great, I tried to see how much work it would be to add the same feature without a dependency. I hope you understand the rationale behind the decision. |
📑 Summary
I've converted static code examples to interactive.
Resolves #5311
📏 Design Decisions
The output is hidden by default, until the reader runs an example. This is intentional. My observations show that hiding the output provides a better reader experience for two reasons:
The page has less content and is perceived as easier to read, increasing the chances that people will actually read it.
Interacting with the article by clicking Run to see the results provides a small sense of accomplishment. This increases reader engagement.
If you want the output to be be shown by default, I can do that. But please try it yourself — maybe you'll see the benefits I'm talking about.
Regarding live reload (automatic rendering as people type). I've tried mermaid.live and found it quite confusing. As I change the code, the diagram specification is often invalid, so live reload shows lots of errors.
I think it's better to reload the diagram only when the reader explicitly asks for it. It's still easy to do this with the
Ctrl+Enter
(Cmd+Enter
) shortcut while editing the code. I've added a note about this shortcut in the bottom right corner of the editor.