cli (blog/preview): Fix preview:

- configuration handling was not updated
- there was a typo in `open_cb`
This commit is contained in:
Goffi 2026-04-24 17:38:19 +02:00
commit 9ffb729b8c

View file

@ -55,7 +55,6 @@ SYNTAX_EXT = {
}
CONF_SYNTAX_EXT = "syntax_ext_dict"
BLOG_TMP_DIR = "blog"
# key to remove from metadata tmp file if they exist
KEY_TO_REMOVE_METADATA = (
@ -93,21 +92,24 @@ RE_ATTACHMENT_METADATA = re.compile(r"^(?P<key>[a-z_]+)=(?P<value>.*)")
ALLOWER_ATTACH_MD_KEY = ("desc", "media_type", "external")
async def guess_syntax_from_path(host, sat_conf, path):
"""Return syntax guessed according to filename extension
async def guess_syntax_from_path(host: "base.LiberviaCli", path: Path) -> str:
"""Guess syntax to use according to a file's name extension.
@param sat_conf(ConfigParser.ConfigParser): instance opened on sat configuration
@param path(str): path to the content file
@return(unicode): syntax to use
If no matching extension is found, fall back to the profile's default
composition syntax.
@param host: CLI host
@param path: path to the content file
@return: syntax name to use
"""
# we first try to guess syntax with extension
ext = os.path.splitext(path)[1][1:] # we get extension without the '.'
# Try to match the file extension against known syntaxes
ext = os.path.splitext(path)[1][1:] # strip the leading dot
if ext:
for k, v in SYNTAX_EXT.items():
if k and ext == v:
return k
for syntax, ext_name in SYNTAX_EXT.items():
if syntax and ext == ext_name:
return syntax
# if not found, we use current syntax
# Extension not found or empty, fall back to profile default
return await host.bridge.param_get_a("Syntax", "Composition", "value", host.profile)
@ -952,7 +954,7 @@ class Preview(base.CommandBase, common.BaseEdit):
if self.open_cb_cmd is None:
open_cb = self.show_preview
else:
open_cp = self.open_preview_ext
open_cb = self.open_preview_ext
self.update_cb_cmd = self.cli_settings.blog_preview_update_cmd
if self.update_cb_cmd is None:
@ -971,7 +973,7 @@ class Preview(base.CommandBase, common.BaseEdit):
self.host.quit(C.EXIT_NOT_FOUND)
self.syntax = await guess_syntax_from_path(
self.host, sat_conf, self.content_file_path
self.host, self.content_file_path
)
# at this point the syntax is converted, we can display the preview