Fix Gist embedding.

This commit is contained in:
ccd0 2017-07-15 01:11:54 -07:00
parent 09abb3da02
commit cf0d9e0d41
2 changed files with 17 additions and 10 deletions

View File

@ -271,12 +271,23 @@ Embedding =
,
key: 'Gist'
regExp: /^\w+:\/\/gist\.github\.com\/[\w\-]+\/(\w+)/
el: (a) ->
el = $.el 'iframe'
el.setAttribute 'sandbox', 'allow-scripts'
content = <%= html('<html><head><title>${a.dataset.uid}</title></head><body><script src="https://gist.github.com/${a.dataset.uid}.js"></script></body></html>') %>
el.src = E.url content
el
style: ''
el: do ->
counter = 0
(a) ->
el = $.el 'pre',
hidden: true
id: "gist-embed-#{counter++}"
$.ajax "https://api.github.com/gists/#{a.dataset.uid}",
responseType: 'json'
onload: ->
el.textContent = Object.values(@response.files)[0].content
el.className = 'prettyprint'
$.global ->
window.prettyPrint? (() ->), document.getElementById(document.currentScript.dataset.id).parentNode
, id: el.id
el.hidden = false
el
title:
api: (uid) -> "https://api.github.com/gists/#{uid}"
text: ({files}) ->

View File

@ -43,7 +43,3 @@ E.cat = function(templates) {
}
return html;
};
E.url = function(content) {
return "data:text/html;charset=utf-8,<!doctype html>" + encodeURIComponent(content.innerHTML);
};