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' key: 'Gist'
regExp: /^\w+:\/\/gist\.github\.com\/[\w\-]+\/(\w+)/ regExp: /^\w+:\/\/gist\.github\.com\/[\w\-]+\/(\w+)/
el: (a) -> style: ''
el = $.el 'iframe' el: do ->
el.setAttribute 'sandbox', 'allow-scripts' counter = 0
content = <%= html('<html><head><title>${a.dataset.uid}</title></head><body><script src="https://gist.github.com/${a.dataset.uid}.js"></script></body></html>') %> (a) ->
el.src = E.url content el = $.el 'pre',
el 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: title:
api: (uid) -> "https://api.github.com/gists/#{uid}" api: (uid) -> "https://api.github.com/gists/#{uid}"
text: ({files}) -> text: ({files}) ->

View File

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