Packages
earmark_parser
1.4.10
1.4.46
1.4.45
1.4.44
1.4.43
1.4.42
1.4.41
1.4.40
1.4.39
1.4.38
1.4.37
1.4.36
1.4.35
1.4.34
1.4.33
1.4.32
1.4.31
1.4.30
1.4.29
1.4.28
1.4.27
1.4.26
1.4.25
1.4.24
1.4.23
1.4.22
1.4.21
1.4.20
1.4.20-pre
1.4.19
1.4.18
1.4.17
1.4.16
1.4.16-pre2
1.4.16-pre1
1.4.16-pre
1.4.15
1.4.13
1.4.12
1.4.11
1.4.10
1.4.9
1.4.8
AST parser and generator for Markdown
Current section
Files
Jump to
Current section
Files
lib/earmark_parser/ast/renderer/table_renderer.ex
defmodule EarmarkParser.Ast.Renderer.TableRenderer do
@moduledoc false
alias EarmarkParser.Ast.Inline
alias EarmarkParser.Context
import EarmarkParser.Ast.Emitter
def render_header(header, lnb, aligns, context) do
{th_ast, context1} =
header
|> Enum.zip(aligns)
|> Enum.map_reduce(context, &_render_col(&1, &2, lnb, "th"))
{emit("thead", emit("tr", th_ast)), context1}
end
def render_rows(rows, lnb, aligns, context) do
{rows1, context1} =
rows
|> Enum.zip(Stream.iterate(lnb, &(&1 + 1)))
|> Enum.map_reduce(context, &_render_row(&1, &2, aligns))
{[emit("tbody", rows1)], context1}
end
defp _render_cols(row, lnb, aligns, context, coltype \\ "td") do
row
|> Enum.zip(aligns)
|> Enum.map_reduce(context, &_render_col(&1, &2, lnb, coltype))
end
defp _render_col({col, align}, context, lnb, coltype) do
context1 = Inline.convert(col, lnb, Context.clear_value(context))
{emit(coltype, context1.value |> Enum.reverse, _align_to_style(align)), context1}
end
defp _render_row({row, lnb}, context, aligns) do
{ast, context1} = _render_cols(row, lnb, aligns, context)
{emit("tr", ast), context1}
end
defp _align_to_style(align)
defp _align_to_style(:left), do: [{"style", "text-align: left;"}]
defp _align_to_style(:right), do: [{"style", "text-align: right;"}]
defp _align_to_style(:center), do: [{"style", "text-align: center;"}]
defp _align_to_style(_), do: []
end