Anonymous avatar Anonymous committed bd2eedb

Highlighting numerical lists and fields in reST mode

Comments (0)

Files changed (5)

 ===========
 
 
+- ReST highlighting : July 24, 2006
+
+
 - Showing editor modified status : July 23, 2006
 
 
   Writing ASTs
 
 
-* reST highlighting
-
-
 * What to do when the program has syntax errors for code assists @ 2
 
 
 > Public Release 0.2RC : July 30, 2006
 
 
-* Enhancing syntax highlighting @ 16h
-
-  * Only highlighting the changed region
-  * Extend highlighting region while highlighting if necessay
-  * Highlighting after cut, paste, undo and redo
-  * Use Modified event for updating highlighting only when necessary
-
-
 * Enhancing editor
 
   * Clearing selection if something happens

docs/workingon.txt

-Basic reST Highlighting
-=======================
+Enhancing syntax highlighting @ 16h
+===================================
 
-- Section titles
-- Lists
-- Directives
-- Literal blocks
-* Inline markups
+* Only highlighting the changed region
+* Extend highlighting region while highlighting if necessay
+* Highlighting after cut, paste, undo and redo
+* Use Modified event for updating highlighting only when necessary
 
-  - *emphasis*
-  - **strong emphasis**
-  - ``inline literal``
-  - inline hyperlinks
+Possible solutions
+* Making Highlighting independent of the editor
+* Adding Highlighting.get_highlighting_region(text, index)
+* Pushing up Highlighting.highlights()
+  
 
-- hyperlink definitions
-
-- Adding to runtests
 
 Pre-Release Refactorings
 ========================
 
 Goals:
 
-- Go to definition for packages should go to __init__.py; for FilteredPackages also
 * Do something for modules that can not be found
 * Dotted not found modules
 
 
+Small Features For 0.2 Release
+==============================
+- Numerical lists
+- Fields
+* Better color selection for reST highlighting
+
+
+
 
 Before 0.2 Release
 ==================

rope/highlight.py

         title_pattern = '(?P<overline>^(([^\\w\\s\\d]+)\n))?' + \
                         '(?P<title>.+)\n' + \
                         '(?P<underline>(\\1|[^\\w\\s\\d])+)$'
-        listsign_pattern = '^\\s*(?P<listsign>[*+-])\\s+.+$'
-        directive_pattern = '(?P<directive>\\.\\. \\w+.+::)(\\s+.+)?'
+        listsign_pattern = '^\\s*(?P<listsign>[*+-]|\\d*\\.)(?=\\s+.+$)'
+        directive_pattern = '(?P<directive>\\.\\. \\w+.+::)'
         emphasis_pattern = '(?P<emphasis>\\*[^*\n]+\\*)'
         strongemphasis_pattern = '(?P<strongemphasis>\\*\\*[^*\n]+\\*\\*)'
         literal_pattern = '(?P<literal>``[^`]+``)'
-        interpreted_pattern = '(?P<interpreted>`[^`]+`)(?P<role>:\\w+:)?'
+        interpreted_pattern = '(?P<interpreted>`.+`)(?P<role>:\\w+:)?'
         hyperlink_target_pattern = '(?P<hyperlink_target>\\w+://[^\\s]+)'
