Last active
February 5, 2019 14:40
-
-
Save wizardforcel/27e835679b6c3bec20ba308bf14df50f to your computer and use it in GitHub Desktop.
split a md file & convert html to md
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 fs = require('fs'); | |
try {fs.mkdirSync('out');} | |
catch(ex){} | |
var co = fs.readFileSync('a.md', 'utf-8'); | |
var files = co.split(/<split>123<\/split>/g); | |
var summary = ''; | |
//var pre = "{% raw %}\n", | |
// sub = "\n{% endraw %}"; | |
for(var i = 0; i < files.length; i++) | |
{ | |
fs.writeFileSync('out/' + i + '.md', files[i], {encoding: 'utf-8'}); | |
var rms = files[i].match(/^#+\x20(.+?)(?:\x20#+)?$/m); | |
var name = rms? rms[1]: ""; | |
summary += '+ [' + name + '](' + i + '.md)\n'; | |
} | |
fs.writeFileSync('out/SUMMARY.md', summary, {encoding: 'utf-8'}); |
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 toMD = require('to-markdown'); | |
var fs = require('fs'); | |
var myConventors = require('./my-conventors'); | |
var co = fs.readFileSync('a.html', 'utf-8') | |
.replace(/(<h1[^>]*>)/g, "<split>123</split>$1"); | |
var tmpConv = [{ | |
filter: function(n) { | |
var classes = n.className.split(' '); | |
return n.nodeName === 'SPAN' && | |
classes.indexOf('math') != -1; | |
}, | |
replacement: function (content) { | |
return '`' + content + '`'; | |
} | |
}, | |
{ | |
filter: function(n) { | |
var classes = n.className.split(' '); | |
return n.nodeName === 'DIV' && | |
classes.indexOf('math') != -1; | |
}, | |
replacement: function (content) { | |
return '\n\n```\n' + content + '\n```\n\n'; | |
} | |
}]; | |
var md = toMD(co, { | |
gfm: true, | |
converters: tmpConv.concat(myConventors) | |
}); | |
fs.writeFileSync('a.md', md, {encoding: 'utf-8'}); | |
console.log('done...'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment