Skip to content

Instantly share code, notes, and snippets.

@keng42
keng42 / md-menu.html
Last active September 23, 2016 12:37 — forked from cloudsben/md-menu.html
markdown menu
<script>
vm.dirs = [];
let hs = vm.$els.article.querySelectorAll('h1, h2, h3, h4, h5, h6');
for (var i = 0; i < hs.length; i++) {
hs[i].setAttribute('id', 'dir-' + i);
vm.dirs.push({
link: '#dir-' + i,
text: hs[i].innerText,
cls: 'dir-' + hs[i].localName
});
@keng42
keng42 / htmlentity.js
Created November 13, 2015 07:52 — forked from CatTail/htmlentity.js
Javascript: encode(decode) html text into html entity
// encode(decode) html text into html entity
var decodeHtmlEntity = function(str) {
return str.replace(/&#(\d+);/g, function(match, dec) {
return String.fromCharCode(dec);
});
};
var encodeHtmlEntity = function(str) {
var buf = [];
for (var i=str.length-1;i>=0;i--) {