Skip to content

Instantly share code, notes, and snippets.

@fheinle
Created August 24, 2012 16:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fheinle/3452472 to your computer and use it in GitHub Desktop.
Save fheinle/3452472 to your computer and use it in GitHub Desktop.
Convert vim outliner to markdown
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
""" convert vim outliner files to markdown """
import sys
def count_indent(line):
"""count indentation level
will be used later to create headings/sections"""
count = 0
for character in line:
if character == "\t":
count += 1
else:
return count
def main(argv):
"""convert indentation to heading levels
body text (i.e. lines starting with ":") are ignored"""
otl_file = open(argv[1], 'r').readlines()
output_lines = []
for line in otl_file:
if line.strip().startswith(':'):
output_lines.append(line.strip()[2:])
else:
heading = (count_indent(line) + 1) * '#'
output_lines.append("%s %s" % (
heading,
line.strip()
)
)
return "\n".join(output_lines)
if __name__ == '__main__':
print '''<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>'''
print(main(sys.argv))
print '''</body>
</html>'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment