From 78afa5d9ba2852a95330447d84613a4a699ef495 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Wed, 26 Jun 2024 14:58:38 -0300 Subject: [PATCH] Make it work with latest misaka --- v8/misaka/misaka.plugin | 2 +- v8/misaka/{misaka.py => misaka_compiler.py} | 40 +++++++++++++-------- 2 files changed, 27 insertions(+), 15 deletions(-) rename v8/misaka/{misaka.py => misaka_compiler.py} (78%) diff --git a/v8/misaka/misaka.plugin b/v8/misaka/misaka.plugin index d84ba71e..57aaaed1 100644 --- a/v8/misaka/misaka.plugin +++ b/v8/misaka/misaka.plugin @@ -1,6 +1,6 @@ [Core] Name = misaka -Module = misaka +Module = misaka_compiler [Nikola] PluginCategory = PageCompiler diff --git a/v8/misaka/misaka.py b/v8/misaka/misaka_compiler.py similarity index 78% rename from v8/misaka/misaka.py rename to v8/misaka/misaka_compiler.py index 52333c5d..c9240537 100644 --- a/v8/misaka/misaka.py +++ b/v8/misaka/misaka_compiler.py @@ -58,38 +58,50 @@ class CompileMisaka(PageCompiler): def __init__(self, *args, **kwargs): super(CompileMisaka, self).__init__(*args, **kwargs) if misaka is not None: - self.ext = misaka.EXT_FENCED_CODE | misaka.EXT_STRIKETHROUGH | misaka.EXT_FOOTNOTES | \ - misaka.EXT_AUTOLINK | misaka.EXT_NO_INTRA_EMPHASIS | misaka.EXT_HIGHLIGHT - - def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None): + self.ext = ( + misaka.api.EXT_FENCED_CODE + | misaka.api.EXT_STRIKETHROUGH + | misaka.api.EXT_FOOTNOTES + | misaka.api.EXT_AUTOLINK + | misaka.api.EXT_NO_INTRA_EMPHASIS + | misaka.api.EXT_HIGHLIGHT + ) + + def compile_string( + self, data, source_path=None, is_two_file=True, post=None, lang=None + ): """Compile the source file into HTML strings (with shortcode support). Returns a tuple of at least two elements: HTML string [0] and shortcode dependencies [last]. """ if misaka is None: - req_missing(['misaka'], 'build this site (compile with misaka)') + req_missing(["misaka"], "build this site (compile with misaka)") if not is_two_file: _, data = self.split_metadata(data, post, lang) new_data, shortcodes = sc.extract_shortcodes(data) output = misaka.html(new_data, extensions=self.ext) - output, shortcode_deps = self.site.apply_shortcodes_uuid(output, shortcodes, filename=source_path, extra_context={'post': post}) + output, shortcode_deps = self.site.apply_shortcodes_uuid( + output, shortcodes, filename=source_path, extra_context={"post": post} + ) return output, shortcode_deps def compile(self, source, dest, is_two_file=True, post=None, lang=None): """Compile the source file into HTML and save as dest.""" if misaka is None: - req_missing(['misaka'], 'build this site (compile with misaka)') + req_missing(["misaka"], "build this site (compile with misaka)") makedirs(os.path.dirname(dest)) with codecs.open(dest, "w+", "utf8") as out_file: with codecs.open(source, "r", "utf8") as in_file: data = in_file.read() - output, shortcode_deps = self.compile_string(data, source, is_two_file, post, lang) + output, shortcode_deps = self.compile_string( + data, source, is_two_file, post, lang + ) out_file.write(output) if post is None: if shortcode_deps: self.logger.error( - "Cannot save dependencies for post {0} (post unknown)", - source) + "Cannot save dependencies for post {0} (post unknown)", source + ) else: post._depfile[dest] += shortcode_deps @@ -99,11 +111,11 @@ def create_post(self, path, content=None, onefile=False, is_page=False, **kw): metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) - if not content.endswith('\n'): - content += '\n' + if not content.endswith("\n"): + content += "\n" with codecs.open(path, "wb+", "utf8") as fd: if onefile: - fd.write('\n\n') + fd.write("\n-->\n\n") fd.write(content)