comparison sat/plugins/plugin_misc_text_syntaxes.py @ 3715:b9718216a1c0 0.9

merge bookmark 0.9
author Goffi <goffi@goffi.org>
date Wed, 01 Dec 2021 16:13:31 +0100
parents 09f5ac48ffe3
children 33d75cd3c371
comparison
equal deleted inserted replaced
3714:af09b5aaa5d7 3715:b9718216a1c0
164 OPT_HIDDEN = "HIDDEN" 164 OPT_HIDDEN = "HIDDEN"
165 OPT_NO_THREAD = "NO_THREAD" 165 OPT_NO_THREAD = "NO_THREAD"
166 SYNTAX_XHTML = _SYNTAX_XHTML 166 SYNTAX_XHTML = _SYNTAX_XHTML
167 SYNTAX_MARKDOWN = "markdown" 167 SYNTAX_MARKDOWN = "markdown"
168 SYNTAX_TEXT = "text" 168 SYNTAX_TEXT = "text"
169 syntaxes = {}
170 # default_syntax must be lower case 169 # default_syntax must be lower case
171 default_syntax = SYNTAX_XHTML 170 default_syntax = SYNTAX_XHTML
172 171
173 params = """
174 <params>
175 <individual>
176 <category name="%(category_name)s" label="%(category_label)s">
177 <param name="%(name)s" label="%(label)s" type="list" security="0">
178 %(options)s
179 </param>
180 </category>
181 </individual>
182 </params>
183 """
184
185 params_data = {
186 "category_name": CATEGORY,
187 "category_label": _(CATEGORY),
188 "name": NAME,
189 "label": _(NAME),
190 "syntaxes": syntaxes,
191 }
192 172
193 def __init__(self, host): 173 def __init__(self, host):
194 log.info(_("Text syntaxes plugin initialization")) 174 log.info(_("Text syntaxes plugin initialization"))
195 self.host = host 175 self.host = host
176 self.syntaxes = {}
177
178 self.params = """
179 <params>
180 <individual>
181 <category name="%(category_name)s" label="%(category_label)s">
182 <param name="%(name)s" label="%(label)s" type="list" security="0">
183 %(options)s
184 </param>
185 </category>
186 </individual>
187 </params>
188 """
189
190 self.params_data = {
191 "category_name": CATEGORY,
192 "category_label": _(CATEGORY),
193 "name": NAME,
194 "label": _(NAME),
195 "syntaxes": self.syntaxes,
196 }
197
196 self.addSyntax( 198 self.addSyntax(
197 self.SYNTAX_XHTML, 199 self.SYNTAX_XHTML,
198 lambda xhtml: defer.succeed(xhtml), 200 lambda xhtml: defer.succeed(xhtml),
199 lambda xhtml: defer.succeed(xhtml), 201 lambda xhtml: defer.succeed(xhtml),
200 TextSyntaxes.OPT_NO_THREAD, 202 TextSyntaxes.OPT_NO_THREAD,
262 if xml_tools.cleanXHTML is None: 264 if xml_tools.cleanXHTML is None:
263 log.debug("Installing cleaning method") 265 log.debug("Installing cleaning method")
264 xml_tools.cleanXHTML = self.cleanXHTML 266 xml_tools.cleanXHTML = self.cleanXHTML
265 267
266 def _updateParamOptions(self): 268 def _updateParamOptions(self):
267 data_synt = TextSyntaxes.syntaxes 269 data_synt = self.syntaxes
268 default_synt = TextSyntaxes.default_syntax 270 default_synt = TextSyntaxes.default_syntax
269 syntaxes = [] 271 syntaxes = []
270 272
271 for syntax in list(data_synt.keys()): 273 for syntax in list(data_synt.keys()):
272 flags = data_synt[syntax]["flags"] 274 flags = data_synt[syntax]["flags"]
278 280
279 for syntax in syntaxes: 281 for syntax in syntaxes:
280 selected = 'selected="true"' if syntax == default_synt else "" 282 selected = 'selected="true"' if syntax == default_synt else ""
281 options.append('<option value="%s" %s/>' % (syntax, selected)) 283 options.append('<option value="%s" %s/>' % (syntax, selected))
282 284
283 TextSyntaxes.params_data["options"] = "\n".join(options) 285 self.params_data["options"] = "\n".join(options)
284 self.host.memory.updateParams(TextSyntaxes.params % TextSyntaxes.params_data) 286 self.host.memory.updateParams(self.params % self.params_data)
285 287
286 def getCurrentSyntax(self, profile): 288 def getCurrentSyntax(self, profile):
287 """ Return the selected syntax for the given profile 289 """ Return the selected syntax for the given profile
288 290
289 @param profile: %(doc_profile)s 291 @param profile: %(doc_profile)s
391 syntax_from = syntax_from.lower().strip() 393 syntax_from = syntax_from.lower().strip()
392 if syntax_to == _SYNTAX_CURRENT: 394 if syntax_to == _SYNTAX_CURRENT:
393 syntax_to = self.getCurrentSyntax(profile) 395 syntax_to = self.getCurrentSyntax(profile)
394 else: 396 else:
395 syntax_to = syntax_to.lower().strip() 397 syntax_to = syntax_to.lower().strip()
396 syntaxes = TextSyntaxes.syntaxes 398 syntaxes = self.syntaxes
397 if syntax_from not in syntaxes: 399 if syntax_from not in syntaxes:
398 raise exceptions.NotFound(syntax_from) 400 raise exceptions.NotFound(syntax_from)
399 if syntax_to not in syntaxes: 401 if syntax_to not in syntaxes:
400 raise exceptions.NotFound(syntax_to) 402 raise exceptions.NotFound(syntax_to)
401 d = None 403 d = None
436 "{} and {} are mutually exclusive".format( 438 "{} and {} are mutually exclusive".format(
437 TextSyntaxes.OPT_HIDDEN, TextSyntaxes.OPT_DEFAULT 439 TextSyntaxes.OPT_HIDDEN, TextSyntaxes.OPT_DEFAULT
438 ) 440 )
439 ) 441 )
440 442
441 syntaxes = TextSyntaxes.syntaxes 443 syntaxes = self.syntaxes
442 key = name.lower().strip() 444 key = name.lower().strip()
443 if key in syntaxes: 445 if key in syntaxes:
444 raise exceptions.ConflictError( 446 raise exceptions.ConflictError(
445 "This syntax key already exists: {}".format(key) 447 "This syntax key already exists: {}".format(key)
446 ) 448 )