The recently updated AppRun Docs Site has made the code snippets in the documents runnable and editable, making the technical documentation interactive and much more fun to use.
The site is built with Material for MkDocs, a beautiful and powerful tool for building technical documentation site. We extended it by adding a web component built with AppRun to deliver the interactive experiences.
In this post, I Will explain how it's made. Let's start with reviewing the user experience.
Technical documents usually have code snippets. Often the code has syntax highlighted for easy reading. However, users usually can only see screenshots but not live results of the code. Screenshots have limitations. For example, when describing how to make animation, a static screenshot is not helpful. We need a way to display the live code execution results.
You can visit the AppRun Docs Page to see a live animation.
Furthermore, users might have been inspired by the code examples and want to try different ideas. Traditionally, they could copy and paste the code to run it in their code editors. It would be nice for users to edit the code right on the doc site and see the results.
You can click the "Try the Code" button of the AppRun Docs Page. It opens the AppRun Playground with an editor and preview pane to play the code.
The user experiences have much improved with the capabilities of seeing the code results and trying the code in technical documents.
Not only is it much more attractive to the readers, but also the authors will feel it much more enjoyable when writing the documents.
Traditionally, authors copy and paste the code snippets from their testing projects into the markdown documents as code blocks. The limitation is that they can only present the code but not the running code. Sometimes, it would be hard to describe the code behaviour. For example, describing a calculator could need a long text, but it could be easier to present the calculator for users to click.
You can visit the AppRun Docs Page to see a running calculator.
All we need to do is to add a web component, called apprun-play under the code blocks.
``js // code snippets `` <apprun-play></apprun-play>
You probably have noticed that the page shows only the results but not the source code. It is because we can control whether to show the source code. We can also decide whether to see the "Try the Code" button.
``js // code snippets `` <apprun-play hide_src="true" hide_button="true"></apprun-play>
You can visit the AppRun Docs Page to see an example of only displaying the running results.
We can present the code snippets, but we can also embed whole applications because the apprun-play web component supports HTML.
<textarea> --8<-- "real-world.html" </textarea> <apprun-play style="height:350px" hide_src="true" hide_button="true"></apprun-play>
When it displays the code result automatically means that it is automatic testing of the code, which tells the author if the code works as expected.
Also, while writing, the authors can come up with new ideas. With apprun-play web component, they can edit the code and see the live results. Once it's done, they can copy and paste the code back into the document.
Overall, the apprun-play web component is a helpful tool for the document author.
Web components/custom elements are safe in the markdown documents. We can build web components out of the AppRun Components quickly.
The apprun-play web component is an AppRun component that gets the source code from its previous sibling element, a textarea, or a div with highlighted code. Then, the apprun-play web component creates an iframe for the code.
Then, you can add it to the configuration file of Material for MkDocs, mkdocs.yml
That's it. The apprun-play web component is ready for use in all the markdown documents.
Finally, the AppRun Docs Site Github project is: https://github.com/apprunjs/apprun-docs/
Please enjoy and send pull requests.
Note: the cover image is a water colour painting I painted from the one by my favourite English painter, John Yardley.