Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4914)

Unified Diff: chrome/common/extensions/docs/server2/document_parser.py

Issue 99703004: Docserver: Fix the TOC rendering for API references by fixing the haphazard way (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/document_parser.py
diff --git a/chrome/common/extensions/docs/server2/document_parser.py b/chrome/common/extensions/docs/server2/document_parser.py
index b44c743e8cfa854c05fbaec74f2d0a8233020e00..08b5e800dcb5984703711a70302c96bb5083ade5 100644
--- a/chrome/common/extensions/docs/server2/document_parser.py
+++ b/chrome/common/extensions/docs/server2/document_parser.py
@@ -48,6 +48,8 @@ class DocumentStructureEntry(object):
# so make it private. In particular we pretend that anything but the first
# h1 is an h2, and it'd be odd to expose that.
self._tag = tag
+ # Documents can override the name of the entry using title="".
+ self._has_explicit_name = False
def __repr__(self):
return '<%s>%s</%s>' % (self._tag, self.name, self._tag)
@@ -125,7 +127,16 @@ class _DocumentParser(HTMLParser):
(tag, self._processing_entry._tag))
return
- self._processing_entry = DocumentStructureEntry(tag, dict(attrs))
+ attrs_dict = dict(attrs)
+ self._processing_entry = DocumentStructureEntry(tag, attrs_dict)
+
+ explicit_name = attrs_dict.pop('title', None)
+ if explicit_name == '':
+ # Don't create a TOC entry at all if the tag has specified title="".
+ return
+ if explicit_name is not None:
+ self._processing_entry.name = explicit_name
+ self._processing_entry._has_explicit_name = True
if tag == 'h1' and self._title_entry is not None:
self._WarnWithPosition('Found multiple <h1> tags. Subsequent <h1> tags '
@@ -169,7 +180,8 @@ class _DocumentParser(HTMLParser):
self._processing_entry = None
def handle_data(self, data):
- if self._processing_entry is not None:
+ if (self._processing_entry is not None and
+ not self._processing_entry._has_explicit_name):
# += is inefficient, but probably fine here because the chances of a
# large number of nested tags within header tags is pretty low.
self._processing_entry.name += data
« no previous file with comments | « chrome/common/extensions/docs/server2/cron.yaml ('k') | chrome/common/extensions/docs/server2/document_parser_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698