Syntax coloring of markdown rendered to HTML by Earmark

In a LiveView module, I use Earmark to convert markdown to HTML. In my markdown, I have Elixir code snippets. I’m wondering how I might apply syntax coloring to the snippets. Does anyone know how this might be done? Thanks

GitHub - tmbb/makedown: Markdown implementation for Elixir using Makeup by @tmbb

Thanks for the reference. It looks promising, but unfortunately it’s not working for me yet. I’m not sure that I’m doing everything necessary. Here’s what I’ve done so far:

{:makedown, "~> 0.2.1"}

and replaced all of:

Earmark.as_html

with:

Makedown.as_html

then run:

mix deps.get

Then when I start my server, I gets lots of warnings and a compilation error (see below).

There were some other instructions regarding ExDoc but it looks like they were optional. I’ll keep poking around to see if I can see what the problem is. Please let me know if you have any suggestions.

Thanks

% mix phx.server
warning: variable "description" does not exist and is being expanded to "description()", please use parentheses to remove the ambiguity or change the variable name
  /Users/charlesirvine/src/i_kno/deps/html_entities/mix.exs:11: HtmlEntities.Mixfile.project/0

warning: variable "package" does not exist and is being expanded to "package()", please use parentheses to remove the ambiguity or change the variable name
  /Users/charlesirvine/src/i_kno/deps/html_entities/mix.exs:12: HtmlEntities.Mixfile.project/0

warning: variable "deps" does not exist and is being expanded to "deps()", please use parentheses to remove the ambiguity or change the variable name
  /Users/charlesirvine/src/i_kno/deps/html_entities/mix.exs:13: HtmlEntities.Mixfile.project/0

==> html_entities
Compiling 2 files (.ex)
warning: the /r modifier in regular expressions is deprecated, please use /U instead
  (elixir 1.14.2) lib/regex.ex:874: Regex.translate_options/2
  (elixir 1.14.2) lib/regex.ex:196: Regex.compile/3
  (elixir 1.14.2) lib/regex.ex:229: Regex.compile!/2
  (elixir 1.14.2) lib/kernel.ex:6002: Kernel."MACRO-sigil_r"/3
  (elixir 1.14.2) src/elixir_dispatch.erl:224: :elixir_dispatch.expand_macro_fun/7
  (elixir 1.14.2) src/elixir_dispatch.erl:187: :elixir_dispatch.do_expand_import/7

warning: String.rstrip/1 is deprecated. Use String.trim_trailing/1 instead
  lib/html_entities/util.ex:24: HtmlEntities.Util.add_entity_to_list/2

Generated html_entities app
==> ex_const
Compiling 1 file (.ex)
Generated ex_const app
==> exconstructor
Compiling 1 file (.ex)
Generated exconstructor app
==> ex_spirit
Compiling 5 files (.ex)
Generated ex_spirit app
==> makeup
Compiling 44 files (.ex)
warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/rrt.ex:30: Makeup.Styles.HTML.RrtStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/vs.ex:35: Makeup.Styles.HTML.VisualStudioStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/xcode.ex:41: Makeup.Styles.HTML.XcodeStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/perldoc.ex:54: Makeup.Styles.HTML.PerldocStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/paraiso-light.ex:55: Makeup.Styles.HTML.ParaisoLightStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/rainbow_dash.ex:57: Makeup.Styles.HTML.RainbowDashStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/trac.ex:52: Makeup.Styles.HTML.TracStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/pastie.ex:62: Makeup.Styles.HTML.PastieStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/vim.ex:47: Makeup.Styles.HTML.VimStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/tango.ex:88: Makeup.Styles.HTML.TangoStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/samba.ex:88: Makeup.Styles.HTML.SambaStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/paraiso-dark.ex:55: Makeup.Styles.HTML.ParaisoDarkStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/native.ex:52: Makeup.Styles.HTML.NativeStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/murphy.ex:69: Makeup.Styles.HTML.MurphyStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/monokai.ex:47: Makeup.Styles.HTML.MonokaiStyle.style/0

warning: the @style_struct() notation (with parenthesis) is deprecated, please use @style_struct (without parenthesis) instead
  lib/makeup/styles/html/pygments/manni.ex:61: Makeup.Styles.HTML.ManniStyle.style/0

warning: EEx.compile_string/2 defined in application :eex is used by the current application but the current application does not depend on :eex. To fix this, you must do one of:

  1. If :eex is part of Erlang/Elixir, you must include it under :extra_applications inside "def application" in your mix.exs

  2. If :eex is a dependency, make sure it is listed under "def deps" in your mix.exs

  3. In case you don't want to add a requirement to :eex, you may optionally skip this warning by adding [xref: [exclude: [EEx]]] to your "def project" in mix.exs

Invalid call found at 2 locations:
  lib/makeup/formatters/html/html_formatter.ex:5: Makeup.Formatters.HTML.HTMLFormatter
  lib/makeup/styles/html.ex:40: Makeup.Styles.HTML.Style

warning: EEx.function_from_string/4 defined in application :eex is used by the current application but the current application does not depend on :eex. To fix this, you must do one of:

  1. If :eex is part of Erlang/Elixir, you must include it under :extra_applications inside "def application" in your mix.exs

  2. If :eex is a dependency, make sure it is listed under "def deps" in your mix.exs

  3. In case you don't want to add a requirement to :eex, you may optionally skip this warning by adding [xref: [exclude: [EEx]]] to your "def project" in mix.exs

Invalid call found at 2 locations:
  lib/makeup/formatters/html/html_formatter.ex:5: Makeup.Formatters.HTML.HTMLFormatter
  lib/makeup/styles/html.ex:40: Makeup.Styles.HTML.Style

Generated makeup app
==> makedown
Compiling 3 files (.ex)

== Compilation error in file lib/makedown.ex ==
** (CompileError) lib/makedown.ex:15: Earmark.Block.Code.__struct__/0 is undefined, cannot expand struct Earmark.Block.Code. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code
    expanding struct: Earmark.Block.Code.__struct__/0
    lib/makedown.ex:15: Makedown.code_renderer/1
could not compile dependency :makedown, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile makedown", update it with "mix deps.update makedown" or clean it with "mix deps.clean makedown"