Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit6fa994c

Browse files
author
mydearxym
committed
refactor(editor-parser): add block parser for checklist plugin
1 parentc0cd28f commit6fa994c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

‎lib/helper/rich_text_parser.ex‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ defmodule Helper.RichTextParser do
6363
"<ol>#{content}</ol>"
6464
end
6565

66+
# IO.inspect(items, label: "checklist items")
67+
# TODO: add item class
68+
defpparse_block(%{"type"=>"checklist","data"=>%{"items"=>items}})do
69+
content=
70+
Enum.reduce(items,"",fnitem,acc->
71+
text=Map.get(item,"text")
72+
checked=Map.get(item,"checked")
73+
74+
casecheckeddo
75+
true->
76+
acc<>"<div><input type=\"checkbox\" checked />#{text}</div>"
77+
78+
false->
79+
acc<>"<div><input type=\"checkbox\" />#{text}</div>"
80+
end
81+
end)
82+
83+
"<div class=\"#{@html_class_prefix}-checklist\">#{content}</div>"
84+
# |> IO.inspect(label: "jjj")
85+
end
86+
6687
defpparse_block(%{"type"=>"delimiter"})do
6788
"<div class=\"#{@html_class_prefix}-delimiter\" />"
6889
end

‎test/helper/rich_text_parser_test.exs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ defmodule GroupherServer.Test.Helper.RichTextParserTest do
6464
"level" : 3
6565
}
6666
},
67+
{
68+
"type" : "checklist",
69+
"data" : {
70+
"items" : [
71+
{
72+
"text" : "This is a block-styled editor",
73+
"checked" : true
74+
},
75+
{
76+
"text" : "Clean output data",
77+
"checked" : false
78+
},
79+
{
80+
"text" : "Simple and powerful API",
81+
"checked" : true
82+
}
83+
]
84+
}
85+
},
6786
{
6887
"type" : "paragraph",
6988
"data" : {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp