summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-03-10 18:13:55 +0100
committerGeorg Brandl <georg@python.org>2012-03-10 18:13:55 +0100
commit54da0756f77e2d1ac35ea99ab9fe2103a0dd160c (patch)
treea5f4936d1a11be9c7a09f493d20e82c92d374180
parenta6a382a5406bf87f47c2ebbb8d30a38d66417621 (diff)
downloadsphinx-54da0756f77e2d1ac35ea99ab9fe2103a0dd160c.tar.gz
Style fixes.
-rw-r--r--CHANGES2
-rw-r--r--doc/config.rst6
-rw-r--r--sphinx/builders/linkcheck.py15
3 files changed, 12 insertions, 11 deletions
diff --git a/CHANGES b/CHANGES
index 0a0fe8d6..fc2eabb5 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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.