-        hyperlink_pattern = '(?P<hyperlink>[^\\s]+_|`.+`_)'
-        hyperlink_definition_pattern = '(?P<hyperlink_definition>\\.\\. _[^\\s:]+:)'
-        all_patterns = title_pattern + '|' + listsign_pattern + '|' + \
-                       directive_pattern + '|' + emphasis_pattern + '|' +\
-                       strongemphasis_pattern + '|' + literal_pattern + '|' + \
-                       hyperlink_pattern + '|' + hyperlink_target_pattern + '|' + \
-                       interpreted_pattern + '|' + hyperlink_definition_pattern
+        hyperlink_pattern = '(?P<hyperlink>[\\w]+_|`[^`]+`_)\\b'
+        hyperlink_definition_pattern = '(?P<hyperlink_definition>\\.\\. _[^\n:]+:)'
+        field_pattern = '^\\s*(?P<field>:[^\n:]+:)'
+        all_patterns = literal_pattern + '|' + hyperlink_pattern + '|' + \
+                       interpreted_pattern + '|' + \
+                       title_pattern + '|' + listsign_pattern + '|' + \
+                       directive_pattern + '|' + emphasis_pattern + '|' + \
+                       strongemphasis_pattern + '|' + \
+                       hyperlink_target_pattern + '|' + field_pattern + '|' + \
+                       hyperlink_definition_pattern
         return re.compile(all_patterns, re.M)
     
     def get_styles(self):
                 'emphasis' : HighlightingStyle(italic=True),
                 'strongemphasis' : HighlightingStyle(bold=True),
                 'literal' : HighlightingStyle(color='#908080'),
-                'interpreted' : HighlightingStyle(color='#008000'),
+                'interpreted' : HighlightingStyle(color='green'),
                 'role' : HighlightingStyle(color='blue'),
                 'hyperlink_target' : HighlightingStyle(color='blue'),
                 'hyperlink' : HighlightingStyle(color='blue'),
-                'hyperlink_definition' : HighlightingStyle(color='blue')}
+                'hyperlink_definition' : HighlightingStyle(color='blue'),
+                'field' : HighlightingStyle(color='purple')}
 
     def highlights(self, editor, start, end):
         text = editor.get(start, end)
             for key, value in match.groupdict().items():
                 if value:
                     a, b = match.span(key)
+#                    print a, b, key
                     yield (editor.get_relative(start, a),
                            editor.get_relative(start, b), key)
 

ropetest/highlighttest.py

     def tearDown(self):
         unittest.TestCase.tearDown(self)
     
-    def assert_in_highlights(self, text, expected):
+    def in_highlights(self, text, expected):
         self.editor.set_text(text)
         start = self.editor.get_start()
         end = self.editor.get_end()
             highlights.append(result)
         expected = (self.editor.get_index(expected[0]), self.editor.get_index(expected[1]),
                     expected[2])
-        self.assertTrue(expected in highlights)
+        return expected in highlights
     
     def test_highlighting_section_titles(self):
         self.assertTrue('title' in self.highlighting.get_styles())
-        self.assert_in_highlights('My Title\n========\n', (0, 8, 'title'))
+        self.assertTrue(self.in_highlights('My Title\n========\n', (0, 8, 'title')))
 
     def test_highlighting_section_titles2(self):
-        self.assert_in_highlights('========\nMy Title\n========\n', (9, 17, 'title'))
+        self.assertTrue(self.in_highlights('========\nMy Title\n========\n', (9, 17, 'title')))
 
     def test_highlighting_section_titles3(self):
-        self.assert_in_highlights('\nMy Title\n========\n', (1, 9, 'title'))
+        self.assertTrue(self.in_highlights('\nMy Title\n========\n', (1, 9, 'title')))
 
     def test_list_signs(self):
         self.assertTrue('listsign' in self.highlighting.get_styles())
-        self.assert_in_highlights('* item # 1\n', (0, 1, 'listsign'))
+        self.assertTrue(self.in_highlights('* item # 1\n', (0, 1, 'listsign')))
 
     def test_list_signs2(self):
-        self.assertTrue('listsign' in self.highlighting.get_styles())
-        self.assert_in_highlights('- item # 1\n', (0, 1, 'listsign'))
+        self.assertTrue(self.in_highlights('- item # 1\n', (0, 1, 'listsign')))
+
+    def test_ordered_lists(self):
+        self.assertTrue(self.in_highlights('1. item # 1\n', (0, 2, 'listsign')))
 
     def test_directives(self):
         self.assertTrue('directive' in self.highlighting.get_styles())
-        self.assert_in_highlights('.. note:: This is a note\n', (0, 9, 'directive'))
+        self.assertTrue(self.in_highlights('.. note:: This is a note\n', (0, 9, 'directive')))
 
     def test_emphasis(self):
         self.assertTrue('emphasis' in self.highlighting.get_styles())
