@zhennann/markdown
Advanced tools
Comparing version 1.0.0 to 1.0.1
64
index.js
@@ -25,2 +25,65 @@ const markdown_it = require('markdown-it'); | ||
const audio_opts = { | ||
validate(params) { | ||
return params.trim().match(/^audio$/); | ||
}, | ||
render(tokens, idx) { | ||
if (tokens[idx].nesting === 1) { | ||
const tokenContent = tokens[idx + 2]; | ||
if (tokenContent && tokenContent.type === 'inline') { | ||
// content | ||
const content = tokenContent.content; | ||
tokenContent.content = ''; | ||
tokenContent.children = []; | ||
// element | ||
const id = `skPlayer-${(new Date()).getTime()}`; | ||
// opening tag | ||
return `<div id="${id}" class="skPlayer"> | ||
<script type="text/javascript"> | ||
function loadScript(src, callback) { | ||
if (!(typeof callback === 'function')) { | ||
callback = function() {}; | ||
} | ||
var check = document.querySelectorAll("script[src='" + src + "']"); | ||
if (check.length > 0) { | ||
check[0].addEventListener('load', function() { | ||
callback(); | ||
}); | ||
callback(); | ||
return; | ||
} | ||
var script = document.createElement('script'); | ||
var head = document.getElementsByTagName('head')[0]; | ||
script.type = 'text/javascript'; | ||
script.charset = 'UTF-8'; | ||
script.src = src; | ||
if (script.addEventListener) { | ||
script.addEventListener('load', function() { | ||
callback(); | ||
}, false); | ||
} else if (script.attachEvent) { | ||
script.attachEvent('onreadystatechange', function() { | ||
var target = window.event.srcElement; | ||
if (target.readyState === 'loaded') { | ||
callback(); | ||
} | ||
}); | ||
} | ||
head.appendChild(script); | ||
} | ||
loadScript('https://cdn.cabloy.org/audio/skPlayer.min.js', function() { | ||
var options = ${content}; | ||
options.element = document.getElementById('${id}'); | ||
var player = new skPlayer(options); | ||
}) | ||
</script> | ||
`; | ||
} | ||
return '<div>\n'; | ||
} | ||
// closing tag | ||
return '</div>\n'; | ||
}, | ||
}; | ||
module.exports = { | ||
@@ -35,2 +98,3 @@ create(ops) { | ||
.use(markdown_it_container, 'hljs-right') | ||
.use(markdown_it_container, 'audio', audio_opts) | ||
.use(markdown_it_deflist) | ||
@@ -37,0 +101,0 @@ .use(markdown_it_emoji) |
{ | ||
"name": "@zhennann/markdown", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "markdown", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13932
127