1. rreilink
  2. sphinx

Commits

Georg Brandl  committed be65de6

Style fixes.

  • Participants
  • Parent commits 3071ba5
  • Branches default

Comments (0)

Files changed (3)

File CHANGES

View file
 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.

File doc/config.rst

View file
 
 .. 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
 

File sphinx/builders/linkcheck.py

View file
 
 
 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):
     """