@@ -5,7 +5,7 @@ defmodule Helper.Converter.MdToEditor do
5
5
see https://editorjs.io/
6
6
"""
7
7
8
- @ supported_header [ "h1" , "h2" , "h3" ]
8
+ @ supported_header [ "h1" , "h2" , "h3" , "h4" , "h5" , "h6" ]
9
9
10
10
@ spec parse ( binary | [ any ] ) :: any
11
11
def parse ( mdstring ) do
@@ -22,12 +22,12 @@ defmodule Helper.Converter.MdToEditor do
22
22
editor_blocks
23
23
end
24
24
25
- #TODO: parse h4-6 as h3
25
+ #parse markdown header to editor's header
26
26
defp parse_block ( { type , _opt , content } )
27
27
when type in @ supported_header do
28
28
content_text =
29
29
Enum . reduce ( content , [ ] , fn content_item , acc ->
30
- parsed = parse_content ( type , content_item )
30
+ parsed = parse_inline ( type , content_item )
31
31
acc ++ parsed
32
32
end )
33
33
@@ -45,10 +45,11 @@ defmodule Helper.Converter.MdToEditor do
45
45
}
46
46
end
47
47
48
+ # parse markdown paragraph to editor's paragraph
48
49
defp parse_block ( { "p" , _opt , content } ) do
49
50
content_text =
50
51
Enum . reduce ( content , [ ] , fn content_item , acc ->
51
- parsed = parse_content ( "p" , content_item )
52
+ parsed = parse_inline ( "p" , content_item )
52
53
acc ++ parsed
53
54
end )
54
55
@@ -67,25 +68,25 @@ defmodule Helper.Converter.MdToEditor do
67
68
end
68
69
69
70
# 字符串直接返回,作为 editor.js 中的 text/data/code 等字段
70
- defp parse_content ( content ) when is_binary ( content ) do
71
+ defp parse_inline ( content ) when is_binary ( content ) do
71
72
content
72
73
end
73
74
74
75
# TODO: editor.js 暂时不支持 del 标签,所以直接返回字符串内容即可
75
- defp parse_content ( { "del" , [ ] , [ content ] } ) do
76
+ defp parse_inline ( { "del" , [ ] , [ content ] } ) do
76
77
content
77
78
end
78
79
79
- defp parse_content ( _type , content ) when is_binary ( content ) do
80
+ defp parse_inline ( _type , content ) when is_binary ( content ) do
80
81
content
81
82
end
82
83
83
- defp parse_content ( type , { _type , _opt , [ content ] } )
84
+ defp parse_inline ( type , { _type , _opt , [ content ] } )
84
85
when type in @ supported_header do
85
- parse_content ( content )
86
+ parse_inline ( content )
86
87
end
87
88
88
- # defpparse_content ({type, _opt, content})
89
+ # defpparse_inline ({type, _opt, content})
89
90
# when type == "h1" or type == "h2" or type == "h3" do
90
91
# content
91
92
# end