cef1bc256d
The `name` field on the `paragraph` type contains a unique ID for the paragraph. It's not guaranteed to be there, on images for example like in the `fd8d091ab8ef` post, but it's there for everything else I can find. This enables deep linking. There's no way to get to the deep link other than opening up the web console. I wanted to link every heading, but you can actually have links in part of a heading so that's not tenable. Maybe a "permalink" link next to every heading?
107 lines
2.7 KiB
Crystal
107 lines
2.7 KiB
Crystal
require "../spec_helper"
|
|
|
|
describe GistScanner do
|
|
it "returns gist ids from paragraphs" do
|
|
iframe = PostResponse::IFrame.new(
|
|
PostResponse::MediaResource.new(
|
|
href: "https://gist.github.com/user/123ABC",
|
|
iframeSrc: "",
|
|
iframeWidth: 0,
|
|
iframeHeight: 0
|
|
)
|
|
)
|
|
paragraphs = [
|
|
PostResponse::Paragraph.new(
|
|
name: "ab12",
|
|
text: "Check out this gist:",
|
|
type: PostResponse::ParagraphType::P,
|
|
markups: [] of PostResponse::Markup,
|
|
iframe: nil,
|
|
layout: nil,
|
|
metadata: nil
|
|
),
|
|
PostResponse::Paragraph.new(
|
|
name: "ab13",
|
|
text: "",
|
|
type: PostResponse::ParagraphType::IFRAME,
|
|
markups: [] of PostResponse::Markup,
|
|
iframe: iframe,
|
|
layout: nil,
|
|
metadata: nil
|
|
),
|
|
]
|
|
|
|
result = GistScanner.new(paragraphs).scan
|
|
|
|
result.should eq(["https://gist.github.com/user/123ABC"])
|
|
end
|
|
|
|
it "returns ids without the file parameters" do
|
|
iframe = PostResponse::IFrame.new(
|
|
PostResponse::MediaResource.new(
|
|
href: "https://gist.github.com/user/123ABC?file=example.txt",
|
|
iframeSrc: "",
|
|
iframeWidth: 0,
|
|
iframeHeight: 0
|
|
)
|
|
)
|
|
paragraphs = [
|
|
PostResponse::Paragraph.new(
|
|
name: "ab12",
|
|
text: "",
|
|
type: PostResponse::ParagraphType::IFRAME,
|
|
markups: [] of PostResponse::Markup,
|
|
iframe: iframe,
|
|
layout: nil,
|
|
metadata: nil
|
|
),
|
|
]
|
|
|
|
result = GistScanner.new(paragraphs).scan
|
|
|
|
result.should eq(["https://gist.github.com/user/123ABC"])
|
|
end
|
|
|
|
it "returns a unique list of ids" do
|
|
iframe1 = PostResponse::IFrame.new(
|
|
PostResponse::MediaResource.new(
|
|
href: "https://gist.github.com/user/123ABC?file=example.txt",
|
|
iframeSrc: "",
|
|
iframeWidth: 0,
|
|
iframeHeight: 0
|
|
)
|
|
)
|
|
iframe2 = PostResponse::IFrame.new(
|
|
PostResponse::MediaResource.new(
|
|
href: "https://gist.github.com/user/123ABC?file=other.txt",
|
|
iframeSrc: "",
|
|
iframeWidth: 0,
|
|
iframeHeight: 0
|
|
)
|
|
)
|
|
paragraphs = [
|
|
PostResponse::Paragraph.new(
|
|
name: "ab12",
|
|
text: "",
|
|
type: PostResponse::ParagraphType::IFRAME,
|
|
markups: [] of PostResponse::Markup,
|
|
iframe: iframe1,
|
|
layout: nil,
|
|
metadata: nil
|
|
),
|
|
PostResponse::Paragraph.new(
|
|
name: "ab13",
|
|
text: "",
|
|
type: PostResponse::ParagraphType::IFRAME,
|
|
markups: [] of PostResponse::Markup,
|
|
iframe: iframe2,
|
|
layout: nil,
|
|
metadata: nil
|
|
),
|
|
]
|
|
|
|
result = GistScanner.new(paragraphs).scan
|
|
|
|
result.should eq(["https://gist.github.com/user/123ABC"])
|
|
end
|
|
end
|