Skip to content

Add new codepen embed script url public.codepenassets.com #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/qiita/markdown/embed/code_pen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module CodePen
"https://production-assets.codepen.io/assets/embed/ei.js",
"https://static.codepen.io/assets/embed/ei.js",
"https://cpwebassets.codepen.io/assets/embed/ei.js",
"https://public.codepenassets.com/embed/index.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write the spec.

shared_examples_for "override embed code attributes" do |allowed:|

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the codepen tests. And, added test for the new codepen URL.

]
CLASS_NAME = %w[codepen]
DATA_ATTRIBUTES = %w[
Expand Down
68 changes: 25 additions & 43 deletions spec/qiita/markdown/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1406,52 +1406,34 @@
end

shared_examples_for "override embed code attributes" do |allowed:|
context "with HTML embed code for CodePen using old script url" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
MARKDOWN
end

if allowed
it "does not sanitize embed code" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
HTML
end
else
it "forces async attribute on script" do
should eq <<-HTML.strip_heredoc
[
"https://production-assets.codepen.io/assets/embed/ei.js",
"https://static.codepen.io/assets/embed/ei.js",
"https://cpwebassets.codepen.io/assets/embed/ei.js",
"https://public.codepenassets.com/embed/index.js",
].each do |script_url|
context "with HTML embed code for CodePen using script url `#{script_url}`" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://production-assets.codepen.io/assets/embed/ei.js" async="async"></script>
HTML
<script src="#{script_url}"></script>
MARKDOWN
end
end
end

context "with HTML embed code for CodePen" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://static.codepen.io/assets/embed/ei.js"></script>
MARKDOWN
end

if allowed
it "does not sanitize embed code" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://static.codepen.io/assets/embed/ei.js"></script>
HTML
end
else
it "forces async attribute on script" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://static.codepen.io/assets/embed/ei.js" async="async"></script>
HTML
if allowed
it "does not sanitize embed code" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="#{script_url}"></script>
HTML
end
else
it "forces async attribute on script" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="#{script_url}" async="async"></script>
HTML
end
end
end
end
Expand Down
Loading