haha! commit
This commit is contained in:
commit
88f6b286c3
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
CONFIG
|
||||||
|
*.pyc
|
||||||
39
README
Normal file
39
README
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
777$7II7III??+,.......:+~=7$$Z$?$OOZOZ77?$$I+??I$ZOD8DD8DD888O$7$77$Z$$$ZZZZZOOO
|
||||||
|
$$$777$$77II??~.,..,.=?777$ZZ==$OZZ$I?=+?Z+==~=7Z7Z$OO8888DDDD8ZOZ$$$7Z$ZOZ$ZZOO
|
||||||
|
$$$7ZZ$Z$$77II=~:.,.:??+IZZZ+?O$ZI+?+:~+7I~~,:~?Z$88O88D88DDDDD8OZOZ$$$ZZZZZOOZZ
|
||||||
|
$$$$ZZ$$$$777I??:::,:7ZZ8OZ$$$7?=::,:~??~:,.....7$8$IZDDD8DDDNDDOZZO$$ZZZZZOZOOO
|
||||||
|
$$$77$7$7III$II+==+$$$OOO8OZ?=:......~. ........,?ZOI$88DOD8DDN8D888$7$ZZ$$Z$$ZO
|
||||||
|
$$7$$$77I77$ZZ$7,:Z$OZOOOOOI. ...,~:.....:~~+:===$Z$7OOD8DDD88O8D888O$7$Z$$$$OZ
|
||||||
|
$$77$$77I$$ZOZI,.7Z88O88O8?. .,:~~::,,.,,,+?$ZZZZZ8OZZ$8$8NDDDD88ODO8ZZ$$$OZZZOO
|
||||||
|
Z$Z$$$77$Z$$O$~.~?$ZOOOOOZ, ,?7$7II+:..,~+$III777I77I$O8OD8DD8D8DO8D88$77$$$ZZZZ
|
||||||
|
OOOOZc$ZOZOZZ?..+??IZO8NO$I?===+=~~~,...,~II???+~:+~:+ZO8D88DOODDDDD8D88OZ77$ZZZ
|
||||||
|
ZOZOOZZZZZOZ$II.~?I$ZZO8ZO~. ..~?+~~.. .,?$I$ZO888O?~$Z88D888O8888DONDD88Z7777$
|
||||||
|
OZZ8O8OZZOZZZZ7I7I$ZZ7$OZ7:.=7ZDO7?~.. ,::+O7$O8O78O7IOD88N8D8DD88DD8OOOO7$$7Z
|
||||||
|
OOOZ88888OOOOZZI~?I$Z$OZI+?77,?$I?:.. .,:,,~,,~+++~+I$ZZ8DDD8DNDD8DDOOOZ7?$$7$
|
||||||
|
OOOZO88OO8OZ7=:,.?7IZZOZI,~=~. ... . ..,,.. ...=:..~I$Z8DDDD8D8DDOD88a7II777$
|
||||||
|
$OOOOOOO8O+.,.:++:++$ZOO7 .,. .,,,.... ..:~.:$Z8DD8DDD88DDD8O$?????I7
|
||||||
|
OO8O8O8OZ$.,:?=..::?IZZ8Z .. ..,.,=,.. ..:I??7O8DD88D888D8OOI?II77II
|
||||||
|
OOOO8OZZ7=,~7?~,,,~~?$7OZ,. .,:~=:,.,:, ..:=+:~788DDD88Z888OZ$+I?III$7
|
||||||
|
ZOZZO$$$ZZZZ$I:~:~,,7=77$~:.. .:$$==IOO7=,.,....,:,:=+$D8DD8888D887II?7777$$
|
||||||
|
ZOOZZZ$$ZZZZ7+::=:::::II~.:.. ..=+?+IIII:...,,..,,,:==$DDD88888DD8$ZZ$$ZOOOO
|
||||||
|
7ZO$n7I$$$Z$7I~,,:,,.,=?:,,.. . ,:::~~I?:,......,,:,:=ZO888D88D8DO88O8888888
|
||||||
|
77777$77$$7I?~,.. .,,,=+~.. ~+=:~+:+II+=~:,:..,,::~?ZODO888D88DD8DDDD8D88N
|
||||||
|
?77???I?II?~:,.....=.:?+~. ., .:?7I:::~::=+~~...,:~=?$OOOZ888OO8OO8888D8D8D
|
||||||
|
7II??I+++~:,.. .,==$7+,. .IZ7~~~~,~:++=:..::~++7ZZODDD8D888a8OOD88D88
|
||||||
|
I???+~:,,,... .=:=~I$$+, .$7?+++++=+==+~,,:==+?78DDDDDDDO88OZOO88O888
|
||||||
|
??+::,,... ... .78Z7IZO=...... ,77:..:::.,~?+~::=++~?$8DDDN8D8O88O88OOOOO88
|
||||||
|
~=~:,,,.,.... .:OO$Z$7... ?$~ .......,:=~,:++==?$88D88D8ZOZOOZOOOO8DOO
|
||||||
|
:~=+:,,.. . ..,?$$+.. =...::,... ,~::~?===+OD88888OZOOOZO$ZOOZZZ8
|
||||||
|
,~++++==.. ....~ZZO~. .:~=~,,...:=~~$7?+?$DD8D8OOZZOZOZOOOO8O8O8
|
||||||
|
.:=+==++,. ...,.:+8DZ...I$7:.....,~=:,....+~?I7=?=$O8DDOOZ88OOO8OOOOOZZO88
|
||||||
|
,:~===?d, .:,:?OD8O...ZOO$$?I,...=~:,,,,~===?+?+77Z8OZ$Z$OOZZOOO8OOOOO8O8
|
||||||
|
,:~=~~=+.. ..=Z8888$.+OZ8OOZ8O7,.::=:~~=~:+????I$$?7$$ZZZOOOOOOOOO8O8OOOOO
|
||||||
|
,,:~~~+=.. ~ZO87I7Z,:7OOZOO?OD$~,:~:+?+==+?+=+77$?IOOZZZOOOOO8OOOOOOOOO888
|
||||||
|
..,,~=+~.. . =$OO:..+?.IZOOZOZ$OZ?=~=~=++=+:?III7$7I=7DD8ZZOO8OO88OO8ZOZ$ZOOO
|
||||||
|
..... .... . ,~?7OZ7..:~I+ZZOO$OOOZZ$+7++?+??I777$$Z7I?~Z8D8OO$Z888O8888ZOZOZOO8
|
||||||
|
,.....,~~==:=?$ZOZ7 .,~7IZZOZZZZOOOZO$I$Z$$Z$Z$ZZ7$I+==~DDDN8DDO$O88D8DDZO8OZ888
|
||||||
|
=+=:~::=~~:+$ZZZ$+...I77$OZ$$IIZ$?$Z7=======~=++??==,::=D8D88D8D8ZOODOOOZZ8ZOaOO
|
||||||
|
|
||||||
|
* install script
|
||||||
|
* man page
|
||||||
|
* deps
|
||||||
87
note.sh
Executable file
87
note.sh
Executable file
@ -0,0 +1,87 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
WHERE=$( cd $(dirname $0) ; pwd -P )
|
||||||
|
|
||||||
|
# default configs
|
||||||
|
if [[ -e "$WHERE/CONFIG" ]]; then
|
||||||
|
source $WHERE/CONFIG
|
||||||
|
fi
|
||||||
|
|
||||||
|
OPTIND=1 #reset getopts
|
||||||
|
|
||||||
|
while getopts t:f:b:s:r: opts; do
|
||||||
|
case $opts in
|
||||||
|
t)
|
||||||
|
TITLE=$OPTARG
|
||||||
|
;;
|
||||||
|
f)
|
||||||
|
FILE=$OPTARG
|
||||||
|
;;
|
||||||
|
b)
|
||||||
|
BIB=$OPTARG
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
STYLE=$OPTARG
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
REF=$OPTARG
|
||||||
|
;;
|
||||||
|
?)
|
||||||
|
echo "invalid option -$OPTARG";
|
||||||
|
exit;
|
||||||
|
;;
|
||||||
|
:)
|
||||||
|
echo "option -$OPTARG requires an argument";
|
||||||
|
exit;
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
if [[ -z "$TITLE" ]]; then
|
||||||
|
echo "No title provided. Aborting."
|
||||||
|
exit;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -d "$TITLE" ]]; then
|
||||||
|
read -p "Specified note already exists... Do you wish to continue? " yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* ) rm -r $TITLE; break;;
|
||||||
|
[Nn]* ) exit;;
|
||||||
|
* ) echo "Please answer yes or no.";;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "\n-----\ntitle: $TITLE\nfile: $FILE\nbib: $BIB\ncsl: $STYLE\nref: $REF\nbibliographe: $BIBLIOGRAPHE_PATH\n-----\n"
|
||||||
|
|
||||||
|
# output
|
||||||
|
mkdir -p $TITLE
|
||||||
|
|
||||||
|
# copy templates
|
||||||
|
cp -aR $WHERE/template/* $TITLE
|
||||||
|
|
||||||
|
cd $TITLE
|
||||||
|
|
||||||
|
# file exists? copy to output
|
||||||
|
[ -z "$FILE" ] && echo "No file to copy. Make sure to reference in text in the note!" || curl -O $FILE
|
||||||
|
|
||||||
|
# bibliography exists? fix makefile accordingly
|
||||||
|
[ -z "$BIB" ] && echo "No bibliography" || sed -i.bak "s#BIB\ :=#BIB\ := $BIB#g" Makefile
|
||||||
|
|
||||||
|
# csl style exists? fix makefile accordingly
|
||||||
|
[ -z "$STYLE" ] && echo "No csl style" || sed -i.bak "s#CSL\ :=#CSL\ := $STYLE#g" Makefile
|
||||||
|
|
||||||
|
if [ -z "$BIBLIOGRAPHE_PATH" ]; then
|
||||||
|
echo "No bibliographe"
|
||||||
|
else
|
||||||
|
node $BIBLIOGRAPHE_PATH/refactorbib.js --data $BIB > tmpbib.json
|
||||||
|
REFERENCE=$(node $BIBLIOGRAPHE_PATH/generatebib.js --data tmpbib.json --items [\"$REF\"] --output md)
|
||||||
|
echo $REFERENCE
|
||||||
|
rm tmpbib.json
|
||||||
|
sed -i.bak "s~*MACHINE-REF*~$REFERENCE~g" notes.mmd
|
||||||
|
fi
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
rm *.bak
|
||||||
|
cd ..
|
||||||
118
parse/parse.py
Executable file
118
parse/parse.py
Executable file
@ -0,0 +1,118 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from statemachine import StateMachine
|
||||||
|
import sys, string, re, json
|
||||||
|
|
||||||
|
markups = {'QUOTES' : ('PAGE', 'pp', 'tags', 'quote', 'fpc'), 'NOTES' : ('NOTE', '#', 'tags', 'note', 'fpc')}
|
||||||
|
output = {'QUOTES' : [], 'NOTES' : []}
|
||||||
|
|
||||||
|
|
||||||
|
def error(cargo):
|
||||||
|
# Don't want to get here! Unidentifiable line
|
||||||
|
sys.stderr.write('Unidentifiable line:\n'+ line)
|
||||||
|
|
||||||
|
def eof(cargo):
|
||||||
|
# Normal termination -- Cleanup code might go here.
|
||||||
|
sys.stdout.write('Processing Successful\n')
|
||||||
|
fpindx = open('.indx','wb')
|
||||||
|
json.dump(output, fpindx)
|
||||||
|
|
||||||
|
def parse(c):
|
||||||
|
fp, l = c
|
||||||
|
while 1:
|
||||||
|
line = fp.readline()
|
||||||
|
if not line: return eof, (fp, line)
|
||||||
|
if line[:2] == '##': return section(line), (fp, line)
|
||||||
|
else: continue
|
||||||
|
|
||||||
|
def QUOTES(c):
|
||||||
|
fp, l = c
|
||||||
|
sys.stdout.write('QUOTES\n')
|
||||||
|
while 1:
|
||||||
|
line = fp.readline()
|
||||||
|
if not line: return eof, (fp, line)
|
||||||
|
elif string.find(string.upper(line), 'PAGE') >= 0: return segment, (fp, line, 'QUOTES', markups['QUOTES'])
|
||||||
|
else: continue
|
||||||
|
|
||||||
|
def NOTES(c):
|
||||||
|
fp, l = c
|
||||||
|
sys.stdout.write('NOTES\n')
|
||||||
|
while 1:
|
||||||
|
line = fp.readline()
|
||||||
|
if not line: return eof, (fp, line)
|
||||||
|
elif string.find(string.upper(line), 'NOTE') >= 0: return segment, (fp, line, 'NOTES', markups['NOTES'])
|
||||||
|
else: continue
|
||||||
|
|
||||||
|
def segment(c):
|
||||||
|
fp, l, sect, mk = c
|
||||||
|
m, x, tt, y, cnt = mk
|
||||||
|
c = ''
|
||||||
|
t = []
|
||||||
|
q = ''
|
||||||
|
cc = ''
|
||||||
|
# identifier
|
||||||
|
c = ext_identifier(l)
|
||||||
|
while 1:
|
||||||
|
cursor = fp.tell()
|
||||||
|
line = fp.readline()
|
||||||
|
if not line:
|
||||||
|
# transition: EOF - record entry
|
||||||
|
rec_segment(c, t, q, cc, (sect, x, tt, y, cnt))
|
||||||
|
return eof, (fp, line)
|
||||||
|
elif string.find(string.upper(line), m) >= 0:
|
||||||
|
# transition: new segment - record entry
|
||||||
|
rec_segment(c, t, q, cc, (sect, x, tt, y, cnt))
|
||||||
|
return segment, (fp, line, sect, mk)
|
||||||
|
elif line[:1] == '<':
|
||||||
|
# tags
|
||||||
|
t += ext_tags(line)
|
||||||
|
continue
|
||||||
|
elif line[:2] == '##':
|
||||||
|
# transition: new section - record entry
|
||||||
|
rec_segment(c, t, q, cc, (sect, x, tt, y, cnt))
|
||||||
|
return section(line), (fp, line)
|
||||||
|
elif line == '\n' :
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
# text
|
||||||
|
if not cc:
|
||||||
|
cc = cursor
|
||||||
|
q += line
|
||||||
|
continue
|
||||||
|
|
||||||
|
## helper fncts
|
||||||
|
def section(line):
|
||||||
|
line = string.upper(line)
|
||||||
|
if string.find(line, 'NOTES') >= 0: return NOTES
|
||||||
|
elif string.find(line, 'QUOTES') >= 0: return QUOTES
|
||||||
|
elif string.find(line, 'REFERENCE') >= 0: return parse
|
||||||
|
else: return error
|
||||||
|
|
||||||
|
def ext_identifier(line):
|
||||||
|
b = string.rsplit(line)
|
||||||
|
return b[-1]
|
||||||
|
|
||||||
|
def ext_tags(line):
|
||||||
|
line = line.rstrip('\n').replace(' ','')
|
||||||
|
t = re.split('<|>', line)
|
||||||
|
return [v for v in t if v]
|
||||||
|
|
||||||
|
def rec_segment(idf, tags, text, cnt, mk):
|
||||||
|
if not text:
|
||||||
|
print 'hmm... no quote on pp.', c
|
||||||
|
return None
|
||||||
|
section_i, idf_i, tags_i, text_i, cnt_i = mk
|
||||||
|
entry = {idf_i : idf, text_i : text, tags_i : tags, cnt_i : cnt}
|
||||||
|
output[section_i].append(entry)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
m = StateMachine();
|
||||||
|
m.add_state(parse)
|
||||||
|
m.add_state(NOTES)
|
||||||
|
m.add_state(QUOTES)
|
||||||
|
m.add_state(segment)
|
||||||
|
m.add_state(error, end_state=1)
|
||||||
|
m.add_state(eof, end_state=1)
|
||||||
|
m.set_start(parse)
|
||||||
|
m.run((sys.stdin, ''))
|
||||||
32
parse/statemachine.py
Normal file
32
parse/statemachine.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
class InitializationError(Exception): pass
|
||||||
|
class StateMachine:
|
||||||
|
def __init__(self):
|
||||||
|
self.handlers = []
|
||||||
|
self.startState = None
|
||||||
|
self.endStates = []
|
||||||
|
|
||||||
|
def add_state(self, handler, end_state=0):
|
||||||
|
self.handlers.append(handler)
|
||||||
|
if end_state:
|
||||||
|
self.endStates.append(handler)
|
||||||
|
|
||||||
|
def set_start(self, handler):
|
||||||
|
self.startState = handler
|
||||||
|
|
||||||
|
def run(self, cargo=None):
|
||||||
|
if not self.startState:
|
||||||
|
raise InitializationError,\
|
||||||
|
"must call .set_start() before .run()"
|
||||||
|
if not self.endStates:
|
||||||
|
raise InitializationError, \
|
||||||
|
"at least one state must be an end_state"
|
||||||
|
handler = self.startState
|
||||||
|
while 1:
|
||||||
|
(newState, cargo) = handler(cargo)
|
||||||
|
if newState in self.endStates:
|
||||||
|
newState(cargo)
|
||||||
|
break
|
||||||
|
elif newState not in self.handlers:
|
||||||
|
raise RuntimeError, "Invalid target %s" % newState
|
||||||
|
else:
|
||||||
|
handler = newState
|
||||||
34
template/Makefile
Normal file
34
template/Makefile
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#output dir
|
||||||
|
OUT := ./
|
||||||
|
|
||||||
|
#csl - http://editor.citationstyles.org/
|
||||||
|
CSL :=
|
||||||
|
|
||||||
|
#bibliography file
|
||||||
|
BIB :=
|
||||||
|
|
||||||
|
#pdf
|
||||||
|
PDF := $(patsubst %.mmd,$(OUT)%.pdf,$(wildcard *.mmd))
|
||||||
|
|
||||||
|
$(OUT)%.pdf : %.mmd
|
||||||
|
pandoc $< -o $@
|
||||||
|
|
||||||
|
#html
|
||||||
|
HTML := $(patsubst %.mmd,$(OUT)%.html,$(wildcard *.mmd))
|
||||||
|
|
||||||
|
$(OUT)%.html : %.mmd
|
||||||
|
pandoc $< -s --filter pandoc-citeproc --csl $(CSL) --bibliography $(BIB) -o $@
|
||||||
|
|
||||||
|
all : dir $(HTML)
|
||||||
|
|
||||||
|
index :
|
||||||
|
parse.py < $(wildcard *.mmd)
|
||||||
|
|
||||||
|
clean :
|
||||||
|
rm -f $(HTML)
|
||||||
|
rm -f $(PDF)
|
||||||
|
|
||||||
|
rebuild : clean all
|
||||||
|
|
||||||
|
dir :
|
||||||
|
mkdir -p $(OUT)
|
||||||
7
template/notes.mmd
Normal file
7
template/notes.mmd
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
### Reference
|
||||||
|
|
||||||
|
*MACHINE-REF
|
||||||
|
|
||||||
|
### Quotes
|
||||||
|
|
||||||
|
### Notes
|
||||||
Loading…
x
Reference in New Issue
Block a user