3 次代码提交 09ed31ba14 ... 838f9cf8b7

作者 SHA1 备注 提交日期
  Rob Austein 838f9cf8b7 Use absolute form of attachment links 3 年之前
  Rob Austein d0c10e7a18 Undo URL quoting of directory names in Markdown output 3 年之前
  Rob Austein 8f033beb45 Don't lose our marbles when outermost list level is indented 3 年之前
共有 2 个文件被更改,包括 12 次插入10 次删除
  1. 8 6
      extract.py
  2. 4 4
      trac2md.py

+ 8 - 6
extract.py

@@ -49,7 +49,7 @@ def attachment_link(row):
     fn2 = os.path.splitext(row["filename"])[1]
     return \
         os.path.join("attachments", "wiki", h1[:3], h1, h2 + fn2), \
-        os.path.join("pelican", "content", urllib.parse.quote(row.id, ""), row.filename)
+        os.path.join("pelican", "content", row.id, row.filename)
 
 class Filter:
 
@@ -108,12 +108,14 @@ def main():
 
     for row in db.execute(wiki_query):
         if keep(row.name):
-            slug = urllib.parse.quote(row.name, "")
-            #print(slug, row.version)
-            with open("wiki/{}.trac".format(slug), "w") as f:
+            with open("wiki/{}.trac".format(urllib.parse.quote(row.name, "")), "w") as f:
                 f.write(row.text)
-            md = markdown_header(row, first_published) + wiki_to_markdown(row.text, slug)
-            with open("pelican/content/{}.md".format(slug), "w") as f:
+            md = markdown_header(row, first_published) + wiki_to_markdown(row.text, row.name)
+            fn = "pelican/content/{}.md".format(row.name)
+            dn = os.path.dirname(fn)
+            if not os.path.exists(dn):
+                os.makedirs(dn)
+            with open(fn, "w") as f:
                 f.write(md)
 
     for row in db.execute(attachment_query):

+ 4 - 4
trac2md.py

@@ -54,7 +54,7 @@ class Trac2Markdown:
         if text == link and link.startswith("http") and "://" in link:
             return "<{}>".format(link)
         elif scheme == "attachment:":
-            return "[{}]({{attach}}{}/{})".format(text, self.slug, link)
+            return "[{}]({{attach}}/{}/{})".format(text, self.slug, link)
         elif scheme in ("source:", "browser:"):
             return "[{}]({}/{})".format(text, self.source_url.rstrip("/"), link.lstrip("/"))
         elif scheme == "wiki:" or (scheme is None and self.camelcase_pattern.match(link)):
@@ -67,7 +67,7 @@ class Trac2Markdown:
         if "://" in text:
             return "<img src=\"{}\">".format(text)
         else:
-            return "![{}]({{attach}}{}/{})".format(text, self.slug, quote(text, ""))
+            return "![{}]({{attach}}/{}/{})".format(text, self.slug, quote(text, ""))
 
     def __init__(self, source_url):
         self.source_url = source_url
@@ -158,12 +158,12 @@ class Trac2Markdown:
                 #
                 nested_line = line.lstrip(' ')
                 if nested_line.startswith('- ') or nested_line.startswith('* '):
+                    indent = len(line) - len(nested_line)
                     if not in_list:
                         new_content.append("\n")
                         nested_level = 0
-                        prev_indent = 0
+                        prev_indent = indent
                         in_list = True
-                    indent = len(line) - len(nested_line)
                     text_indent = len(line) - len(nested_line[1:].lstrip())
                     if indent > prev_indent:
                         nested_level += 1