Skip to content

Commit 7179dfa

Browse files
Support StackBlitz embed
1 parent 568655e commit 7179dfa

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

lib/qiita/markdown.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
require "qiita/markdown/embed/speeker_deck"
1919
require "qiita/markdown/embed/docswell"
2020
require "qiita/markdown/embed/figma"
21+
require "qiita/markdown/embed/stack_blitz"
2122
require "qiita/markdown/transformers/filter_attributes"
2223
require "qiita/markdown/transformers/filter_script"
2324
require "qiita/markdown/transformers/filter_iframe"
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
@@ -11,6 +11,7 @@ class FilterIframe
1111
Embed::Docswell::SCRIPT_HOSTS,
1212
Embed::Figma::SCRIPT_HOST,
1313
Embed::GoogleDrive::SCRIPT_HOST,
14+
Embed::StackBlitz::SCRIPT_HOST,
1415
].flatten.freeze
1516

1617
def self.call(**args)

spec/qiita/markdown/processor_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,43 @@
17471747
end
17481748
end
17491749

1750+
context "with HTML embed code for StackBlitz" do
1751+
shared_examples "embed code stackblitz example" do
1752+
let(:markdown) do
1753+
<<-MARKDOWN.strip_heredoc
1754+
<iframe src="#{url}" width="800" height="600" frameborder="0" allowfullscreen="true"></iframe>
1755+
MARKDOWN
1756+
end
1757+
let(:url) { "#{scheme}//stackblitz.com/embed/example" }
1758+
1759+
if allowed
1760+
it "does not sanitize embed code" do
1761+
should eq <<-HTML.strip_heredoc
1762+
<iframe src="#{url}" width="800" height="600" frameborder="0" allowfullscreen="true"></iframe>
1763+
HTML
1764+
end
1765+
else
1766+
it "forces width attribute on iframe" do
1767+
should eq <<-HTML.strip_heredoc
1768+
<iframe src="#{url}" width="100%" height="600" frameborder="0" allowfullscreen="true"></iframe>
1769+
HTML
1770+
end
1771+
end
1772+
end
1773+
1774+
context "with scheme" do
1775+
let(:scheme) { "https:" }
1776+
1777+
include_examples "embed code stackblitz example"
1778+
end
1779+
1780+
context "without scheme" do
1781+
let(:scheme) { "" }
1782+
1783+
include_examples "embed code stackblitz example"
1784+
end
1785+
end
1786+
17501787
context "with embed code for Tweet" do
17511788
let(:markdown) do
17521789
<<-MARKDOWN.strip_heredoc

0 commit comments

Comments
 (0)