public
Created

Convert .nc file to Markdown..

  • Download Gist
narkcown.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#!/usr/bin/coffee
 
fs = require 'fs'
chars = ['>', '-', '*', ' ', '+']
ss = ' '
 
if process.argv[2]? then filename = process.argv[2]
else
console.log 'You need to name one file here --!'
do process.exit
 
if (match = filename.match /(.+.)nc$/)?
new_filename = match[1]+'md'
else
console.log 'unrecognized subfix, supposed to `.nc`'
do process.exit
 
nc2md = (file) ->
list = file.split '\n'
list = list.map (line) ->
line = line.trimRight()
if line is '\\' then '<br>'
else if line.length <= 2 then line
else if line[0..1] is ss then ss+line else line+ss
copy = []
normal = true
for line in list
plain =
if not line[0]? then 2 else
if line[0] in chars then -1 else 1
copy.push '' if (plain + normal) is 0
copy.push line
normal = plain
copy.join '\n'
 
fs.readFile filename, 'utf-8', (err, file) ->
throw err if err?
md = nc2md file
fs.writeFile new_filename, md, 'utf-8', ->
console.log 'Finished :::', new_filename

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.