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..374320bde0cf4b7a309a3dfc87a40e40bd437c2b 100644 |
| --- a/grit/format/policy_templates/writers/doc_writer.py |
| +++ b/grit/format/policy_templates/writers/doc_writer.py |
| @@ -66,11 +66,13 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): |
| parent: The DOM node to which the text will be added. |
| text: The string to be added. |
| ''' |
| + # A simple regexp to search for URLs. It is enough for now. |
| + url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') |
| + |
| # Iterate through all the URLs and replace them with links. |
| - out = [] |
| while True: |
| # Look for the first URL. |
| - res = self._url_matcher.search(text) |
| + res = url_matcher.search(text) |
| if not res: |
| break |
| # Calculate positions of the substring of the URL. |
| @@ -85,6 +87,22 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): |
| text = text[end:] |
| self.AddText(parent, text) |
| + def _AddParagraphs(self, parent, text): |
| + '''Break description into paragraphs and replace URLs with links. |
| + |
| + Args: |
| + parent: The DOM node to which the text will be added. |
| + text: The string to be added. |
| + ''' |
| + if len(text) == 0: |
|
Mattias Nissler (ping if slow)
2015/02/10 14:09:55
nit: This check is no longer needed. The loop belo
peletskyi
2015/02/10 16:12:56
Done.
|
| + return |
| + # Split text into list of paragraphs |
|
Mattias Nissler (ping if slow)
2015/02/10 14:09:55
nit: missing period
peletskyi
2015/02/10 16:12:56
Done.
|
| + entries = text.split('\n\n') |
| + for entry in entries: |
| + # Create a new paragraph node |
|
Mattias Nissler (ping if slow)
2015/02/10 14:09:55
nit: period
peletskyi
2015/02/10 16:12:56
Done.
|
| + paragraph = self.AddElement(parent, 'p') |
| + # Insert text to the paragraph with processing the urls |
|
Mattias Nissler (ping if slow)
2015/02/10 14:09:55
nit: period
peletskyi
2015/02/10 16:12:56
Done.
|
| + self._AddTextWithLinks(paragraph, entry) |
| def _AddStyledElement(self, parent, name, style_ids, attrs=None, text=None): |
| '''Adds an XML element to a parent, with CSS style-sheets included. |
| @@ -114,8 +132,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']) |
| + |
|
Mattias Nissler (ping if slow)
2015/02/10 14:09:55
nit: no reason for a blank line here AFAICT?
peletskyi
2015/02/10 16:12:56
Done.
|
| + # Replace URLs with links and /n with <p>...</p> in the description. |
|
Mattias Nissler (ping if slow)
2015/02/10 14:09:55
nit: I suggested to reword the comment to be clear
peletskyi
2015/02/10 16:12:56
I have "Break description into paragraphs and repl
|
| + self._AddParagraphs(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 +527,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._AddParagraphs(div, note) |
| def _AddPolicyRow(self, parent, policy): |
| '''Adds a row for the policy in the summary table. |
| @@ -597,7 +616,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._AddParagraphs( |
| summary_div, |
| self._GetLocalizedMessage('intro')) |
| self.AddElement(summary_div, 'br') |
| @@ -690,8 +709,6 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): |
| 'ul': 'padding-left: 0px; margin-left: 0px;' |
| } |
| - # A simple regexp to search for URLs. It is enough for now. |
| - self._url_matcher = lazy_re.compile('(http://[^\\s]*[^\\s\\.])') |
| def GetTemplateText(self): |
| # Return the text representation of the main <div> tag. |