Created
June 12, 2014 21:40
-
-
Save mapk0y/5ee9d85c59fbfc1b2fc9 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding: utf-8; -*- | |
# github に上げるテキストのタイトルを抜き出して目次を作る | |
# https://github.com/sonots/growthforecast-tuning/blob/master/toc.rb | |
# vi: set ts=4 sw=4 sts=0 et: | |
import os,sys,urllib | |
filename = sys.argv[1] | |
flag = 0 | |
start = 1 | |
for i in open(filename, 'r'): | |
if start == 1: | |
start = 0 | |
continue | |
if i.startswith('```'): | |
flag = flag ^ 1 | |
if flag == 1: | |
continue | |
if i.startswith('#'): | |
s = i.split(None,1) | |
level = len(s[0]) -1 | |
title = s[1].strip() | |
uri = urllib.quote(title.lower().replace(' ', '-').replace('.', '')) | |
print("%s* [%s](#%s)" % (' ' * level * 2, title, uri)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment