Skip to content

Instantly share code, notes, and snippets.

@dwcramer
Last active August 29, 2015 14:05

Revisions

  1. dwcramer renamed this gist Aug 23, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Chunk Markdown → ChunkMarkdown.py
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,10 @@
    # h1 below an h2, this happily sticks it in the file
    # for it's parent h2.

    # Name output files based on heading names, replacing
    # spaces with - and adding ".html.md". No other bad characters
    # are stripped from the heading.

    import re

    with open('concepts.html.markdown') as file:
  2. dwcramer revised this gist Aug 23, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions Chunk Markdown
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,11 @@
    #!/usr/bin/python

    # Chunk a big markdown file into smaller files
    # at the h2 level. Throw away anything above that.
    # This assumes a 'well-formed' file. I.e. if you put an
    # h1 below an h2, this happily sticks it in the file
    # for it's parent h2.

    import re

    with open('concepts.html.markdown') as file:
  3. dwcramer created this gist Aug 23, 2014.
    30 changes: 30 additions & 0 deletions Chunk Markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/usr/bin/python

    import re

    with open('concepts.html.markdown') as file:
    data = file.readlines()

    data.reverse()

    headings = []

    for line in data:
    m = re.match("^## ", line)
    if m:
    headings.append(line)

    section = []

    for line in data:
    section.append(line)

    if len(headings) > 0 and line == headings[0]:
    section.reverse()
    filename = line.split("## ",1)[1].replace(" ","-").rstrip().lower() + ".html.md"
    sectionFile = open(filename,'w')
    for lline in section:
    sectionFile.write('%s'% lline)
    sectionFile.close()
    section = []
    del headings[0]