plugins text-syntaxes: added a default value to use the current user syntax in convert
This commit is contained in:
parent
89c2519ae7
commit
7d3f74ef62
2 changed files with 13 additions and 2 deletions
|
|
@ -31,6 +31,8 @@ import re
|
|||
CATEGORY = "Composition"
|
||||
NAME = "Syntax"
|
||||
_SYNTAX_XHTML = "XHTML"
|
||||
_SYNTAX_CURRENT = "@CURRENT@"
|
||||
|
||||
# TODO: check/adapt following list
|
||||
STYLES_WHITELIST = ["azimuth", "background-color", "border-bottom-color", "border-collapse", "border-color", "border-left-color", "border-right-color", "border-top-color", "clear", "color", "cursor", "direction", "display", "elevation", "float", "font", "font-family", "font-size", "font-style", "font-variant", "font-weight", "height", "letter-spacing", "line-height", "overflow", "pause", "pause-after", "pause-before", "pitch", "pitch-range", "richness", "speak", "speak-header", "speak-numeral", "speak-punctuation", "speech-rate", "stress", "text-align", "text-decoration", "text-indent", "unicode-bidi", "vertical-align", "voice-family", "volume", "white-space", "width"] # based on feedparser list (http://pythonhosted.org/feedparser/html-sanitization.html)
|
||||
|
||||
|
|
@ -101,7 +103,7 @@ class TextSyntaxes(object):
|
|||
self.addSyntax(self.SYNTAX_MARKDOWN, markdown.markdown, html2text.html2text, [TextSyntaxes.OPT_DEFAULT])
|
||||
except ImportError:
|
||||
warning("markdown or html2text not found, can't use Markdown syntax")
|
||||
host.bridge.addMethod("syntaxConvert", ".plugin", in_sign='sssb', out_sign='s',
|
||||
host.bridge.addMethod("syntaxConvert", ".plugin", in_sign='sssbs', out_sign='s',
|
||||
async=True, method=self.convert)
|
||||
|
||||
def _updateParamOptions(self):
|
||||
|
|
@ -175,14 +177,19 @@ class TextSyntaxes(object):
|
|||
|
||||
return deferToThread(blocking_cleaning, xhtml)
|
||||
|
||||
def convert(self, text, syntax_from, syntax_to=_SYNTAX_XHTML, safe=True):
|
||||
def convert(self, text, syntax_from, syntax_to=_SYNTAX_XHTML, safe=True, profile=None):
|
||||
""" Convert a text between two syntaxes
|
||||
@param text: text to convert
|
||||
@param syntax_from: source syntax (e.g. "markdown")
|
||||
@param syntax_to: dest syntax (e.g.: "XHTML")
|
||||
@param safe: clean resulting XHTML to avoid malicious code if True
|
||||
@param profile: needed only when syntax_from or syntax_to is set to _SYNTAX_CURRENT
|
||||
@return: converted text """
|
||||
|
||||
if syntax_from == _SYNTAX_CURRENT:
|
||||
syntax_from = self.getCurrentSyntax(profile)
|
||||
if syntax_to == _SYNTAX_CURRENT:
|
||||
syntax_to = self.getCurrentSyntax(profile)
|
||||
syntaxes = TextSyntaxes.params_data['syntaxes']
|
||||
if syntax_from not in syntaxes:
|
||||
raise UnknownSyntax(syntax_from)
|
||||
|
|
|
|||
Loading…
Reference in a new issue