summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-06-10 12:36:40 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2021-06-10 12:36:40 +0200
commit72189b3ec608873052b0c1d8bfb0685972b8269f (patch)
treeaa05615cf67e7ddd09c3bc0b3fb573d767d65792
parentfix? (diff)
downloadvimwiki-scripts-72189b3ec608873052b0c1d8bfb0685972b8269f.tar.gz
vimwiki-scripts-72189b3ec608873052b0c1d8bfb0685972b8269f.tar.xz
Handle deffinition lists at start of entries.
-rwxr-xr-xdo.py67
1 files changed, 58 insertions, 9 deletions
diff --git a/do.py b/do.py
index 71639a4..e898898 100755
--- a/do.py
+++ b/do.py
@@ -10,6 +10,7 @@ import os.path as path
import email
from email.policy import default
from datetime import datetime
+from dateutil import parser as dtparser
import argparse
path_base = '/'
@@ -229,6 +230,7 @@ output = open(f'doc.{mode}', 'w')
name = pwd.getpwuid(os.getuid()).pw_gecos
+
if mode == 'tex':
output.write(f'''
\\documentclass[a4paper]{{article}}
@@ -244,17 +246,9 @@ if mode == 'tex':
\\usepackage{{fancyhdr}}
\\usepackage{{hyperref}}
- \\title{{{heading}}}
- \\date\\today
- \\author{{{name}}}
- \\begin{{document}}
- \\maketitle
- % \\tableofcontents
''')
elif mode == 'txt':
- d = f'{datetime.now():%Y-%m-%d}'
- output.write(f'\n{heading.center(40)}\n{d.center(40)}\n')
sectioncounter = 0
subsectioncounter = 0
@@ -320,9 +314,64 @@ for match in tag_iter:
outstr += page1[pos:]
+options = { 'date': '\\today' if mode == 'tex' else f'{datetime.now():%Y-%m-%d}' }
+
+# split the text into paragraph blocks
+lines = outstr.split('\n')
+paragraphs = []
+paragraph = []
+for line in lines:
+ if line == '':
+ if paragraph == []:
+ continue
+ else:
+ paragraphs.append(paragraph)
+ paragraph = []
+ else:
+ paragraph.append(line)
+
+# check the first paragraph for a deffinition list, and parse that
+# into variables
+for i in range(len(paragraphs[0])):
+ line = paragraphs[0][i]
+ if m := re.match('- (\w+)\s*::\s*(.*)', line):
+ if m[1] == 'date':
+ dt = dtparser.parse(m[2])
+ if mode == 'tex':
+ options['date'] = f'{dt:%Y--%m--%d}'
+ else:
+ options['date'] = f'{dt:%Y-%m-%d}'
+
+ else:
+ options[m[1]] = m[2]
+ else:
+ # remove handled lines, keep remaining lines in paragraphs list
+ paragraphs[0] = paragraphs[0][i:]
+ break
+else:
+ # remove first paragraph from paragraphs list
+ paragraphs = paragraphs[1:]
+
+
if mode == 'tex':
+ output.write(f"""
+ \\title{{{heading}}}
+ \\date{{{options['date']}}}
+ \\author{{{name}}}
+ \\begin{{document}}
+ \\maketitle
+ % \\tableofcontents
+ """)
output.write('\\begin{verbatim}\n')
-output.write(outstr + '\n')
+elif mode == 'txt':
+ d = options['date']
+ output.write(f'\n{heading.center(40)}\n{d.center(40)}\n')
+
+for paragraph in paragraphs:
+ output.write('\n'.join(paragraph))
+ output.write('\n\n')
+# output.write(outstr + '\n')
+
if mode == 'tex':
output.write('\\end{verbatim}\n\\appendix\n')