Skip to content

feat: Google Drive iframe support #163

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 11, 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 @@ -12,6 +12,7 @@
require "qiita/markdown/embed/tweet"
require "qiita/markdown/embed/asciinema"
require "qiita/markdown/embed/youtube"
require "qiita/markdown/embed/google_drive"
require "qiita/markdown/embed/slide_share"
require "qiita/markdown/embed/google_slide"
require "qiita/markdown/embed/speeker_deck"
Expand Down
11 changes: 11 additions & 0 deletions lib/qiita/markdown/embed/google_drive.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 GoogleDrive
SCRIPT_HOST = "drive.google.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 @@ -10,6 +10,7 @@ class FilterIframe
Embed::GoogleSlide::SCRIPT_HOST,
Embed::Docswell::SCRIPT_HOSTS,
Embed::Figma::SCRIPT_HOST,
Embed::GoogleDrive::SCRIPT_HOST,
].flatten.freeze

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

context "with HTML embed code for Google Drive" do
shared_examples "embed code googledrive example" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<iframe src="#{url}" width="640" height="480" frameborder="0" allowfullscreen="true"></iframe>
MARKDOWN
end
let(:file_id) { "DRIVE_FILE_ID_EXAMPLE" }
let(:url) { "#{scheme}//drive.google.com/file/d/#{file_id}/preview" }

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

context "with scheme" do
let(:scheme) { "https:" }
include_examples "embed code googledrive example"
end

context "without scheme" do
let(:scheme) { "" }
include_examples "embed code googledrive example"
end
end

context "with HTML embed code for SlideShare" do
shared_examples "embed code slideshare example" do
let(:markdown) do
Expand Down