Georg Brandl avatar Georg Brandl committed be65de6

Style fixes.

Comments (0)

Files changed (3)

 Release 1.2 (in development)
 ============================
 
+* PR#45: The linkcheck builder now checks ``#anchor``\ s for existence.
+
 * PR#28: Added Hungarian translation.
 
 * PR#35: Added Slovak translation.
 
 .. confval:: linkcheck_anchors
 
-   True or false, whether to check the existence of #anchor in links. Since
-   this requires downloading the whole document, it's considerably slower
-   when enabled. Default is ``True``.
+   True or false, whether to check the validity of ``#anchor``\ s in links.
+   Since this requires downloading the whole document, it's considerably slower
+   when enabled.  Default is ``True``.
 
    .. versionadded:: 1.2
 

sphinx/builders/linkcheck.py

 
 
 class AnchorCheckParser(HTMLParser):
+    """Specialized HTML parser that looks for a specific anchor."""
+
     def __init__(self, search_anchor):
         HTMLParser.__init__(self)
 
             if key in ('id', 'name') and value == self.search_anchor:
                 self.found = True
 
+
 def check_anchor(f, hash):
     """Reads HTML data from a filelike object 'f' searching for anchor 'hash'.
-
-    Returns True if anchor was found, False otherwise"""
-
+    Returns True if anchor was found, False otherwise.
+    """
     parser = AnchorCheckParser(hash)
-
     try:
         # Read file in chunks of 8192 bytes. If we find a matching anchor, we
-        # break the loop early in hopes not to have to download the whole thing
-
+        # break the loop early in hopes not to have to download the whole thing.
         chunk = f.read(8192)
         while chunk and not parser.found:
             parser.feed(chunk)
             chunk = f.read(8192)
-
         parser.close()
     except HTMLParseError:
         # HTMLParser is usually pretty good with sloppy HTML, but it tends to
         # choke on EOF. But we're done then anyway.
         pass
+    return parser.found
 
-    return parser.found
 
 class CheckExternalLinksBuilder(Builder):
     """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.