changeset 2325:760df3a58c24

jp (blog/edit): syntax modifications: - adapted to new behaviour (keys which are names in lower case en stripped are now used) - added --syntax so force a specific syntax. If not used, profile's default syntax will be used
author Goffi <goffi@goffi.org>
date Thu, 13 Jul 2017 20:55:35 +0200
parents fe922e6fabd4
children 91a14dab924d
files frontends/src/jp/cmd_blog.py
diffstat 1 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_blog.py	Thu Jul 13 20:53:51 2017 +0200
+++ b/frontends/src/jp/cmd_blog.py	Thu Jul 13 20:55:35 2017 +0200
@@ -40,7 +40,7 @@
 # extensions to use with known syntaxes
 SYNTAX_EXT = {
     '': 'txt', # used when the syntax is not found
-    "XHTML": "xhtml",
+    "xhtml": "xhtml",
     "markdown": "md"
     }
 
@@ -286,6 +286,7 @@
         self.parser.add_argument("-T", '--title', type=base.unicode_decoder, help=_(u"title of the item"))
         self.parser.add_argument("-t", '--tag', type=base.unicode_decoder, action='append', help=_(u"tag (category) of your item"))
         self.parser.add_argument("--no-comment", action='store_true', help=_(u"disable comments"))
+        self.parser.add_argument("-S", '--syntax', type=base.unicode_decoder, help=_(u"syntax to use (default: get profile's default syntax)"))
         common.BaseEdit.add_parser_options(self)
 
     def buildMetadataFile(self, content_file_path, mb_data=None):
@@ -352,7 +353,11 @@
         self.runEditor("blog_editor_args", content_file_path, content_file_obj, meta_file_path=meta_file_path, meta_ori=meta_ori)
 
     def publish(self, content, mb_data):
-        mb_data['content_rich'] =  content
+        if self.args.syntax is None:
+            # default syntax has been used
+            mb_data['content_rich'] =  content
+        else:
+            mb_data['content_xhtml'] = self.host.bridge.syntaxConvert(content, self.current_syntax, 'XHTML', False, self.profile)
 
         if self.pubsub_item is not None:
             mb_data['id'] = self.pubsub_item
@@ -362,7 +367,8 @@
 
     def getTmpSuff(self):
         # we get current syntax to determine file extension
-        self.current_syntax = self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile)
+        if self.current_syntax is None:
+            self.current_syntax = self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile)
         return SYNTAX_EXT.get(self.current_syntax, SYNTAX_EXT[''])
 
     def getItemData(self, service, node, item):
@@ -381,7 +387,15 @@
     def start(self):
         # if there are user defined extension, we use them
         SYNTAX_EXT.update(config.getConfig(self.sat_conf, 'jp', CONF_SYNTAX_EXT, {}))
-        self.current_syntax = None
+        self.current_syntax = self.args.syntax
+        if self.current_syntax is not None:
+            try:
+                self.current_syntax = self.args.syntax = self.host.bridge.syntaxGet(self.current_syntax)
+            except Exception as e:
+                if "NotFound" in unicode(e):  # FIXME: there is not good way to check bridge errors
+                    self.parser.error(_(u"unknown syntax requested ({syntax})").format(syntax=self.args.syntax))
+                else:
+                    raise e
 
         self.pubsub_service, self.pubsub_node, self.pubsub_item, content_file_path, content_file_obj, mb_data = self.getItemPath(self.args.item)