Markdown UI
January 15, 2021·8 minute readBut coming from Notion, I miss some nice features like kanban views, calendars, or tables. Something that doesn't come out of the box in the Markdown spec.
Goal
In this post, I want to explore and experiment with the possibilities of using this approach to render more rich components to show plain text, like the one required to model a simple interactive table.
To understand the project vision you can check the conceptual lifecycle of the information in the followin diagram:
First step: Parsing
To be able to validate the idea and achieve the minimum viable product, we will take the easiest example to play with. We are going to build an interactive markdown table. All values in this table will be floats. This is an example of the content:
Field
. Then, a list of floats separated by commas will form the rows of the
table, in this case, called Record
. Then a File
will be a list of Record
separated by break lines:Once we have a nice grammar definition, we can use it to build the parser. Pest is going to build all the utility modules to be able to parse the incoming data to abstract syntax tree nodes.
Enum
's to be able to differentiate the
parsed tokens.On the other hand, it will also generate a parser to build the correct tree of nodes:
test.csv
as input, we are going to get:Second step: Render
Serialize
and
Deserialize
traits to our structures.parse
function that can be called
from Javascript world:JsValue
's with a representation of our Field
and
Record
structures. Those objects will be used to render a nice and
interactive UI build on top of React.Third step: Interaction
Now that we are able to render the parsed content, we can continue adding a bit of interactivity to the view. You can imagine whatever nice use case for your widget. From adding buttons, drag and drop, calendars, etc.
For demo purposes, we are going to add just a button to add new rows to the table.
This button will modify the internal state of Javascript objects that represents those records and the UI will react accordingly. As an example, we are going to as to the user a new row of float numbers to be added to the table:
Fourth step: Serialization
store
function and expose it to wasm_bindgen
:Then, we call this new function from React passing as argument all rows in the table from the state:
And we get the final goal of new Markdown 🎉 for this dynamic table component:
Conclusion
We went through all the steps required to parse arbitrary data to feed a reactive UI and close the cycle back to text. As we said, the possibilities of this approach for markdown documentation or more rich second brains are endless.
To see a working demo widget, check the widget below:
Markdown UI - Table
✨ Check this out 👇
This textarea is interactive. Change the markdown value or add rows to React table. They are in sync
Markdown
React
In a next post we are going to implement an interactive kanban board with tasks following the same strategy as this one. Stay tuned!
Thanks for reading me and to all people that helped me to polish this article!
Happy hacking!