Weeknotes 46
15th May, 2022
“Appease the linter”
-
If you want to write tests for rendered HTML you might find it tricky to assert against the text because the tags will get in the way.
To workaround this you can extract the text using Nokogiri like so:
[1] pry(main)> html = "<b>I'm bold</b>" => "<b>I'm bold</b>" [2] pry(main)> Nokogiri::HTML(html).text => "I'm bold"
-
File under "…so preoccupied with whether they could, they didn’t stop to think if they should"
‹div class="[&*: nth-child(2)]: text-red-500 [&>*[data-potato]]:italic">
I flip-flop about Tailwind often, but I’m really not sure about this.
-
“The
download
attribute in HTML at a glance” – Never heard of this, looks handy, and browser support is very good. Do I even computer? -
I wrote recently about discovering NanoIDs. This week I was introduced to HashIDs, which are similar but can be decoded back to their source integer.
Hashids is a small open-source library that generates short, unique, non-sequential ids from numbers.
It converts numbers like 347 into strings like “yr8”, or array of numbers like [27, 986] into “3kTMd”.
You can also decode those ids back. This is useful in bundling several parameters into one or simply using them as short UIDs.
-
GitHub’s “Authorize Slack” button in their settings page doesn’t do anything in Safari. Click, nothing. Good times. Works in Chrome though doesn’t it…
-
I prototyped a quick way to render a linked table of contents for Markdown files this week. I used Redcarpet because it ranked high in my Google search 😉
You need to pass the
HTML_TOC
renderer when rendering.renderer = Redcarpet::Render::HTML_TOC.new(nesting_level: 2..5) Redcarpet::Markdown.new(renderer).render(<markdown>)
This will output a link for each header in the document, letting you link directly to them. Handily, you can tell Redcarpet to only take into account Markdown headers of a certain range. For example, this ignores
<h1>
s but outputs all the others. -
The side project is progressing now, by which I mean “procrastinating by reading about JavaScript animations” instead of doing what actually needs to be done.
-
Run the linter. Consider the linter. But, please, do not appease the linter. It’s a computer, and is often wrong.