diff options
| author | Georg Brandl <georg@python.org> | 2012-03-10 18:13:55 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2012-03-10 18:13:55 +0100 |
| commit | 54da0756f77e2d1ac35ea99ab9fe2103a0dd160c (patch) | |
| tree | a5f4936d1a11be9c7a09f493d20e82c92d374180 | |
| parent | a6a382a5406bf87f47c2ebbb8d30a38d66417621 (diff) | |
| download | sphinx-54da0756f77e2d1ac35ea99ab9fe2103a0dd160c.tar.gz | |
Style fixes.
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | doc/config.rst | 6 | ||||
| -rw-r--r-- | sphinx/builders/linkcheck.py | 15 |
3 files changed, 12 insertions, 11 deletions
@@ -1,6 +1,8 @@ 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. diff --git a/doc/config.rst b/doc/config.rst index 4368a306..a8d5c07f 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1320,9 +1320,9 @@ Options for the linkcheck builder .. 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 diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 25d34aca..a8adcdac 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -35,6 +35,8 @@ class HeadRequest(Request): class AnchorCheckParser(HTMLParser): + """Specialized HTML parser that looks for a specific anchor.""" + def __init__(self, search_anchor): HTMLParser.__init__(self) @@ -46,30 +48,27 @@ class AnchorCheckParser(HTMLParser): 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 + class CheckExternalLinksBuilder(Builder): """ Checks for broken external links. |
