Skip to content

Support StackBlitz embed #176

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 1 commit into from
Jun 13, 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.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require "qiita/markdown/embed/speeker_deck"
require "qiita/markdown/embed/docswell"
require "qiita/markdown/embed/figma"
require "qiita/markdown/embed/stack_blitz"
require "qiita/markdown/transformers/filter_attributes"
require "qiita/markdown/transformers/filter_script"
require "qiita/markdown/transformers/filter_iframe"
Expand Down
11 changes: 11 additions & 0 deletions lib/qiita/markdown/embed/stack_blitz.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Qiita
module Markdown
module Embed
module StackBlitz
SCRIPT_HOST = "stackblitz.com"
end
end
end
end
1 change: 1 addition & 0 deletions lib/qiita/markdown/transformers/filter_iframe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class FilterIframe
Embed::Docswell::SCRIPT_HOSTS,
Embed::Figma::SCRIPT_HOST,
Embed::GoogleDrive::SCRIPT_HOST,
Embed::StackBlitz::SCRIPT_HOST,
].flatten.freeze

def self.call(**args)
Expand Down
37 changes: 37 additions & 0 deletions spec/qiita/markdown/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,43 @@
end
end

context "with HTML embed code for StackBlitz" do
shared_examples "embed code stackblitz example" do
let(:markdown) do
<<~MARKDOWN
<iframe src="#{url}" width="800" height="600" frameborder="0" allowfullscreen="true"></iframe>
MARKDOWN
end
let(:url) { "#{scheme}//stackblitz.com/embed/example" }

if allowed
it "does not sanitize embed code" do
should eq <<~HTML
<iframe src="#{url}" width="800" height="600" frameborder="0" allowfullscreen="true"></iframe>
HTML
end
else
it "forces width attribute on iframe" do
should eq <<~HTML
<iframe src="#{url}" width="100%" height="600" frameborder="0" allowfullscreen="true"></iframe>
HTML
end
end
end

context "with scheme" do
let(:scheme) { "https:" }

include_examples "embed code stackblitz example"
end

context "without scheme" do
let(:scheme) { "" }

include_examples "embed code stackblitz example"
end
end

context "with embed code for Tweet" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
Expand Down