-        self.assert_in_highlights('*important*', (0, 11, 'emphasis'))
+        self.assertTrue(self.in_highlights('*important*', (0, 11, 'emphasis')))
 
     def test_strong_emphasis(self):
         self.assertTrue('strongemphasis' in self.highlighting.get_styles())
-        self.assert_in_highlights('**important**', (0, 13, 'strongemphasis'))
+        self.assertTrue(self.in_highlights('**important**', (0, 13, 'strongemphasis')))
 
     def test_strong_emphasis(self):
         self.assertTrue('literal' in self.highlighting.get_styles())
-        self.assert_in_highlights('``rope``', (0, 8, 'literal'))
+        self.assertTrue(self.in_highlights('``rope``', (0, 8, 'literal')))
 
     def test_interpreted(self):
         self.assertTrue('interpreted' in self.highlighting.get_styles())
-        self.assert_in_highlights('`rope`', (0, 6, 'interpreted'))
+        self.assertTrue(self.in_highlights('`rope`', (0, 6, 'interpreted')))
 
     def test_role(self):
         self.assertTrue('role' in self.highlighting.get_styles())
-        self.assert_in_highlights('`rope`:emphasis:', (6, 16, 'role'))
+        self.assertTrue(self.in_highlights('`rope`:emphasis:', (6, 16, 'role')))
 
     def test_hyperlink_target(self):
         self.assertTrue('hyperlink_target' in self.highlighting.get_styles())
-        self.assert_in_highlights('http://rope.sf.net/index.html', (0, 29, 'hyperlink_target'))
+        self.assertTrue(self.in_highlights('http://rope.sf.net/index.html',
+                                           (0, 29, 'hyperlink_target')))
 
     def test_hyperlink(self):
         self.assertTrue('hyperlink' in self.highlighting.get_styles())
-        self.assert_in_highlights('rope_', (0, 5, 'hyperlink'))
+        self.assertTrue(self.in_highlights('rope_', (0, 5, 'hyperlink')))
 
     def test_hyperlink2(self):
-        self.assert_in_highlights('`rope homepage`_', (0, 16, 'hyperlink'))
+        self.assertTrue(self.in_highlights('`rope homepage`_', (0, 16, 'hyperlink')))
+
+    def test_hyperlink3(self):
+        self.assertFalse(self.in_highlights('rope_homepage', (0, 5, 'hyperlink')))
+
+    def test_hyperlink_in_multilines(self):
+        self.assertTrue(self.in_highlights('`rope\nhomepage`_', (0, 16, 'hyperlink')))
 
     def test_hyperlink_definition(self):
         self.assertTrue('hyperlink_definition' in self.highlighting.get_styles())
-        self.assert_in_highlights('.. _rope: http://rope.sf.net\n', (0, 9, 'hyperlink_definition'))
+        self.assertTrue(self.in_highlights('.. _rope: http://rope.sf.net\n',
+                                           (0, 9, 'hyperlink_definition')))
+
+    def test_hyperlink_definition2(self):
+        self.assertTrue(self.in_highlights('.. _rope homepage: http://rope.sf.net\n', 
+                                           (0, 18, 'hyperlink_definition')))
+
+    def test_highlights_in_lists(self):
+        self.assertTrue(self.in_highlights('* rope_\n', (2, 7, 'hyperlink')))
+
+    def test_highlights_in_lists2(self):
+        self.assertTrue(self.in_highlights('- `rope homepage`_::\n', (2, 18, 'hyperlink')))
+
+    def test_not_highlighting_hyperlinks_in_inline_literals(self):
+        self.assertFalse(self.in_highlights('``rope_``', (2, 7, 'hyperlink')))
+
+    def test_highlighting_fields(self):
+        self.assertTrue('field' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights(':Age: 3 months', (0, 5, 'field')))
 
 
 def suite():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.