Skip to content

Commit 3022aab

Browse files
Support StackBlitz embed
1 parent d13ad8a commit 3022aab

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

lib/qiita/markdown.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
require "qiita/markdown/embed/speeker_deck"
1818
require "qiita/markdown/embed/docswell"
1919
require "qiita/markdown/embed/figma"
20+
require "qiita/markdown/embed/stack_blitz"
2021
require "qiita/markdown/transformers/filter_attributes"
2122
require "qiita/markdown/transformers/filter_script"
2223
require "qiita/markdown/transformers/filter_iframe"
12 KB
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module Qiita
4+
module Markdown
5+
module Embed
6+
module StackBlitz
7+
SCRIPT_HOST = "stackblitz.com"
8+
end
9+
end
10+
end
11+
end

lib/qiita/markdown/transformers/filter_iframe.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class FilterIframe
1010
Embed::GoogleSlide::SCRIPT_HOST,
1111
Embed::Docswell::SCRIPT_HOSTS,
1212
Embed::Figma::SCRIPT_HOST,
13+
Embed::StackBlitz::SCRIPT_HOST,
1314
].flatten.freeze
1415

1516
def self.call(**args)

spec/qiita/markdown/processor_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,43 @@
17111711
end
17121712
end
17131713

1714+
context "with HTML embed code for StackBlitz" do
1715+
shared_examples "embed code stackblitz example" do
1716+
let(:markdown) do
1717+
<<-MARKDOWN.strip_heredoc
1718+
<iframe src="#{url}" width="800" height="600" frameborder="0" allowfullscreen="true"></iframe>
1719+
MARKDOWN
1720+
end
1721+
let(:url) { "#{scheme}//stackblitz.com/embed/example" }
1722+
1723+
if allowed
1724+
it "does not sanitize embed code" do
1725+
should eq <<-HTML.strip_heredoc
1726+
<iframe src="#{url}" width="800" height="600" frameborder="0" allowfullscreen="true"></iframe>
1727+
HTML
1728+
end
1729+
else
1730+
it "forces width attribute on iframe" do
1731+
should eq <<-HTML.strip_heredoc
1732+
<iframe src="#{url}" width="100%" height="600" frameborder="0" allowfullscreen="true"></iframe>
1733+
HTML
1734+
end
1735+
end
1736+
end
1737+
1738+
context "with scheme" do
1739+
let(:scheme) { "https:" }
1740+
1741+
include_examples "embed code stackblitz example"
1742+
end
1743+
1744+
context "without scheme" do
1745+
let(:scheme) { "" }
1746+
1747+
include_examples "embed code stackblitz example"
1748+
end
1749+
end
1750+
17141751
context "with embed code for Tweet" do
17151752
let(:markdown) do
17161753
<<-MARKDOWN.strip_heredoc

0 commit comments

Comments
 (0)