Skip to content

Commit c9e66ac

Browse files
committed
update
1 parent d363ce6 commit c9e66ac

File tree

7 files changed

+147
-0
lines changed

7 files changed

+147
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: social-embeds
2+
author: Mark Sellors
3+
version: 0.0.2
4+
contributes:
5+
shortcodes:
6+
- gists.lua
7+
- loom.lua
8+
- twitter.lua
9+
- vimeo.lua
10+
- youtube.lua
11+
- mastodon.lua
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function gist(args)
2+
if quarto.doc.isFormat('html') then
3+
local user = pandoc.utils.stringify(args[1])
4+
local gist_id = pandoc.utils.stringify(args[2])
5+
local file_fragment = ''
6+
if args[3] ~= nil then
7+
local file = pandoc.utils.stringify(args[3])
8+
file_fragment = '?file=' .. file
9+
end
10+
11+
-- Assemble HTML to be returned
12+
local html = '<script src="https://gist.github.com/'
13+
.. user
14+
.. '/'
15+
.. gist_id
16+
.. '.js'
17+
.. file_fragment
18+
.. '"></script>'
19+
20+
return pandoc.RawInline('html', html)
21+
else
22+
return pandoc.Null()
23+
end
24+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function loom(args)
2+
if quarto.doc.isFormat('html') then
3+
local videoid = pandoc.utils.stringify(args[1])
4+
5+
-- Assemble HTML to be returned
6+
local html = '<div style="position: relative; padding-bottom: 56.25%; height: 0;"><iframe src="https://www.loom.com/embed/'
7+
.. videoid
8+
.. '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div>'
9+
10+
return pandoc.RawInline('html', html)
11+
else
12+
return pandoc.Null()
13+
end
14+
end
15+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function mastodon(args)
2+
if quarto.doc.isFormat('html') then
3+
local status_url = pandoc.utils.stringify(args[1])
4+
print(status_url)
5+
-- Assemble HTML to be returned
6+
local html = '<div style="position: relative; padding-bottom: 56.25%; height: 0;"> <iframe src="'.. status_url ..'/embed" class="mastodon-embed" style="max-width: 100%; border: 0;" width="100%" height="400" allowfullscreen="allowfullscreen"></iframe><script src="https://mastodon.social/embed.js" async="async"></script></div> '
7+
8+
return pandoc.RawInline('html', html)
9+
else
10+
return pandoc.Null()
11+
end
12+
end
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
local function ensureHtmlDeps()
2+
quarto.doc.addHtmlDependency({
3+
name = 'twitter',
4+
version = '0.0.1',
5+
scripts = {
6+
{
7+
path = "",
8+
attribs = {src="https://platform.twitter.com/widgets.js"},
9+
afterBody = true
10+
}
11+
}
12+
})
13+
end
14+
15+
local function isEmpty(s)
16+
return s == nil or s == ''
17+
end
18+
19+
function tweet(args, kwargs)
20+
if quarto.doc.isFormat('html') then
21+
ensureHtmlDeps()
22+
23+
if isEmpty(args[1]) then
24+
user = pandoc.utils.stringify(kwargs["user"])
25+
status_id = pandoc.utils.stringify(kwargs["id"])
26+
else
27+
user = pandoc.utils.stringify(args[1])
28+
status_id = pandoc.utils.stringify(args[2])
29+
end
30+
31+
-- Assemble the twitter oembed API URL from the user inputs
32+
local tweet_embed = 'https://publish.twitter.com/oembed?url=https://twitter.com/'
33+
.. user
34+
.. '/status/'
35+
.. status_id
36+
.. '&align=center'
37+
38+
print(tweet_embed)
39+
40+
local mt, api_resp = pandoc.mediabag.fetch(tweet_embed)
41+
42+
-- generate a random number to append to the html div ID to avoid re-use
43+
local id = math.random(10000, 99999)
44+
45+
local tweet_data = '<div id="tweet-'
46+
.. id
47+
.. '"></div><script>tweet='
48+
.. api_resp
49+
.. ';document.getElementById("tweet-'
50+
.. id
51+
.. '").innerHTML = tweet["html"];</script>'
52+
53+
return pandoc.RawInline('html', tweet_data)
54+
else
55+
return pandoc.Null()
56+
end
57+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function vimeo(args)
2+
if quarto.doc.isFormat('html') then
3+
local videoid = pandoc.utils.stringify(args[1])
4+
5+
-- Assemble HTML to be returned
6+
local html = '<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"> <iframe src="https://player.vimeo.com/video/'
7+
.. videoid
8+
.. '" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="vimeo video" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> </div> '
9+
10+
return pandoc.RawInline('html', html)
11+
else
12+
return pandoc.Null()
13+
end
14+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function youtube(args)
2+
if quarto.doc.isFormat('html') then
3+
local videoid = pandoc.utils.stringify(args[1])
4+
5+
-- Assemble HTML to be returned
6+
local html = '<div id="youtube-frame" style="position: relative; padding-bottom: 56.25%; /* 16:9 */ height: 0;"><iframe width="100%" height="" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" src="https://www.youtube.com/embed/'
7+
.. videoid
8+
.. '" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>'
9+
10+
return pandoc.RawInline('html', html)
11+
else
12+
return pandoc.Null()
13+
end
14+
end

0 commit comments

Comments
 (0)