QScintilla/MarkupProviders/RestructuredTextProvider.py

changeset 5398
1f4509cf8f35
parent 5397
fee5485e67f4
child 5402
ce21a78a5fcf
equal deleted inserted replaced
5397:fee5485e67f4 5398:1f4509cf8f35
19 def __init__(self): 19 def __init__(self):
20 """ 20 """
21 Constructor 21 Constructor
22 """ 22 """
23 super(RestructuredTextProvider, self).__init__() 23 super(RestructuredTextProvider, self).__init__()
24
25 self.__headerChars = ["=", "-", "~", "+", "#", "^"]
26
27 def kind(self):
28 """
29 Public method to get the markup kind.
30
31 @return string with markup kind
32 @rtype str
33 """
34 return "rest"
24 35
25 def hasBold(self): 36 def hasBold(self):
26 """ 37 """
27 Public method to indicate the availability of bold markup. 38 Public method to indicate the availability of bold markup.
28 39
38 @return flag indicating the availability of italic markup 49 @return flag indicating the availability of italic markup
39 @rtype bool 50 @rtype bool
40 """ 51 """
41 return True 52 return True
42 53
54 def headerLevels(self):
55 """
56 Public method to determine the available header levels.
57
58 @return supported header levels
59 @rtype int
60 """
61 return len(self.__headerChars)
62
43 def bold(self, editor): 63 def bold(self, editor):
44 """ 64 """
45 Public method to generate bold text. 65 Public method to generate bold text.
46 66
47 @param editor reference to the editor to work on 67 @param editor reference to the editor to work on
55 75
56 @param editor reference to the editor to work on 76 @param editor reference to the editor to work on
57 @type Editor 77 @type Editor
58 """ 78 """
59 self.__insertMarkup("*", editor) 79 self.__insertMarkup("*", editor)
80
81 def header(self, editor, level):
82 """
83 Public method to generate a header.
84
85 @param editor reference to the editor to work on
86 @type Editor
87 @param level header level
88 @type int
89 """
90 if editor is None or level > self.headerLevels():
91 return
92
93 editor.beginUndoAction()
94 cline, cindex = editor.getCursorPosition()
95 lineSeparator = editor.getLineSeparator()
96 if not editor.text(cline).endswith(lineSeparator):
97 editor.insertAt(lineSeparator, cline, len(editor.text(cline)))
98 lineLength = len(editor.text(cline)) - len(lineSeparator)
99 editor.insertAt(
100 lineLength * self.__headerChars[level - 1] + lineSeparator,
101 cline + 1, 0)
102 editor.setCursorPosition(cline + 2, 0)
103 editor.endUndoAction()
60 104
61 def __insertMarkup(self, markup, editor): 105 def __insertMarkup(self, markup, editor):
62 """ 106 """
63 Private method to insert the specified markup. 107 Private method to insert the specified markup.
64 108

eric ide

mercurial