The Level Journal

Stories about building my startup.

Page 2

How to display server-rendered HTML in Elm 0.19

I’m building a team communication product called Level, and one of the core features is rendering posts as Markdown.

Elm has a library to handle this on the client-side. It’s a wrapper around the marked.js library that uses Kernel code call out to JavaScript land. (It appears the plan is to implement a native Markdown rendered in Elm eventually).

This library works great for doing basic Markdown rendering without additional decoration but is a bit limited if you need to do things like traverse the rendered HTML to inject special styles, or perform additional sanitization of user input.

To my knowledge, there’s not an API to traverse and modify DOM trees in Elm. It might be possible to accomplish these things on the client-side with enough JavaScript hackery, but that admittedly makes me a bit squeamish.

Before upgrading to 0.19, there was a hack for taking some server-rendered HTML...

Continue reading →

JavaScript raises my blood pressure

This morning I worked on fleshing out pagination on various pages that need it (viewing posts in a group, your “pings,” and the unified activity stream). I had previously punted on implementing it, but it’s definitely a requirement for the MVP. This was also an excellent opportunity to refactor some of the routing logic in Elm.

I ended up extracting a Pagination module that takes a Connection of nodes and renders the prev/next buttons. This is one area where Elm really shines. After all, everything – including HTML definitions – is just function.

In the afternoon, I turned my attention toward something that feels like an area of risk: Markdown rendering. When I upgraded to Elm 0.19, I switched to using elm-markdown to render post and reply bodies. The old hack I was using to inject server-rendered HTML into a <div> node was eliminated (for a good reason), so I took a crack at using the...

Continue reading →

Why Svbtle?

I hatched the idea for this journal the other day while pondering ways to keep engaged with folks as I spend many long days slinging code (showerideas).

On a whim, I decided to poll the audience to see if folks would be interested in these updates and the results were affirming:

The next step was to choose where to publish these posts. If you know me personally, this will come as no surprise: I tend to be a bit of a perfectionist, especially when it comes to design. Combine that with the typical software developer hazard of wanting to implement stuff by hand, this little project could have easily...

Continue reading →

Refactoring Elm

I started the day wrapping up some refactoring work that I began last week. The purpose of the refactor was to streamline the routing in the Elm SPA (single-page application), which was made possible by some of the new goodies that shipped in Elm 0.19.

I debated whether it was worth sinking a few days into upgrading to 0.19 at this stage of the project, but decided it was better to pay the time penalty now than push it out into the future and risk never getting around to it.

Some highlights from the refactor:

✔️ Converted several separate Elm programs to pages in the SPA
✔️ Eliminated the need for a hard page refresh to switch between spaces
✔️ Changed from fragment-based routing to path-based routing
✔️ Reorganized how websocket events propagate through the SPA
✔️ Extracted helper functions to cut down repetition in Main.elm

The highest risk with a refactor like this is scope...

Continue reading →