Skip to content

Commit

Permalink
Merge pull request #9 from estermer/es/underline
Browse files Browse the repository at this point in the history
UNDERLINE
  • Loading branch information
buob authored Feb 13, 2020
2 parents 346c877 + 9fb50c1 commit 5cc0fe4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/draft.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Draft do
|> Map.get("blocks")
|> Enum.reduce([], &group_list_items/2)
|> Enum.map(&process_block(&1, entity_map, context))
|> Enum.join("\n")
|> Enum.join("")
end

@doc """
Expand Down
4 changes: 2 additions & 2 deletions lib/draft/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ defmodule Draft.Block do
entity_map,
context
) do
"<ul>#{Enum.map(children, &process_block(&1, entity_map, context)) |> Enum.join("\n")}</ul>"
"<ul>#{Enum.map(children, &process_block(&1, entity_map, context)) |> Enum.join("")}</ul>"
end

def process_block(
%{"type" => "ordered-list", "data" => %{"children" => children}},
entity_map,
context
) do
"<ol>#{Enum.map(children, &process_block(&1, entity_map, context)) |> Enum.join("\n")}</ol>"
"<ol>#{Enum.map(children, &process_block(&1, entity_map, context)) |> Enum.join("")}</ol>"
end

def process_block(
Expand Down
6 changes: 5 additions & 1 deletion lib/draft/ranges.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Draft.Ranges do
|> Enum.map(fn style -> process_style(style, context) end)
|> Enum.join(" ")

"<span \n style=\"#{css}\">#{text}</span>"
"<span style=\"#{css}\">#{text}</span>"

!is_nil(key) ->
process_entity(entity_map |> Map.get(Integer.to_string(key)), text, context)
Expand All @@ -39,6 +39,10 @@ defmodule Draft.Ranges do
"font-style: italic;"
end

def process_style("UNDERLINE", _) do
"text-decoration: underline;"
end

def process_entity(
%{"type" => "LINK", "mutability" => "MUTABLE", "data" => %{"url" => url}},
text,
Expand Down
15 changes: 9 additions & 6 deletions test/draft_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ defmodule DraftTest do
"text" => "Hello World!",
"inlineStyleRanges" => [
%{"style" => "ITALIC", "offset" => 8, "length" => 3},
%{"style" => "BOLD", "offset" => 2, "length" => 2}
%{"style" => "BOLD", "offset" => 2, "length" => 2},
%{"style" => "UNDERLINE", "offset" => 4, "length" => 4}
],
"type" => "unstyled",
"depth" => 0,
Expand All @@ -222,7 +223,7 @@ defmodule DraftTest do
}

output =
"<p>He<span style=\"font-weight: bold;\">ll</span>o Wo<span style=\"font-style: italic;\">rld</span>!</p>"
"<p>He<span style=\"font-weight: bold;\">ll</span><span style=\"text-decoration: underline;\">o Wo</span><span style=\"font-style: italic;\">rld</span>!</p>"

assert to_html(input) == output
end
Expand Down Expand Up @@ -354,7 +355,7 @@ defmodule DraftTest do
]
}

output = "<ol><li>one</li></ol>"
output = "<ol><li style=\"mso-special-format:numbullet;\">one</li></ol>"
assert to_html(input) == output
end

Expand All @@ -374,7 +375,7 @@ defmodule DraftTest do
]
}

output = "<ul><li>one</li></ul>"
output = "<ul><li style=\"mso-special-format:bullet;\">one</li></ul>"
assert to_html(input) == output
end

Expand Down Expand Up @@ -403,7 +404,9 @@ defmodule DraftTest do
]
}

output = "<ul><li>one</li><li>two</li></ul>"
output =
"<ul><li style=\"mso-special-format:bullet;\">one</li><li style=\"mso-special-format:bullet;\">two</li></ul>"

assert to_html(input) == output
end

Expand Down Expand Up @@ -460,7 +463,7 @@ defmodule DraftTest do
}

output =
"<ul><li>one</li></ul><ol><li>whoops</li></ol><ul><li>two</li></ul><p>Hello</p><ol><li>and another</li></ol>"
"<ul><li style=\"mso-special-format:bullet;\">one</li></ul><ol><li style=\"mso-special-format:numbullet;\">whoops</li></ol><ul><li style=\"mso-special-format:bullet;\">two</li></ul><p>Hello</p><ol><li style=\"mso-special-format:numbullet;\">and another</li></ol>"

assert to_html(input) == output
end
Expand Down

0 comments on commit 5cc0fe4

Please sign in to comment.