changeset 744:312a2842b2b8

plugins text-syntaxes: added a default value to use the current user syntax in convert
author souliane <souliane@mailoo.org>
date Mon, 09 Dec 2013 15:31:07 +0100
parents 5a131930348d
children 812dc38c0094
files frontends/src/constants.py src/plugins/plugin_misc_text_syntaxes.py
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/constants.py	Thu Nov 28 21:27:18 2013 +0100
+++ b/frontends/src/constants.py	Mon Dec 09 15:31:07 2013 +0100
@@ -55,3 +55,7 @@
 
 class Const(object):
     PRESENCE = getPresence()
+
+    # from plugin_misc_text_syntaxes
+    _SYNTAX_XHTML = "XHTML"
+    _SYNTAX_CURRENT = "@CURRENT@"
--- a/src/plugins/plugin_misc_text_syntaxes.py	Thu Nov 28 21:27:18 2013 +0100
+++ b/src/plugins/plugin_misc_text_syntaxes.py	Mon Dec 09 15:31:07 2013 +0100
@@ -31,6 +31,8 @@
 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 @@
             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 @@
 
         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)