Skip to content

Instantly share code, notes, and snippets.

@cumet04
Created February 17, 2016 12:01
Show Gist options
  • Save cumet04/35097bff9840455f24fd to your computer and use it in GitHub Desktop.
Save cumet04/35097bff9840455f24fd to your computer and use it in GitHub Desktop.
pukiwikiでmarkdownを使うプラグイン(marked.js利用)
<?php
/**
* Markdon Syntax with marked.js
*/
function plugin_markedjs_convert()
{
$args = func_get_args();
$body = array_pop($args);
$noskin = in_array("noskin", $args);
$body = htmlspecialchars($body);
static $num = 0;
$num++;
$divid = 'markedjs_content' . $num;
$output = "
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.js'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js'></script>
<div id='$divid'>$body</div>
<script>
hljs.initHighlightingOnLoad();
setTimeout(function() {
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: true,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false,
langPrefix: ''
});
var e = document.getElementById('$divid');
e.innerHTML=marked(e.textContent);
}, 0);
</script>";
return $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment