File: html_renderer.ex

package info (click to toggle)
elixir-earmark-parser 1.4.44-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,148 kB
  • sloc: makefile: 9
file content (45 lines) | stat: -rw-r--r-- 1,021 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
defmodule EarmarkParser.Ast.Renderer.HtmlRenderer do
  import EarmarkParser.Context, only: [prepend: 2]
  import EarmarkParser.Helpers.HtmlParser
  import EarmarkParser.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
      end

    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
      end

    prepend(context, [tag_ | rest])
  end

  def render_html_comment_line(line) do
    html_comment_start = ~r{\A\s*<!--}
    html_comment_end = ~r{-->.*\z}

    line
    |> String.replace(html_comment_start, "")
    |> String.replace(html_comment_end, "")
  end
end