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.

Commit76e2ff1

Browse files
author
mydearxym
committed
refactor: 💡 converter
rename paser and related tests to converter namespace
1 parent8b7fda4 commit76e2ff1

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed

‎lib/helper/rich_text_parser.ex‎renamed to ‎lib/helper/converter/editor_to_html.ex‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
defmoduleHelper.RichTextParserdo
1+
defmoduleHelper.Converter.EditorToHtmldo
22
@moduledoc"""
3-
parse editor.js's jsonformat to raw html andmore
3+
parse editor.js's jsondata to raw html andsanitize it
44
55
see https://editorjs.io/
66
"""
7-
aliasHelper.Sanitizer
7+
aliasHelper.Converter.HtmlSanitizer
88

99
@html_class_prefix"cps-viewer"
1010

11+
@specconvert_to_html(binary)::binary
1112
defconvert_to_html(string)whenis_binary(string)do
1213
with{:ok,parsed}=string_to_json(string),
1314
true<-valid_editor_data?(parsed)do
1415
content=
1516
Enum.reduce(parsed["blocks"],"",fnblock,acc->
16-
clean_html=block|>parse_block|>Sanitizer.sanitize()
17+
clean_html=block|>parse_block|>HtmlSanitizer.sanitize()
1718
acc<>clean_html
1819
end)
1920

2021
"<div class=\"#{@html_class_prefix}\">#{content}<div>"
21-
|>IO.inspect(label:"hello")
22+
#|> IO.inspect(label: "hello")
2223
end
2324
end
2425

‎lib/helper/converter/editor_to_md.ex‎

Whitespace-only changes.

‎lib/helper/sanitizer.ex‎renamed to ‎lib/helper/converter/html_sanitizer.ex‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmoduleHelper.Sanitizerdo
1+
defmoduleHelper.Converter.HtmlSanitizerdo
22
@moduledoc"""
33
Sanitizer user input from editor.js or other
44
content contains html tags
@@ -26,9 +26,9 @@ defmodule Helper.Sanitizer do
2626
Meta.allow_tag_with_these_attributes("h1",["class"])
2727
Meta.allow_tag_with_these_attributes("h2",["class"])
2828
Meta.allow_tag_with_these_attributes("h3",["class"])
29-
Meta.allow_tag_with_these_attributes("h4",["class"])
30-
Meta.allow_tag_with_these_attributes("h5",["class"])
31-
Meta.allow_tag_with_these_attributes("h6",["class"])
29+
#Meta.allow_tag_with_these_attributes("h4", ["class"])
30+
#Meta.allow_tag_with_these_attributes("h5", ["class"])
31+
#Meta.allow_tag_with_these_attributes("h6", ["class"])
3232
Meta.allow_tag_with_these_attributes("p",["class"])
3333
Meta.allow_tag_with_these_attributes("img",["class","src"])
3434
Meta.allow_tag_with_these_attributes("div",["class"])

‎lib/helper/converter/md_to_editor.ex‎

Whitespace-only changes.

‎test/groupher_server_web/controller/og_test.exs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule GroupherServerWeb.Test.Controller.OG do
2424
assertMap.has_key?(image,"url")
2525
end
2626

27-
@tag:wip2
27+
@tag:wip
2828
test"should return valid structure & error msg when query domain is not exsit"do
2929
conn=build_conn()
3030

@@ -52,7 +52,7 @@ defmodule GroupherServerWeb.Test.Controller.OG do
5252
assertMap.has_key?(image,"url")
5353
end
5454

55-
@tag:wip2
55+
@tag:wip
5656
test"return empty valid structure when url not follow open-graph"do
5757
conn=build_conn()
5858

‎test/helper/rich_text_parser_test.exs‎renamed to ‎test/helper/converter/editor_to_html_test.exs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
defmoduleGroupherServer.Test.Helper.RichTextParserTestdo
1+
defmoduleGroupherServer.Test.Helper.Converter.EditorToHtmldo
22
@moduledocfalse
33

44
useGroupherServerWeb.ConnCase,async:true
55

6-
aliasHelper.RichTextParser,as:Parser
6+
aliasHelper.Converter.EditorToHtml,as:Parser
77

88
@real_editor_data~S({
99
"time" : 1567250876713,

‎test/helper/sanitizer_test.exs‎renamed to ‎test/helper/converter/html_sanitizer_test.exs‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
defmoduleGroupherServer.Test.Helper.Sanitizerdo
1+
defmoduleGroupherServer.Test.Helper.Converter.HtmlSanitizerdo
22
@moduledocfalse
33

44
useGroupherServerWeb.ConnCase,async:true
55

66
aliasHelper.RichTextParser,as:Parser
7-
aliasHelper.Sanitizer
7+
aliasHelper.Converter.HtmlSanitizer,as:Sanitizer
88

99
describe"[snaitizer test]"do
10-
test"should strip p h1-6 etc tags"do
11-
html="<p>hello</p><h1>1</h1><h2>2</h2><h3>3</h3><h4>4</h4><h5>5</h5><h6>6</h6>world"
10+
@tag:wip2
11+
test"should strip p h4-6 etc tags"do
12+
html=
13+
"<form>hello</form><h4>1</h4><h5>2</h5><h6>3</h6><h4>4</h4><h5>5</h5><h6>6</h6><h1>world</h1><h2>world2</h2><h3>world3</h3>"
1214

13-
assertSanitizer.sanitize(html)=="hello123456world"
15+
assertSanitizer.sanitize(html)=="hello123456<h1>world</h1><h2>world2</h2><h3>world3</h3>"
1416
end
1517

1618
test"disallow ftp urls"do
@@ -27,23 +29,24 @@ defmodule GroupherServer.Test.Helper.Sanitizer do
2729
"This is <a href=\"http://coderplanets.com/post/1\" name=\"name\" title=\"title\">cps</a>"
2830
end
2931

32+
@tag:wip2
3033
test"allow mark tag with class attr"do
31-
html="This <p>is</p> <mark class=\"cool-look\" other=\"other\">mark text</mark>"
34+
html="This <form>is</form> <mark class=\"cool-look\" other=\"other\">mark text</mark>"
3235
assertSanitizer.sanitize(html)=="This is <mark class=\"cool-look\">mark text</mark>"
3336
end
3437

3538
test"allow code tag with class attr"do
36-
html="This <p>is</p> <code class=\"cool-look\" other=\"other\">code string</code>"
39+
html="This <form>is</form> <code class=\"cool-look\" other=\"other\">code string</code>"
3740
assertSanitizer.sanitize(html)=="This is <code class=\"cool-look\">code string</code>"
3841
end
3942

4043
test"allow b tag with no attr"do
41-
html="This <p>is</p> <b class=\"cool-look\" other=\"other\">text</b>"
44+
html="This <form>is</form> <b class=\"cool-look\" other=\"other\">text</b>"
4245
assertSanitizer.sanitize(html)=="This is <b>text</b>"
4346
end
4447

4548
test"allow i tag with no attr"do
46-
html="This <p>is</p> <i class=\"cool-look\" other=\"other\">text</i>"
49+
html="This <form>is</form> <i class=\"cool-look\" other=\"other\">text</i>"
4750
assertSanitizer.sanitize(html)=="This is <i>text</i>"
4851
end
4952
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp