Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 61f78db37b6e7c158ca0d1db8fb017e03aac0c9d @Harrison-M committed Nov 28, 2012
Showing with 190 additions and 0 deletions.
  1. +6 −0 Default.sublime-commands
  2. +18 −0 LICENSE
  3. +22 −0 README.md
  4. +54 −0 indentparser.py
  5. +26 −0 indentsublime.py
  6. +16 −0 indenttxt.py
  7. +36 −0 output.html
  8. BIN parser.pyc
  9. +12 −0 test.txt
@@ -0,0 +1,6 @@
+[
+ {
+ "caption": "Indent.txt: Parse",
+ "command": "indent_to_list"
+ }
+]
18 LICENSE
@@ -0,0 +1,18 @@
+This software is released under the MIT license:
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
+# Indent.txt
+Turn your indented notes into HTML
+
+## How to use
+
+### Sublime Text 2
+1. Place this repository's folder in your Sublime Packages folder ([Sublime Package Control](http://wbond.net/sublime_packages/package_control) support coming soon)
+2. Run the "Indent.txt: Parse" command from the command palette (Ctrl-Shift-P) on a file or selection from a file
+3. The resulting HTML will open in a new tab.
+
+### Command line
+
+ python indenttxt.py inputfile outputfile
+
+Parses inputfile using the Indent.txt parser and saves the result to outputfile
+
+## License
+MIT
+
+## Coming soon:
+* Formatting
+* Automatic table of contents
@@ -0,0 +1,54 @@
+import re
+import cgi
+
+
+class IndentTxtParser:
+ def parseFile(self, filename):
+
+ #Init
+ inputFile = open(filename, "rU")
+ output = self.parse(inputFile)
+ inputFile.close()
+ return output
+
+ def parseText(self, text):
+ return self.parse(text.split("\n"))
+
+ def parse(self, iterable):
+ indentLevel = 0
+ output = "<!doctype html>\n<html>\n<body>\n<ul>\n"
+
+ #Compile our regex for reuse
+ indentRE = re.compile("^(\t| )")
+ lineNum = 0
+
+ for line in iterable:
+ lineNum += 1
+ newIndentLevel = 0
+ while(indentRE.match(line)):
+ line = indentRE.sub("", line)
+ newIndentLevel += 1
+ indentDiff = newIndentLevel - indentLevel
+ #Indent
+ if(indentDiff >= 1):
+ output += "\n<ul>\n"
+ #Need to go down additional levels
+ for i in range(indentDiff - 1):
+ output += "<li>\n<ul>\n"
+ #Outdent
+ elif(indentDiff <= -1):
+ output += "</li>\n"
+ for i in range(abs(indentDiff)):
+ output += "</ul>\n</li>\n"
+ #Samedent
+ else:
+ output += "</li>\n"
+ output += "<li>" + cgi.escape(line)
+ indentLevel = newIndentLevel
+ #Tie up loose ends
+ if(len(iterable) > 0):
+ output += "</li>\n"
+ for level in range(indentLevel):
+ output += "</ul>\n</li>\n"
+ output += "</ul>\n</body>\n</html>"
+ return output
@@ -0,0 +1,26 @@
+import sublime, sublime_plugin, indentparser
+
+
+class IndentToList(sublime_plugin.TextCommand):
+ def run(self, edit):
+ parser = indentparser.IndentTxtParser()
+ #Get current selection
+ sels = self.view.sel()
+ selsParsed = 0
+ if(len(sels) > 0):
+ for sel in sels:
+ #Make sure selection isn't just a cursor
+ if(abs(sel.b - sel.a) > 0):
+ self.parseRegion(parser, sel, edit)
+ selsParsed += 1
+ #All selections just cursor marks?
+ if(selsParsed == 0):
+ region = sublime.Region(0, self.view.size() - 1)
+ self.parseRegion(parser, region, edit)
+
+ def parseRegion(self, parser, region, edit):
+ lines = self.view.line(region)
+ text = self.view.substr(lines)
+ indented = parser.parseText(text)
+ newview = self.view.window().new_file()
+ newview.insert(edit, 0, indented)
@@ -0,0 +1,16 @@
+import indentparser
+import argparse
+
+
+argHandler = argparse.ArgumentParser(
+ description="Convert an indented notes file to HTML.")
+argHandler.add_argument('inputfile', metavar='inputfile.txt', type=str,
+ help='File to parse')
+argHandler.add_argument('outputfile', metavar='outputfile.html', type=str,
+ help='Output file')
+
+parser = indentparser.IndentTxtParser()
+args = argHandler.parse_args()
+outFile = open(args.outputfile, "w")
+outFile.write(parser.parseFile(args.inputfile))
+outFile.close()
@@ -0,0 +1,36 @@
+<!doctype html>
+<html>
+<body>
+<ul>
+</li>
+<li>All you have to do...
+<ul>
+<li>Is create an indented hierarchy</li>
+<li>Of your notes</li>
+<li>In a list</li>
+<li>And Indent.txt will turn it into a nice HTML file
+<ul>
+<li>
+<ul>
+<li>With a ul hierarchy based on indent levels</li>
+</ul>
+</li>
+</ul>
+</li>
+<li>Just use either
+<ul>
+<li>The command line utility</li>
+<li>or the Sublime Text 2 Plugin</li>
+</ul>
+</li>
+</ul>
+</li>
+<li>It's great for:
+<ul>
+<li>Note-taking</li>
+<li>Outlining</li>
+</ul>
+</li>
+</ul>
+</body>
+</html>
Binary file not shown.
@@ -0,0 +1,12 @@
+All you have to do...
+ Is create an indented hierarchy
+ Of your notes
+ In a list
+ And Indent.txt will turn it into a nice HTML file
+ With a ul hierarchy based on indent levels
+ Just use either
+ The command line utility
+ or the Sublime Text 2 Plugin
+It's great for:
+ Note-taking
+ Outlining

0 comments on commit 61f78db

Please sign in to comment.