127 |
129 |
128 @param editor reference to the editor to work on |
130 @param editor reference to the editor to work on |
129 @type Editor |
131 @type Editor |
130 """ |
132 """ |
131 self.__insertMarkup("`", editor) |
133 self.__insertMarkup("`", editor) |
|
134 |
|
135 def hasCodeBlock(self): |
|
136 """ |
|
137 Public method to indicate the availability of code block markup. |
|
138 |
|
139 @return flag indicating the availability of code block markup |
|
140 @rtype bool |
|
141 """ |
|
142 return True |
|
143 |
|
144 def codeBlock(self, editor): |
|
145 """ |
|
146 Public method to generate code block text. |
|
147 |
|
148 @param editor reference to the editor to work on |
|
149 @type Editor |
|
150 """ |
|
151 if editor is None: |
|
152 return |
|
153 |
|
154 lineSeparator = editor.getLineSeparator() |
|
155 editor.beginUndoAction() |
|
156 if editor.hasSelectedText(): |
|
157 newText = "```{0}{1}```{0}".format( |
|
158 lineSeparator, editor.selectedText()) |
|
159 editor.replaceSelectedText(newText) |
|
160 else: |
|
161 editor.insert("```{0}{0}```{0}".format(lineSeparator)) |
|
162 cline, cindex = editor.getCursorPosition() |
|
163 editor.setCursorPosition(cline + 1, 0) |
|
164 editor.endUndoAction() |
132 |
165 |
133 def __insertMarkup(self, markup, editor): |
166 def __insertMarkup(self, markup, editor): |
134 """ |
167 """ |
135 Private method to insert the specified markup. |
168 Private method to insert the specified markup. |
136 |
169 |
153 else: |
186 else: |
154 editor.insert(2 * markup) |
187 editor.insert(2 * markup) |
155 cline, cindex = editor.getCursorPosition() |
188 cline, cindex = editor.getCursorPosition() |
156 editor.setCursorPosition(cline, cindex + len(markup)) |
189 editor.setCursorPosition(cline, cindex + len(markup)) |
157 editor.endUndoAction() |
190 editor.endUndoAction() |
|
191 |
|
192 def hasHyperlink(self): |
|
193 """ |
|
194 Public method to indicate the availability of hyperlink markup. |
|
195 |
|
196 @return flag indicating the availability of hyperlink markup |
|
197 @rtype bool |
|
198 """ |
|
199 return True |
|
200 |
|
201 def hyperlink(self, editor): |
|
202 """ |
|
203 Public method to generate hyperlink text. |
|
204 |
|
205 @param editor reference to the editor to work on |
|
206 @type Editor |
|
207 """ |
|
208 from .HyperlinkMarkupDialog import HyperlinkMarkupDialog |
|
209 dlg = HyperlinkMarkupDialog(False, True) |
|
210 if dlg.exec_() == QDialog.Accepted: |
|
211 text, target, title = dlg.getData() |
|
212 |
|
213 link = "[{0}]".format(text) |
|
214 if target and title: |
|
215 link = '{0}({1} "{2}")'.format(link, target, title) |
|
216 elif target: |
|
217 link = '{0}({1})'.format(link, target) |
|
218 elif title: |
|
219 link = '{0}("{1}")'.format(link, title) |
|
220 |
|
221 editor.beginUndoAction() |
|
222 cline, cindex = editor.getCursorPosition() |
|
223 editor.insert(link) |
|
224 editor.setCursorPosition(cline, cindex + len(link)) |
|
225 editor.endUndoAction() |
|
226 |
|
227 def hasLine(self): |
|
228 """ |
|
229 Public method to indicate the availability of a horizontal line markup. |
|
230 |
|
231 @return flag indicating the availability of a horizontal line markup |
|
232 @rtype bool |
|
233 """ |
|
234 return True |
|
235 |
|
236 def line(self, editor): |
|
237 """ |
|
238 Public method to generate a horizontal line text. |
|
239 |
|
240 @param editor reference to the editor to work on |
|
241 @type Editor |
|
242 """ |
|
243 if editor is None: |
|
244 return |
|
245 |
|
246 lineSeparator = editor.getLineSeparator() |
|
247 editor.beginUndoAction() |
|
248 markup = "{0}-----{0}{0}".format(lineSeparator) |
|
249 editor.insert(markup) |
|
250 cline, cindex = editor.getCursorPosition() |
|
251 editor.setCursorPosition(cline + 3, 0) |
|
252 editor.endUndoAction() |