--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile Sun Sep 14 13:54:37 2014 +0900
+ ./rst2cheatsheet.py source.rst > cheatsheet.html
+ ./html2png.py "file://$(realpath cheatsheet.html)" wallcheat.png
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/html2png.py Sun Sep 14 13:54:37 2014 +0900
+class SimpleBrowser(object):
+ # http://kmandla.wordpress.com/2010/05/24/the-1-2kb-python-browser-script/
+ # taken from there and adapted to be stupid and take screenshots
+ def __init__(self, url, output_filename):
+ self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
+ self.window.connect('delete_event', self.close_application)
+ screen = self.window.get_screen()
+ self.webview = webkit.WebView()
+ self.webview.set_size_request(screen.get_width(), screen.get_height())
+ self.window.add(self.webview)
+ self.window.set_title('%s' % url)
+ 'document-load-finished', self.screenshot, output_filename)
+ def screenshot(webview, frame, output_filename):
+ width, height = webview.window.get_size()
+ pb = gtk.gdk.Pixbuf('rgb', False, 8, width, height)
+ cm = gtk.gdk.colormap_get_system()
+ pb.get_from_drawable(webview.window, cm, 0, 0, 0, 0, width, height)
+ pb.save(output_filename, 'png')
+ glib.timeout_add_seconds(1, callback) # delay until rendering finishes
+ def close_application(self, widget, event, data=None):
+if __name__ == '__main__':
+ SimpleBrowser(sys.argv[1], sys.argv[2])
+ print 'usage:', sys.argv[0], 'INPUT OUTPUT'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rst2cheatsheet.py Sun Sep 14 13:54:37 2014 +0900
+from docutils.core import publish_parts
+from docutils.writers import html4css1
+class CheatsheetWriter(html4css1.Writer):
+ html4css1.Writer.__init__(self)
+ self.translator_class = CheatsheetTranslator
+class CheatsheetTranslator(html4css1.HTMLTranslator):
+ def visit_section(self, node):
+ if not self.section_level:
+ self.body.append(self.starttag(node, 'div', CLASS='uk-float-left uk-margin-large-right uk-margin-bottom'))
+ self.section_level += 1
+ def depart_section(self, node):
+ self.section_level -= 1
+ if not self.section_level:
+ self.body.append('</div>')
+ def visit_title(self, node):
+ if self.section_level == 1:
+ self.body.append('<!--h1>')
+ self.body.append(self.starttag(node, 'h2', ''))
+ def depart_title(self, node):
+ if self.section_level == 1:
+ self.body.append('</h1-->\n')
+ self.body.append('</h2>\n')
+ def visit_literal(self, node):
+ self.body.append(self.starttag(node, 'code', ''))
+ def visit_title_reference(self, node):
+ self.body.append(self.starttag(node, 'kbd', ''))
+ def depart_title_reference(self, node):
+ self.body.append('</kbd>')
+ def visit_definition_list(self, node):
+ self.body.append(self.starttag(node, 'table', CLASS='table-cheats uk-text-left'))
+ def depart_definition_list(self, node):
+ self.body.append('</table>\n')
+ def visit_definition_list_item(self, node):
+ self.body.append(self.starttag(node, 'tr', ''))
+ def depart_definition_list_item(self, node):
+ self.body.append('</tr>\n')
+ def visit_term(self, node):
+ self.body.append(self.starttag(node, 'td', ''))
+ def depart_term(self, node):
+ self.body.append('</td>')
+ def visit_definition(self, node):
+ self.body.append(self.starttag(node, 'td', ''))
+ def depart_definition(self, node):
+ self.body.append('</td>')
+with open(source_path, 'r') as sf:
+parts = publish_parts(source=source, source_path=source_path, writer=CheatsheetWriter())
+with open('template.html', 'r') as tf:
+print template.replace('{{ content }}', parts['fragment']).encode('utf-8')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source.rst Sun Sep 14 13:54:37 2014 +0900
+ beginning of *previous*, *next* paragraph
+ beginning of *previous*, *next* sentence
+ *beginning*, *middle* of line
+ *first*, *last* character of line
+ line n, default the *first*, *last*
+ percentage n of the file
+ column n of current line
+ match of next brace, bracket, comment, #define
+ line n from *start*, *bottom* of window
+ insert *before*, *after* cursor
+ insert at *beginning*, *end* of line
+ insert text in first column
+ open a new line *below*, *above* the current line
+ change to the end of line
+ *lowercase*, *uppercase* text of movement m
+ yank current line into register
+ put register *after*, *before* cursor position
+ like `p`, `P` with indent adjusted
+ like `p`, `P` leaving cursor after new text
+ the group matches the empty string; the letters set the corresponding flags
+ a non-capturing version of regular parentheses
+ the substring matched by the group is accessible via the symbolic group
+ matches whatever text was matched by the earlier named group named
+ the contents of the parentheses are simply ignored
+ matches next, but doesn't consume any of the string (lookahead assertion)
+ negative lookahead assertion
+ matches a preceding string (lookbehind assertion)
+ negative lookbehind assertion, patterns which start with it may match at
+ the beginning of the string being searched
+``(?(id/name)yes-pattern|no-pattern)``
+ magic. ``(<)?(\w+@\w+(?:\.\w+)+)(?(1)>)``
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/template.html Sun Sep 14 13:54:37 2014 +0900
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/uikit/2.9.0/css/uikit.min.css">
+ h1, h2, h3, h4, h5, h6 {
+ .table-cheats td:first-child {
+ <div class="uk-margin-large-top uk-margin-large-right uk-margin-large-bottom uk-margin-large-left">