Last active
January 5, 2017 06:55
-
-
Save Vnthf/710fca6ade10e4880a8ed9c8bee4389f to your computer and use it in GitHub Desktop.
ewfewf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var codepen = function (markdownit) { | |
markdownit.renderer.rules.codepen = function tokenize_return(tokens, idx) { | |
return '<div class="' + tokens[idx].codepenId + ' code_pan_temp"></div>'; | |
}; | |
markdownit.inline.ruler.before('emphasis', 'codepen', function (state, silent) { | |
var CODEPAN_LINK_REGEX = /^\[[^\]]+\]\(((?:http|https):\/\/codepen.io\/(\w+)\/pen\/(\w+))\)/, | |
CODEPAN_INLINE_REGEX = /^((?:http|https):\/\/codepen.io\/(\w+)\/pen\/(\w+))/; | |
var linkParser = CODEPAN_LINK_REGEX.exec(state.src) || CODEPAN_INLINE_REGEX.exec(state.src); | |
if (!linkParser) { | |
return false; | |
} | |
var userId = linkParser[2], | |
codepenId = linkParser[3]; | |
state.pos = state.pos + state.src.length - 1; | |
var tokens = [], token = []; | |
if (!silent) { | |
state.pending = null; | |
var newState = new state.md.inline.State('codepen', state.md, state.env); | |
token = state.push('codepen', ''); | |
token.userId = userId; | |
token.codepenId = codepenId; | |
token.url = 'https://codepen.io/api/oembed?url=' + linkParser[1] + '&format=js&callback=coolDude'; | |
$.ajax({ | |
url: token.url, | |
type: 'GET', | |
dataType: 'jsonp', | |
success: function (result) { | |
console.log(result) | |
$('.' + token.codepenId).html(result.html); | |
} | |
}); | |
} | |
state.pos = state.pos + state.src.length - 1; | |
state.posMax = state.tokens.length; | |
return true; | |
}); | |
} | |
module.exports = codepen; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment