Skip to content

Instantly share code, notes, and snippets.

@tiye
Created May 7, 2012 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiye/2626097 to your computer and use it in GitHub Desktop.
Save tiye/2626097 to your computer and use it in GitHub Desktop.
Convert .nc file to Markdown..
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment