10 changed files with 142 additions and 7 deletions
-
8assets/css/tabs.scss
-
22config/config.exs
-
50lib/fuck_gab/scrubber.ex
-
3lib/fuck_gab_web/controllers/page_controller.ex
-
17lib/fuck_gab_web/templates/page/index.html.eex
-
10lib/fuck_gab_web/templates/panel/panel.html.eex
-
3lib/fuck_gab_web/views/panel_view.ex
-
3mix.exs
-
4mix.lock
-
29test/fuck_gab/scrubber_test.exs
@ -0,0 +1,50 @@ |
|||
defmodule FuckGab.Scrubber do |
|||
@moduledoc """ |
|||
Sanitizes panel content for display. |
|||
""" |
|||
require FastSanitize.Sanitizer.Meta |
|||
alias FastSanitize.Sanitizer.Meta |
|||
|
|||
Meta.strip_comments() |
|||
|
|||
Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], ["http", "https"]) |
|||
|
|||
Meta.allow_tag_with_this_attribute_values(:a, "class", [ |
|||
"hashtag", |
|||
"u-url", |
|||
"mention", |
|||
"u-url mention", |
|||
"mention u-url" |
|||
]) |
|||
|
|||
Meta.allow_tag_with_this_attribute_values(:a, "rel", [ |
|||
"tag", |
|||
"nofollow", |
|||
"noopener", |
|||
"noreferrer", |
|||
"ugc" |
|||
]) |
|||
|
|||
Meta.allow_tag_with_these_attributes(:a, ["name", "title"]) |
|||
Meta.allow_tag_with_these_attributes(:abbr, ["title"]) |
|||
Meta.allow_tag_with_these_attributes(:b, []) |
|||
Meta.allow_tag_with_these_attributes(:blockquote, []) |
|||
Meta.allow_tag_with_these_attributes(:br, []) |
|||
Meta.allow_tag_with_these_attributes(:code, []) |
|||
Meta.allow_tag_with_these_attributes(:del, []) |
|||
Meta.allow_tag_with_these_attributes(:em, []) |
|||
Meta.allow_tag_with_these_attributes(:i, []) |
|||
Meta.allow_tag_with_these_attributes(:li, []) |
|||
Meta.allow_tag_with_these_attributes(:ol, []) |
|||
Meta.allow_tag_with_these_attributes(:p, []) |
|||
Meta.allow_tag_with_these_attributes(:pre, []) |
|||
Meta.allow_tag_with_these_attributes(:strong, []) |
|||
Meta.allow_tag_with_these_attributes(:sub, []) |
|||
Meta.allow_tag_with_these_attributes(:sup, []) |
|||
Meta.allow_tag_with_these_attributes(:u, []) |
|||
Meta.allow_tag_with_these_attributes(:ul, []) |
|||
Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"]) |
|||
Meta.allow_tag_with_these_attributes(:span, []) |
|||
|
|||
Meta.strip_everything_not_covered() |
|||
end |
@ -1,5 +1,16 @@ |
|||
<section class="home-page__top"> |
|||
<p class="description"><%= @site_description %></p> |
|||
</section> |
|||
<%= if @site_description.display == true do %> |
|||
<section class="home-page__top"> |
|||
<p class="description"><%= @site_description.content %></p> |
|||
</section> |
|||
<% end %> |
|||
<%= with panels when is_list(panels) and length(panels) > 0 <- @panels[:above_explore] do |
|||
render_many panels, FuckGabWeb.PanelView, "panel.html" |
|||
end %> |
|||
<%= live_render(@conn, FuckGabWeb.DirectoryLive) %> |
|||
<%= with panels when is_list(panels) and length(panels) > 0 <- @panels[:above_suggestion_form] do |
|||
render_many panels, FuckGabWeb.PanelView, "panel.html" |
|||
end %> |
|||
<%= live_render(@conn, FuckGabWeb.SuggestionForm) %> |
|||
<%= with panels when is_list(panels) and length(panels) > 0 <- @panels[:below_suggestion_form] do |
|||
render_many panels, FuckGabWeb.PanelView, "panel.html" |
|||
end %> |
@ -0,0 +1,10 @@ |
|||
<section class="tab"> |
|||
<div class="tab-header"> |
|||
<h3 class="tab-title"><%= @panel.title %></h3> |
|||
</div> |
|||
<div class="tab-content"> |
|||
<%= with {:ok, content} <- FastSanitize.Sanitizer.scrub(@panel.content, FuckGab.Scrubber) do |
|||
raw(content) |
|||
end %> |
|||
</div> |
|||
</section> |
@ -0,0 +1,3 @@ |
|||
defmodule FuckGabWeb.PanelView do |
|||
use FuckGabWeb, :view |
|||
end |
@ -0,0 +1,29 @@ |
|||
defmodule FuckGab.ScrubberTest do |
|||
use FuckGab.DataCase |
|||
|
|||
describe "Scraper" do |
|||
test "make sure HTML Scrubber works properly" do |
|||
expected = """ |
|||
<b>bold up</b> |
|||
<p>paragraphics</p> |
|||
break down<br/> |
|||
<span>spannity span, wonderful spaaan</span> |
|||
<ul><li>Unordered list stuff</li></ul> |
|||
<ol><li>ORDER! ORDER!</li></ol> |
|||
<blockquote>Blocked by the quotes</blockquote> |
|||
<abbr title="This is Sparta">Welcome to Sparta</abbr> |
|||
<code>Oh, hi! I'm Cody!</code> |
|||
<del>DELET THIS!</del> |
|||
<em>Emerald</em> |
|||
<i>Mama-mia!</i> |
|||
<pre>Prepare</pre> |
|||
<strong>STRUNGGG MAN!</strong> |
|||
<sub>Subway in New York</sub> |
|||
<sup>Sup bitches!</sup> |
|||
<u>Why r u gae?</u> |
|||
""" |
|||
|
|||
assert {:ok, expected} == FastSanitize.Sanitizer.scrub(expected, FuckGab.Scrubber) |
|||
end |
|||
end |
|||
end |
Write
Preview
Loading…
Cancel
Save
Reference in new issue