Last active
November 16, 2017 10:36
-
-
Save Pinacolada64/02590e916d1612fad9b9cec5b3a6fc4c to your computer and use it in GitHub Desktop.
An attempt to automatically generate HTML tables from markdown
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
from __future__ import print_function | |
import re | |
import os | |
### clear; python rewrite-tables.py > list.html | |
# print("cwd:", os.getcwd()) | |
# os.chdir("/home/ryan/now") | |
# print("cwd:", os.getcwd()) | |
# with file = open('classes', 'r'): # This is a big file | |
# except IOError, ValueError: | |
# print(Exception) | |
debug = False | |
file = ( | |
"### Citizen", | |
"- @[ooc](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-ooc-cmdooc) - stop puppeting and go ooc", | |
"- @[ic](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-ic-cmdic) - start puppeting and go ic", | |
"- @[sessions](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-sessions-cmdsessions) - check your connected session(s)", | |
"### Helper", | |
"- @[name](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-name-cmdname) - change the name and/or aliases of an object", | |
"- @[alias](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-alias-cmdsetobjalias) - adding permanent aliases for object", | |
"### Crafter", | |
"- @[spawn](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-spawn-cmdspawn) - spawn objects from prototype", | |
"### Builder", | |
"- @[quell](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-quell-cmdquell) - use character's permissions instead of account's (Leave builder mode)", | |
"#### Building", | |
"- @[dig](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-dig-cmddig) - build new rooms and connect them to the current location", | |
"- @[link](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-link-cmdlink) - link existing rooms together with existing exits", | |
"- @[unlink](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-unlink-cmdunlink) - remove exit-connections between rooms", | |
"- @[open](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-open-cmdopen) - open a new exit from the current room", | |
"- @[tunnel](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-tunnel-cmdtunnel) - create new rooms in cardinal directions only", | |
"- @[tel](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-tel-cmdteleport) - teleport object to another location", | |
"#### Info", | |
"- @[examine](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-examine-cmdexamine) - get detailed information about an object", | |
"- @[find](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-find-cmdfind) - search the database for objects", | |
"### Helpstaff", | |
"- @[sethelp](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-sethelp-cmdsethelp) - Edit the help database.", | |
"- @[charcreate](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-charcreate-cmdcharcreate) - create a new character", | |
"### Mage", | |
"- @[emit](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-emit-cmdemit) - admin command for emitting message to multiple objects", | |
"- @[boot](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-boot-cmdboot) - kick an account from the server.", | |
"- @[wall](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-wall-cmdwall) - make an announcement to all", | |
"### Wizard", | |
"#### Accounts", | |
"- @[ban](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-ban-cmdban) - ban an account from the server", | |
"- @[unban](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-unban-cmdunban) - remove a ban from an account", | |
"- @[userpassword](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-userpassword-cmdnewpassword) - change the password of an account", | |
"#### Objects", | |
"- @[lock](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-lock-cmdlock) - assign a lock definition to an object", | |
"- @[perm](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-perm-cmdperm) - set the permissions of an account or object", | |
"- @[tag](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-tag-cmdtag) - handles the tags of an object", | |
"- @[set](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-set-cmdsetattribute) - set attribute on an object or account", | |
"### Immortal", | |
"#### Coding/Database", | |
"- @[cmdsets](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-cmdsets-cmdlistcmdsets) - list command sets defined on an object", | |
"- @[copy](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-copy-cmdcopy) - copy an object and its properties", | |
"- @[cpattr](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-cpattr-cmdcpattr) - copy attributes between objects", | |
"- @[mvattr](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-mvattr-cmdmvattr) - move attributes between objects", | |
"- @[objects](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-objects-cmdobjects) - statistics on objects in the database", | |
"- @[wipe](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-wipe-cmdwipe) - clear all attributes from an object", | |
"- @[py](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-py-cmdpy) - execute a snippet of python code", | |
"- @[typeclass](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-typeclass-cmdtypeclass) - set or change an object's typeclass", | |
"- @[script](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-script-cmdscript) - attach a script to an object", | |
"- @[scripts](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-scripts-cmdscripts) - list and manage all running scripts", | |
"#### Server", | |
"- @[reload](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-reload-cmdreload) - reload the server without disconnecting anyone", | |
"- @[reset](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-reset-cmdreset) - reset and reboot the server - will disconnect everyone", | |
"- @[shutdown](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-shutdown-cmdshutdown) - stop the server completely, nobody can connect", | |
"- @[server](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-server-cmdserverload) - show server load and memory statistics", | |
"- @[service](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-service-cmdservice) - manage system services", | |
"- @[irc2chan](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-irc2chan-cmdirc2chan) - link an evennia channel to an external IRC channel", | |
"- @[rss2chan](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-rss2chan-cmdrss2chan) - link an evennia channel to an external RSS feed", | |
"- X@[ccreate](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-ccreate-cmdchannelcreate) - create a new channel", | |
"- X@[cdesc](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-cdesc-cmdcdesc) - describe a channel you control", | |
"- X@[cdestroy](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-cdestroy-cmdcdestroy) - destroy a channel you created", | |
"- X@[cemit](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-cemit-cmdcemit) - send an admin message to a channel", | |
"- X@[clock](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-clock-cmdclock) - change channel locks of a channel you control", | |
"- *@[create](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-create-cmdcreate) - create new objects", | |
"- X@[cwho](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-cwho-cmdcwho) - show who is listening to a channel", | |
"- X@[destroy](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-destroy-cmddestroy) - permanently delete objects", | |
"- X@[sethome](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-sethome-cmdsethome) - set an object's home location", | |
"- X[addcom](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-addcom-cmdaddcom) - add a channel alias and/or subscribe to a channel", | |
"- X[allcom](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-allcom-cmdallcom) - perform admin operations on all channels", | |
"- X@[cboot](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-cboot-cmdcboot) - kick an account from a channel you control", | |
"- X[delcom](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-delcom-cmddelcom) - remove a channel alias and/or unsubscribe from channel", | |
"- X[drop](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-drop-cmddrop) - drop something", | |
"- X[get](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-get-cmdget) - pick up something", | |
"- X[look](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-look-cmdooclook) - look while out-of-character", | |
"- X[page](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-page-cmdpage) - send a private message to another account" | |
) | |
# command = re.compile(r'^\[\w\]') | |
# url = re.compile(r'(https://.*)\)') | |
# summary = re.compile(r' - \((.+)\)') | |
# capture table class markdown: beginning of line, up to 4 '#'s, space, class name | |
p = re.compile(r'^#{,4} (.*)') | |
command_class = "default" | |
print(''' | |
<html> | |
<table> | |
<th> | |
<tr> | |
<td>Level</td> | |
<td>Type</td> | |
<td>Command</td> | |
<td>Summary</td> | |
</tr> | |
</th> | |
''') | |
for info in file: # Using 'for ... in' on file object | |
# print(info) | |
m = p.match(info) # does line match table class markdown? | |
if m: | |
command_class = m.group(1) # reassign to captured class name (\1) | |
if debug: | |
print('*** Switching to {}'.format(command_class)) | |
print('Should skip outputting HTML') | |
if not m: | |
# strip command from between [ ] | |
# command = info.split('[')[1].split(']')[0] | |
command = info[info.find('[')+1:info.find(']')] | |
if debug: | |
print("command: {}".format(command)) | |
# strip url from between ( ) | |
url = info[info.find('(')+1:info.find(')')] | |
# info.split('(')[1].split(')')[0] | |
if debug: | |
print("url: {}".format(url)) | |
# strip command summary from after ') - ' | |
summary = info[info.find(') - ')+4:] | |
# summary = info.split(' - ')[1] | |
if debug: | |
print("summary: {}".format(summary)) | |
print(''' | |
<tr> | |
<td id="level" class="{}" sorttable_customkey="3"> | |
{} | |
</td> | |
<td id="type"> | |
--- | |
</td> | |
<td id="command"> | |
@ | |
<a href="{}"> | |
{} | |
</a> | |
</td> | |
<td id="summary"> | |
{} | |
</td> | |
</tr>'''.format(command_class.lower(), command_class, url, command, summary)) | |
print(''' | |
</table> | |
</html> | |
''') | |
# file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment