Skip to content

Instantly share code, notes, and snippets.

@Vnthf
Last active January 5, 2017 06:55
Show Gist options
  • Save Vnthf/710fca6ade10e4880a8ed9c8bee4389f to your computer and use it in GitHub Desktop.
Save Vnthf/710fca6ade10e4880a8ed9c8bee4389f to your computer and use it in GitHub Desktop.
ewfewf
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