Packages

Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as a command-line tool (run mix escript.build first). Output generation is pluggable.

Retired package: Deprecated - Earmark is no longer maintained. Migrate to a replacement, for example MDEx (https://hex.pm/packages/mdex).
Security advisory: This version has known vulnerabilities. View advisories

Current section

Files

Jump to
earmark lib earmark_parser ast renderer html_renderer.ex
Raw

lib/earmark_parser/ast/renderer/html_renderer.ex

defmodule Earmark.Parser.Ast.Renderer.HtmlRenderer do
import Earmark.Parser.Context, only: [prepend: 2]
import Earmark.Parser.Helpers.HtmlParser
import Earmark.Parser.Helpers.AstHelpers, only: [annotate: 2]
@moduledoc false
# Structural Renderer for html blocks
def render_html_block(lines, context, annotation)
def render_html_block(lines, context, annotation) do
[tag] = parse_html(lines)
tag_ = if annotation, do: annotate(tag, annotation), else: tag
prepend(context, tag_)
end
def render_html_oneline([line|_], context, annotation \\ []) do
[tag|rest] = parse_html([line])
tag_ = if annotation, do: annotate(tag, annotation), else: tag
prepend(context, [tag_|rest])
end
@html_comment_start ~r{\A\s*<!--}
@html_comment_end ~r{-->.*\z}
def render_html_comment_line(line) do
line
|> String.replace(@html_comment_start, "")
|> String.replace(@html_comment_end, "")
end
end