TIL: extracting Elixir module and function hyperlinks from Markdown

TIL: extracting Elixir module and function hyperlinks from Markdown

03 March, 2025 3 min read
Markdown, Elixir, grep, regex, book

While reviewing and polishing Northwind Elixir Traders (my book on modeling and working with SQLite databases with Elixir and Ecto) on its way to 100% completion, I decided to hyperlink all mentions to functions and modules of Elixir, Ecto, Ecto.SQL and Ecto SQLite3 in the Markdown source of the book to the corresponding Elixir documentation page. This makes it easier for the reader to access documentation and look up each module or each function’s head and any of its available options, both for understanding what is happening in the code snippets we run in IEx and in the code blocks of the NorthwindElixirTraders Elixir application we develop step by step throughout the book.

As the review progressed, I found myself copying and pasting more of the same chunks of text from earlier part of the text that had already referred to a function. It became a hassle to lose my position in a text file by Ctrl-f-ing a function name, then select and copy the chunk of the hyperlinked function name, and then get back to where I was earlier, to paste it there.

The following command extracts all those hyperlinks from the Markdown files. I keep its output open in a text editor, so that I can copy the hyperlinked module or function references into the Northwind Elixir Traders text while reviewing without losing track of where I am:

grep -hoP '\[`([A-Z][A-Za-z0-9_.]*)?(?:[a-z_]+)?\/?\d?`\]\((?!#)[^)]*\)' *.md | sort | uniq

This also matches hyperlinks to SQLite functions on sqlite.org . For the record, as I’m currently in the middle of reviewing Chapter 15 on more and more-advanced queries with windows, window functions, window aggregates and partitioning, these are the modules and functions used thus far in the book: