]> oss.titaniummirror.com Git - webber.git/commitdiff
link.py: removed a TODO item: finally correcly search for wrong links
authorHolger Schurig <holgerschurig@gmail.com>
Thu, 1 Jul 2010 12:09:48 +0000 (14:09 +0200)
committerHolger Schurig <holgerschurig@gmail.com>
Thu, 1 Jul 2010 12:09:48 +0000 (14:09 +0200)
in/plugins/read_html.md
in/plugins/read_markdown.md
in/plugins/read_rst.md
plugins/link.py

index 9ae454098cb0d323c7478ab526bc77f24c2bdf80..d2e634563500d09ce4f1d10d119e0d5a061fe5a8 100644 (file)
@@ -21,4 +21,4 @@ A sample "`test.html`" document looks like this:
        <!-- to be continued -->
 
 You'll find more about "`title:`", "`parent:`" and "`ctime:`" in the
-[[page format|pageformat.html]] description.
+[[page format|pageformat]] description.
index c9682a9a6f7a6e2774ed0fa96032dc73d2f438c6..cc4206bfa8488a7bcf680f97045b2ad3d77b11c8 100644 (file)
@@ -27,7 +27,7 @@ A sample "`test.md`" document looks like this:
        Don't send me spam, *ever*!
 
 You'll find more about "`title:`", "`parent:`" and "`ctime:`" in the
-[[page format|pageformat.html]] description.
+[[page format|pageformat]] description.
 
 = Modifications =
 
index 45543d8275cb644f09cf9ebe1b6ce4a10a7a4848..d2293354a22aa334a2219233d42e749c09824c82 100644 (file)
@@ -27,4 +27,4 @@ standard Python module "`docutils`" to convert RST into HTML. A sample
        Don't send me spam, *ever*!
 
 You'll find more about "`title:`", "`parent:`" and "`ctime:`" in the
-[[page format|pageformat.html]] description.
\ No newline at end of file
+[[page format|pageformat]] description.
index f7ecb2ade75b97bb369c34e8d0fe4f64f0d72bca..8a3404a4befc43d4751f84160db07a840b66cd8b 100644 (file)
@@ -1,6 +1,8 @@
 # -*- coding: iso-8859-1 -*-
 from webber import *
-import os, re
+import os, re, urlparse
+
+_file_links = {}
 
 # To understand this beast, read /usr/share/doc/python2.5-doc/html/lib/module-re.html :-)
 
@@ -19,6 +21,7 @@ reLink = re.compile(r'''
        \]\]                            # end of link
        ''', re.VERBOSE)
 
+
 def do_link(m):
        """Used in re.sub() to substitute link with HTML"""
        text = m.group(1) or ""
@@ -41,11 +44,13 @@ def do_link(m):
                                break
        if not text:
                text = link
-       # validate link
-       # TODO: validating local files still not working
-       if not link.startswith("http:") and not link.endswith(".html") and not link.endswith(".png"):
+       # validate local files
+       components = urlparse.urlparse(link)
+       if components.scheme in ("", "file"):
                file = get_current_file()
-               warning("%s: unknown link to '%s'" % (file.rel_path, link) )
+               fname = os.path.join(file.direc, components.path)
+               fname = os.path.normpath(fname)
+               _file_links[fname] = file.rel_path
        return '<a href="%s%s">%s</a>' % (link, anchor, text)
 
 
@@ -65,6 +70,7 @@ def test_link():
                else:
                        print "No link:", s
 
+
 def test_sub():
        for s in (
                        'Before [[!macro]] after',
@@ -80,3 +86,15 @@ def test_sub():
 @set_hook("linkify")
 def linkify(params):
        params.file.contents = reLink.sub(do_link, params.file.contents)
+
+
+@set_hook("finish")
+def check_links(params):
+       """Checks all links that are stored in _file_links to warn if the
+       file doesn't exist"""
+
+       for s in _file_links:
+               #print "check:", s, cfg.out_dir
+               out_file = os.path.join(cfg.out_dir, s)
+               if not os.path.exists(out_file):
+                       warning("%s: invalid link to '%s'" % (_file_links[s], s))