This repository was archived by the owner on Nov 8, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 13 files changed +27
-31
lines changed Expand file tree Collapse file tree 13 files changed +27
-31
lines changed Original file line number Diff line number Diff line change 1- defmodule Helper.Metric.Article do
1+ defmodule Helper.Converter.EditorToHTML.Class do
22 @ moduledoc """
33 html article class names parsed from editor.js's json data
44
@@ -9,7 +9,7 @@ defmodule Helper.Metric.Article do
99 @ doc """
1010 get all the class names of the parsed editor.js's html parts
1111 """
12- def class_names ( :html ) do
12+ def article ( ) do
1313 % {
1414 # root wrapper
1515 "viewer" => "article-viewer-wrapper" ,
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ defmodule Helper.Converter.EditorToHTML.Frags.Header do
44
55 see https://editorjs.io/
66 """
7- alias Helper.Metric
87 alias Helper.Types , as: T
98
10- @ class get_in ( Metric.Article . class_names ( :html ) , [ "header" ] )
9+ alias Helper.Converter.EditorToHTML.Class
10+
11+ @ class get_in ( Class . article ( ) , [ "header" ] )
1112
1213 @ spec get ( T . editor_header ( ) ) :: T . html ( )
1314 def get ( % { "eyebrowTitle" => eyebrow_title , "footerTitle" => footer_title } = data ) do
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ defmodule Helper.Converter.EditorToHTML.Frags.List do
44
55 see https://editorjs.io/
66 """
7- alias Helper.Metric
7+ alias Helper.Converter.EditorToHTML.Class
88
9- @ class get_in ( Metric.Article . class_names ( :html ) , [ "list" ] )
9+ @ class get_in ( Class . article ( ) , [ "list" ] )
1010
1111 def get_item ( :checklist , % {
1212 "checked" => checked ,
Original file line number Diff line number Diff line change @@ -9,10 +9,9 @@ defmodule Helper.Converter.EditorToHTML.Header do
99
1010 defmacro __using__ ( _opts ) do
1111 quote do
12- alias Helper.Metric
13- alias Helper.Converter.EditorToHTML.Frags
12+ alias Helper.Converter.EditorToHTML . { Class , Frags }
1413
15- @ class get_in ( Metric.Article . class_names ( :html ) , [ "header" ] )
14+ @ class get_in ( Class . article ( ) , [ "header" ] )
1615
1716 defp parse_block ( % { "type" => "header" , "data" => data } ) do
1817 Frags.Header . get ( data )
Original file line number Diff line number Diff line change @@ -13,16 +13,16 @@ defmodule Helper.Converter.EditorToHTML do
1313 """
1414
1515 use Helper.Converter.EditorToHTML . { Header , Paragraph , List }
16+ alias Helper.Types , as: T
1617
17- alias Helper . { Metric , Utils }
18+ alias Helper.Utils
1819 alias Helper.Converter . { EditorToHTML , HtmlSanitizer }
19- alias EditorToHTML.Validator
20+ alias EditorToHTML . { Class , Validator }
2021
2122 # alias EditorToHTML.Assets.{DelimiterIcons}
23+ @ root_class Class . article ( )
2224
23- @ root_class Metric.Article . class_names ( :html )
24-
25- @ spec to_html ( binary | maybe_improper_list ) :: false | { :ok , << _ :: 64 , _ :: _ * 8 >> }
25+ @ spec to_html ( String . t ( ) ) :: T . ok_html ( )
2626 def to_html ( string ) when is_binary ( string ) do
2727 with { :ok , parsed } = string_to_json ( string ) ,
2828 { :ok , _ } <- Validator . is_valid ( parsed ) do
Original file line number Diff line number Diff line change @@ -9,10 +9,9 @@ defmodule Helper.Converter.EditorToHTML.List do
99
1010 defmacro __using__ ( _opts ) do
1111 quote do
12- alias Helper.Metric
13- alias Helper.Converter.EditorToHTML.Frags
12+ alias Helper.Converter.EditorToHTML . { Class , Frags }
1413
15- # @class get_in(Metric.Article.class_names(:html ), "list")
14+ # @class get_in(Class.article( ), [ "list"] )
1615
1716 defp parse_block ( % { "type" => "list" , "data" => data } ) do
1817 % { "items" => items } = data
Original file line number Diff line number Diff line change @@ -6,8 +6,6 @@ defmodule Helper.Converter.EditorToHTML.Paragraph do
66 """
77 defmacro __using__ ( _opts ) do
88 quote do
9- # alias Helper.Metric
10-
119 defp parse_block ( % { "type" => "paragraph" , "data" => % { "text" => text } } ) do
1210 "<p>#{ text } </p>"
1311 end
Original file line number Diff line number Diff line change @@ -42,4 +42,5 @@ defmodule Helper.Types do
4242 html fragment
4343 """
4444 @ type html :: String . t ( )
45+ @ type ok_html :: { :ok , String . t ( ) }
4546end
Original file line number Diff line number Diff line change @@ -3,11 +3,10 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Header do
33
44 use GroupherServerWeb.ConnCase , async: true
55
6- alias Helper.Metric
76 alias Helper.Converter.EditorToHTML , as: Parser
8- alias Helper.Converter.EditorToHTML.Frags
7+ alias Helper.Converter.EditorToHTML . { Class , Frags }
98
10- @ root_class Metric.Article . class_names ( :html )
9+ @ root_class Class . article ( )
1110
1211 describe "[header block unit]" do
1312 @ editor_json % {
Original file line number Diff line number Diff line change @@ -3,13 +3,13 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do
33
44 use GroupherServerWeb.ConnCase , async: true
55
6- alias Helper.Metric
6+ alias Helper.Converter.EditorToHTML.Class
77 alias Helper.Converter.EditorToHTML , as: Parser
88
99 # "<addr class="cdx-lock">hello</addr> Editor.js <mark class="cdx-marker">workspace</mark>. is an element <script>alert("hello")</script>"
1010
1111 # "text" : "<script>evil scripts</script>"
12- @ root_class Metric.Article . class_names ( :html )
12+ @ root_class Class . article ( )
1313
1414 @ real_editor_data ~S( {
1515 "time" : 1567250876713,
You can’t perform that action at this time.
0 commit comments