QScintilla/MarkupProviders/HtmlProvider.py

changeset 5404
6b19ad5470a3
parent 5402
ce21a78a5fcf
child 5407
f833f89571b8
equal deleted inserted replaced
5403:d6b43ecf2488 5404:6b19ad5470a3
6 """ 6 """
7 Module implementing the HTML markup provider. 7 Module implementing the HTML markup provider.
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11
12 from PyQt5.QtWidgets import QDialog
11 13
12 from .MarkupBase import MarkupBase 14 from .MarkupBase import MarkupBase
13 15
14 16
15 class HtmlProvider(MarkupBase): 17 class HtmlProvider(MarkupBase):
121 123
122 @param editor reference to the editor to work on 124 @param editor reference to the editor to work on
123 @type Editor 125 @type Editor
124 """ 126 """
125 self.__insertMarkup("code", editor) 127 self.__insertMarkup("code", editor)
128
129 def hasCodeBlock(self):
130 """
131 Public method to indicate the availability of code block markup.
132
133 @return flag indicating the availability of code block markup
134 @rtype bool
135 """
136 return True
137
138 def codeBlock(self, editor):
139 """
140 Public method to generate code block text.
141
142 @param editor reference to the editor to work on
143 @type Editor
144 """
145 if editor is None:
146 return
147
148 lineSeparator = editor.getLineSeparator()
149 editor.beginUndoAction()
150 if editor.hasSelectedText():
151 newText = "<pre><code>{0}{1}</code></pre>{0}".format(
152 lineSeparator, editor.selectedText())
153 editor.replaceSelectedText(newText)
154 else:
155 editor.insert("<pre><code>{0}{0}</code></pre>{0}".format(
156 lineSeparator))
157 cline, cindex = editor.getCursorPosition()
158 editor.setCursorPosition(cline + 1, 0)
159 editor.endUndoAction()
126 160
127 def __insertMarkup(self, markup, editor): 161 def __insertMarkup(self, markup, editor):
128 """ 162 """
129 Private method to insert the specified markup. 163 Private method to insert the specified markup.
130 164
147 else: 181 else:
148 editor.insert("<{0}></{0}>".format(markup)) 182 editor.insert("<{0}></{0}>".format(markup))
149 cline, cindex = editor.getCursorPosition() 183 cline, cindex = editor.getCursorPosition()
150 editor.setCursorPosition(cline, cindex + len(markup) + 2) 184 editor.setCursorPosition(cline, cindex + len(markup) + 2)
151 editor.endUndoAction() 185 editor.endUndoAction()
186
187 def hasHyperlink(self):
188 """
189 Public method to indicate the availability of hyperlink markup.
190
191 @return flag indicating the availability of hyperlink markup
192 @rtype bool
193 """
194 return True
195
196 def hyperlink(self, editor):
197 """
198 Public method to generate hyperlink text.
199
200 @param editor reference to the editor to work on
201 @type Editor
202 """
203 from .HyperlinkMarkupDialog import HyperlinkMarkupDialog
204 dlg = HyperlinkMarkupDialog(True, False)
205 if dlg.exec_() == QDialog.Accepted:
206 text, target, title = dlg.getData()
207 if not text:
208 text = target
209
210 if title:
211 link = '<a href="{0}" title="{2}">{1}</a>'.format(
212 target, text, title)
213 else:
214 link = '<a href="{0}">{1}</a>'.format(target, text)
215
216 editor.beginUndoAction()
217 cline, cindex = editor.getCursorPosition()
218 editor.insert(link)
219 editor.setCursorPosition(cline, cindex + len(link))
220 editor.endUndoAction()
221
222 def hasLine(self):
223 """
224 Public method to indicate the availability of a horizontal line markup.
225
226 @return flag indicating the availability of a horizontal line markup
227 @rtype bool
228 """
229 return True
230
231 def line(self, editor):
232 """
233 Public method to generate a horizontal line text.
234
235 @param editor reference to the editor to work on
236 @type Editor
237 """
238 if editor is None:
239 return
240
241 editor.beginUndoAction()
242 markup = "<hr />"
243 editor.insert(markup)
244 cline, cindex = editor.getCursorPosition()
245 editor.setCursorPosition(cline, cindex + len(markup))
246 editor.endUndoAction()

eric ide

mercurial