aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xextract.py4
-rw-r--r--pelican/content/AlphaBoardComponents.md2
-rw-r--r--pelican/content/DocMeet.md4
-rwxr-xr-xtrac2md.py38
4 files changed, 18 insertions, 30 deletions
diff --git a/extract.py b/extract.py
index 33a49e1..f3c19c1 100755
--- a/extract.py
+++ b/extract.py
@@ -101,7 +101,7 @@ def main():
for row in db.execute(wiki_query):
if keep(row.name):
slug = urllib.parse.quote(row.name, "")
- print(slug, row.version)
+ #print(slug, row.version)
with open("wiki/{}.trac".format(slug), "w") as f:
f.write(row.text)
md = markdown_header(row, first_published) + trac2md.WikiToMD(row.text, slug)
@@ -110,7 +110,7 @@ def main():
for row in db.execute(attachment_query):
src, dst = attachment_link(row)
- print("{} => {}".format(dst, src))
+ #print("{} => {}".format(dst, src))
if not os.path.isdir(os.path.dirname(dst)):
os.makedirs(os.path.dirname(dst))
os.link(src, dst)
diff --git a/pelican/content/AlphaBoardComponents.md b/pelican/content/AlphaBoardComponents.md
index ee9da4a..86ab59e 100644
--- a/pelican/content/AlphaBoardComponents.md
+++ b/pelican/content/AlphaBoardComponents.md
@@ -140,7 +140,7 @@ Suggested components for the MKM and the switch:
### Entropy Sources
-* The avalanche noise entropy source should be implemented according to [attachment:alpha_board_noise_source.pdf existing schematics].
+* The avalanche noise entropy source should be implemented according to [existing schematics]({attach}AlphaBoardComponents/alpha_board_noise_source.pdf).
* The noise source should have a shielding can and suitable ground plane etc. to keep radiation of entropy bits as low as possible.
* The "12-15v stable" VCC should be controllable by the FPGA (enable/disable controlled by output pin on FPGA) to increase life time of components.
diff --git a/pelican/content/DocMeet.md b/pelican/content/DocMeet.md
index 41c5f1c..306c43f 100644
--- a/pelican/content/DocMeet.md
+++ b/pelican/content/DocMeet.md
@@ -11,5 +11,5 @@ Date: 2016-12-15 22:39
## Documents
-* [attachment:140109.cryptech.pdf 140109.cryptech.pdf Presentation - Overview of Project with Funding Requests]
-* [attachment:141002.cryptech-iij.pdf 141002.cryptech-iij.pdf CrypTech Presentation at Open IIJ Seminar]
+* [140109.cryptech.pdf Presentation - Overview of Project with Funding Requests]({attach}DocMeet/140109.cryptech.pdf)
+* [141002.cryptech-iij.pdf CrypTech Presentation at Open IIJ Seminar]({attach}DocMeet/141002.cryptech-iij.pdf)
diff --git a/trac2md.py b/trac2md.py
index 7e3a495..9d002dc 100755
--- a/trac2md.py
+++ b/trac2md.py
@@ -17,7 +17,8 @@ from urllib.parse import quote
image_pattern = re.compile(r"\[\[Image\((.*)\)\]\]")
wikilink_1_pattern = re.compile(r"\[\[(http.*)\]\]|\[(http.*)\]")
-wikilink_2_pattern = re.compile(r"\[\[(?:wiki:)?([a-zA-Z0-9_]+)\]\]|\[wiki:(.+)\]")
+wikilink_2_pattern = re.compile(r"\[\[attachment:([a-zA-Z0-9_]+)\]\]|\[attachment:(.+)\]")
+wikilink_3_pattern = re.compile(r"\[\[(?:wiki:)?([a-zA-Z0-9_]+)\]\]|\[wiki:(.+)\]")
strikethrough_pattern = re.compile(r"~~(.*)~~")
camelcase_pattern = re.compile(r"!((?:\w|[#])+)")
@@ -28,8 +29,6 @@ wikiheading_patterns = tuple(
def convert_headers(line):
- ''' Convert wikiformat headers
- '''
for level_count, header in wikiheading_patterns:
try:
level = header.search(line).group(1)
@@ -43,7 +42,7 @@ def convert_headers(line):
return line
-def make_mdlink(text):
+def make_mdlink(text, slug):
for sep in "| ":
if sep in text:
parts = text.split(sep, 1)
@@ -53,35 +52,25 @@ def make_mdlink(text):
parts = [p.strip() for p in parts]
if parts[-1].startswith('"') and parts[-1].endswith('"'):
parts[-1] = parts[-1][1:-1]
- return "[{}]({})".format(parts[-1], parts[0])
-
-
-def convert_wikilinks_1(line):
- ''' Convert wikiformat links
- '''
- m = wikilink_1_pattern.search(line)
- if m:
- mdlink = make_mdlink(m.group(1) or m.group(2))
- line = line.replace(m.group(0), mdlink)
- return line
+ if slug is None:
+ return "[{}]({})".format(parts[-1], parts[0])
+ else:
+ return "[{}]({{attach}}{}/{})".format(parts[-1], slug, parts[0])
-def convert_wikilinks_2(line):
- ''' Convert more wiki links'''
- m = wikilink_2_pattern.search(line)
+def convert_wikilinks(line, pattern, slug = None):
+ m = pattern.search(line)
if m:
text = m.group(1) or m.group(2)
if text.lower() == "pageoutline":
mdlink = ""
else:
- mdlink = make_mdlink(text)
+ mdlink = make_mdlink(text, slug)
line = line.replace(m.group(0), mdlink)
return line
def convert_strike(line):
- ''' Convert wikiformat striked text
- '''
striked_result = strikethrough_pattern.search(line)
if striked_result:
try:
@@ -117,8 +106,6 @@ def convert_linebreak(line):
return line
def WikiToMD(content, slug):
- ''' Convert wiki/RST format to Markdown. Code blocks, bold/italics,
- wiki links, lists, striked text, and headers. '''
# Line breaks in Markdown must be at end of line, so add newlines as needed
content = content.replace("[[br]]", "\\\\").replace("[[BR]]", "\\\\").replace("\\\\", "\\\\\n")
@@ -206,8 +193,9 @@ def WikiToMD(content, slug):
line = convert_headers(line)
# Convert wiki links
- line = convert_wikilinks_1(line)
- line = convert_wikilinks_2(line)
+ line = convert_wikilinks(line, wikilink_1_pattern)
+ line = convert_wikilinks(line, wikilink_2_pattern, slug)
+ line = convert_wikilinks(line, wikilink_3_pattern)
# Convert striked through text
line = convert_strike(line)