← All series

Series contents

Log in to track your progress

  1. 1. Welcome to Alchemist Camp Episode
  2. 2. Lesson 1: The guessing game Episode
  3. 3. Solution 1: The Greeter Episode
  4. 4. Lesson 2: Word Count Episode
  5. 5. Word Count ULTIMATE EDITION! Episode
  6. 6. Minimal Todo List Part 1 Episode
  7. 7. Elixir lists vs Elixir tuples Article
  8. 8. The Image Snatcher Episode
  9. 9. Minimal Todo List Part 2 Episode
  10. 10. Elixir maps made effortless Article
  11. 11. Fibonacci with tail recursion Episode
  12. 12. Mini Markdown Episode
  13. 13. Extending Mini Markdown Episode
  14. 14. Alchemy Markdown Episode
  15. 15. Using mix to modularize and add tests Episode
  16. 16. Command line applications with escript Episode
  17. 17. Caboose, a simple Unix tail clone Episode
  18. 18. Game board (Tictac Part 1) Episode
  19. 19. Structs: Maps with checks and default values Article
  20. 20. Deck generation, Pythagorean Triplets and more Episode
  21. 21. Whiteboarding the Tictac state machine Episode
  22. 22. Game state machine (Tictac Part 2) Episode
  23. 23. Modelling the memory game Episode
  24. 24. Finishing Tictac and making a CLI Episode
  25. 25. Threatened by rooks, bishops and knights Episode
  26. 26. A worker to log stats from a YouTube’s API Episode
  27. 27. Constructing bitmap files with Elixir Episode
  28. 28. Making bitmaps with color palettes Episode
  29. 29. Flattening lists recursively in Elixir Episode

Alchemy Markdown

It's time to learn how to use mix! Mix is the Elixir equivalent of npm/yarn, pip or gem and it plays a fundamental role in dependency management, automated testing, OTP application management and scripting.

Last episode we worked on a minimal (and incomplete) implementation of Markdown. Now we're going to use mix to pull in Earmark, a Markdown implementation. Interestingly, its author is Dave Thomas, who wrote the excellent guide Programming Elixir.

Here's a breakdown of this episode:

  • Choosing Earmark - (1:44)
  • Getting started with mix - (3:10)
  • A first look at testing - (5:37)
  • The mix file and adding deps - (8:47)
  • Using Earmark and adding functionality & unit tests - (12:00)
  • Reviewing unit tests and migrating integration test from last time - (31:07)
  • Discovering Earmark is a dash-eater (plus workaround) - (37:30)

The markdown features implemented are:

  • All the standard ones implemented by Earmark (thank you Dave and thank you Mix!)
  • <big></big> tags, by placing ++ before and after a string of text.
  • <small></small> tags by placing -- before and after a string of text.
  • <hr/> tags by making a line start with three or more - or * characters with any number of spaces between them.

All of these features as well as those from MiniMarkdown are unit tested using the standard mix test.

Open standalone page ↗

3 Comments

My -- turns into ΓÇô on windows powershell. I tried <<45>> with no luck. So my tests fail with left: "<p>\nSome ΓÇôsmallΓÇô words!</p>\n" right: "<small>small</small> words"

When I use git bash I get: left: "<p>\nSome –small– words!</p>\n" right: "<small>small</small> words"

- jifem · 5 years ago

If you use three ` in a row, you can do GFM-style comments here!

- alchemist · 5 years ago

Another way to regex for hrs :

def hrs(text) do
    Regex.replace(~r/(\r\n|\r|\n|^)([*-])\s*(\2\s*){2,}/, text, "\\1<hr />")
end
- jtoulouse · 5 years ago