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
This commit is contained in:
Goffi 2017-07-13 20:55:35 +02:00
commit da6bf7123a

View file

@ -40,7 +40,7 @@ __commands__ = ["Blog"]
# 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 @@ class Edit(base.CommandBase, BlogCommon, common.BaseEdit):
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 @@ class Edit(base.CommandBase, BlogCommon, common.BaseEdit):
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 @@ class Edit(base.CommandBase, BlogCommon, common.BaseEdit):
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 @@ class Edit(base.CommandBase, BlogCommon, common.BaseEdit):
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)