Chromium Code Reviews| Index: grit/format/policy_templates/writers/doc_writer.py |
| diff --git a/grit/format/policy_templates/writers/doc_writer.py b/grit/format/policy_templates/writers/doc_writer.py |
| index e90e16cb63388e9e2b9f5f642a91f5c06e07d445..bb76fb898129dc4b91cfe4c0e9e2cb1202b8bc04 100644 |
| --- a/grit/format/policy_templates/writers/doc_writer.py |
| +++ b/grit/format/policy_templates/writers/doc_writer.py |
| @@ -58,32 +58,37 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): |
| ''' |
| return ', '.join([item_map[x] for x in items]) |
| - def _AddTextWithLinks(self, parent, text): |
| - '''Parse a string for URLs and add it to a DOM node with the URLs replaced |
| - with <a> HTML links. |
| + def _AddTextWithLinksAndParagraphs(self, parent, text): |
| + '''Parse a string for URLs and paragraphs and |
| + add it to a DOM node with the URLs replaced |
| + with <a> HTML links and paragraphs replaced by <p>. |
| Args: |
| parent: The DOM node to which the text will be added. |
| text: The string to be added. |
| ''' |
| - # Iterate through all the URLs and replace them with links. |
| - out = [] |
| + |
| + # Open paragraph |
| + paragraph = self.AddElement(parent, 'p') |
| while True: |
| - # Look for the first URL. |
| + # Look for the first URL or break line. |
| res = self._url_matcher.search(text) |
| if not res: |
| break |
| - # Calculate positions of the substring of the URL. |
| - url = res.group(0) |
| + # Calculate positions of the substring of the URL or new line. |
| + group = res.group(0) # Either "/n/n" or "http://some.url" |
| start = res.start(0) |
| end = res.end(0) |
| - # Add the text prior to the URL. |
| - self.AddText(parent, text[:start]) |
| - # Add a link for the URL. |
| - self.AddElement(parent, 'a', {'href': url}, url) |
| + # Add the text prior to the URL or break line. |
| + self.AddText(paragraph, text[:start]) |
| + # Either add new paragraph or add a link for the URL. |
| + if group == "\n\n": #have we found a break line? |
| + paragraph = self.AddElement(parent, 'p') |
| + else: |
| + self.AddElement(paragraph, 'a', {'href': group}, group) |
| # Drop the part of text that is added. |
| text = text[end:] |
| - self.AddText(parent, text) |
| + self.AddText(paragraph, text) |
| def _AddStyledElement(self, parent, name, style_ids, attrs=None, text=None): |
| @@ -114,8 +119,9 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): |
| parent: The DOM node for which the feature list will be added. |
| policy: The data structure of a policy. |
| ''' |
| - # Replace URLs with links in the description. |
| - self._AddTextWithLinks(parent, policy['desc']) |
| + |
| + # Replace URLs with links and /n with <p>...</p> in the description. |
| + self._AddTextWithLinksAndParagraphs(parent, policy['desc']) |
| # Add list of enum items. |
| if policy['type'] in ('string-enum', 'int-enum', 'string-enum-list'): |
| ul = self.AddElement(parent, 'ul') |
| @@ -508,7 +514,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): |
| problem_href = policy['problem_href'] |
| div = self._AddStyledElement(parent, 'div', ['div.note']) |
| note = self._GetLocalizedMessage('note').replace('$6', problem_href) |
| - self._AddTextWithLinks(div, note) |
| + self._AddTextWithLinksAndParagraphs(div, note) |
| def _AddPolicyRow(self, parent, policy): |
| '''Adds a row for the policy in the summary table. |
| @@ -597,7 +603,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): |
| summary_div = self.AddElement(self._main_div, 'div') |
| self.AddElement(summary_div, 'a', {'name': 'top'}) |
| self.AddElement(summary_div, 'br') |
| - self._AddTextWithLinks( |
| + self._AddTextWithLinksAndParagraphs( |
| summary_div, |
| self._GetLocalizedMessage('intro')) |
| self.AddElement(summary_div, 'br') |
| @@ -691,7 +697,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): |
| } |
| # A simple regexp to search for URLs. It is enough for now. |
| - self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') |
| + self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])|\n\n') |
|
Mattias Nissler (ping if slow)
2015/02/10 08:30:08
It's rather confusing to do both URL matching and
|
| def GetTemplateText(self): |
| # Return the text representation of the main <div> tag. |