mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-08-26 21:27:13 -05:00
Don't consider contents of source comments for the search index.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
Release 0.6.2 (in development)
|
Release 0.6.2 (in development)
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
|
* Don't consider contents of source comments for the search index.
|
||||||
|
|
||||||
* Set the default encoding to ``utf-8-sig`` to handle files with a
|
* Set the default encoding to ``utf-8-sig`` to handle files with a
|
||||||
UTF-8 BOM correctly.
|
UTF-8 BOM correctly.
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -12,7 +12,7 @@ import re
|
|||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
from docutils.nodes import Text, NodeVisitor
|
from docutils.nodes import comment, Text, NodeVisitor, SkipNode
|
||||||
|
|
||||||
from sphinx.util.stemmer import PorterStemmer
|
from sphinx.util.stemmer import PorterStemmer
|
||||||
from sphinx.util import jsdump, rpartition
|
from sphinx.util import jsdump, rpartition
|
||||||
@@ -83,6 +83,8 @@ class WordCollector(NodeVisitor):
|
|||||||
self.found_words = []
|
self.found_words = []
|
||||||
|
|
||||||
def dispatch_visit(self, node):
|
def dispatch_visit(self, node):
|
||||||
|
if node.__class__ is comment:
|
||||||
|
raise SkipNode
|
||||||
if node.__class__ is Text:
|
if node.__class__ is Text:
|
||||||
self.found_words.extend(word_re.findall(node.astext()))
|
self.found_words.extend(word_re.findall(node.astext()))
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
test_search
|
||||||
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
Test the search index builder.
|
||||||
|
|
||||||
|
:copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS.
|
||||||
|
:license: BSD, see LICENSE for details.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from docutils import frontend, utils, nodes
|
||||||
|
from docutils.parsers import rst
|
||||||
|
|
||||||
|
from sphinx.search import IndexBuilder
|
||||||
|
|
||||||
|
|
||||||
|
def setup_module():
|
||||||
|
global settings, parser
|
||||||
|
optparser = frontend.OptionParser(components=(rst.Parser,))
|
||||||
|
settings = optparser.get_default_values()
|
||||||
|
parser = rst.Parser()
|
||||||
|
|
||||||
|
|
||||||
|
FILE_CONTENTS = '''\
|
||||||
|
.. test that comments are not indexed: boson
|
||||||
|
|
||||||
|
test that non-comments are indexed: fermion
|
||||||
|
'''
|
||||||
|
|
||||||
|
def test_wordcollector():
|
||||||
|
doc = utils.new_document('test data', settings)
|
||||||
|
doc['file'] = 'dummy'
|
||||||
|
parser.parse(FILE_CONTENTS, doc)
|
||||||
|
|
||||||
|
ix = IndexBuilder(None)
|
||||||
|
ix.feed('filename', 'title', doc)
|
||||||
|
assert 'boson' not in ix._mapping
|
||||||
|
assert 'fermion' in ix._mapping
|
||||||
Reference in New Issue
Block a user