Files
python-Lektor/new_version_of_mistune.patch
Matej Cepl fd5cdafa42 - Update to 3.3.5:
- Backport #1044. Fixes 404 from admin server for /admin.
  - Backport #1033. Fixes TypeError from click==8.1.3.
  - Back-port #1019: fixes for werkzeug 2.1.0.
- Update to 3.3.2:
  - Enabled the Jinja debug extension when the LEKTOR_DEV env var
    is set to 1 and lektor server is used. (#984)
  - The wording in the LICENSE file was standardized to that of
    the current BSD 3-Clause License. (#972)
  - Fix overzealous HTML-entity escaping of link and image
    attributes. (#989)
  - Fix a bug in make_editor_session when editing non-existant
    pages with a non-primary alt. (#964)
  - Fix the ability to add an initial flowblock to a
    page. (Broken in 3.3.1.)
  - Refactor API views to move business logic back into the Tree
    adapter (#967). This fixes #962.
  - Changed the structure of the URLs used by the GUI single-page
    app (#976). This fixes problems with the "edit" pencil when
    using alternatives (#975), and issues when page ids include
    colons (#610).
  - Other React refactors and fixes (#988).
  - Fix Attachment.url_path when alternatives are in use. There
    is only one copy of each attachment emitted — the url_path
    should always be that corresponding to the primary
    alternative. (#958)
  - Pad.get, if not passed an explicit value for the alt
    parameter, now returns the record for the primary alternative
    rather than the fallback record. Similarly, Pad.root now
    returns the root record for the primary alternative. (#958,

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-Lektor?expand=0&rev=19
2022-07-22 22:48:19 +00:00

115 lines
4.0 KiB
Diff

From 20c01cf12fab27c26d1bb0b66c9dca5904cfa148 Mon Sep 17 00:00:00 2001
From: Evilham <cvs@evilham.com>
Date: Sun, 10 Oct 2021 20:45:50 +0200
Subject: [PATCH 1/5] Support newer mistune versions in addition to older ones
It looks like lepture has been busy and mistune 2.0.0 is about to be
released, there is already some software that depends on its alpha/rc
versions and rather than backporting that, it makes more sense to
prepare Lektor to be compatible with the newer version.
This patch aims to introduce minimal changes to achieve that while
keeping compatibility with mistune 0.8.X.
---
lektor/markdown.py | 68 +++++++++++++++++++++++++++++++++++------------------
setup.cfg | 2 -
2 files changed, 46 insertions(+), 24 deletions(-)
--- a/lektor/markdown.py
+++ b/lektor/markdown.py
@@ -14,30 +14,50 @@ _markdown_cache = threading.local()
def escape(text: str) -> str:
return mistune.escape(text, quote=True)
+_old_mistune = int(mistune.__version__.split(".", maxsplit=1)[0]) < 2
-class ImprovedRenderer(mistune.Renderer):
- def link(self, link, title, text):
- if self.record is not None:
- url = url_parse(link)
- if not url.scheme:
- link = self.record.url_to("!" + link, base_url=get_ctx().base_url)
- link = escape(link)
- if not title:
- return '<a href="%s">%s</a>' % (link, text)
- title = escape(title)
- return '<a href="%s" title="%s">%s</a>' % (link, title, text)
+if _old_mistune:
- def image(self, src, title, text):
- if self.record is not None:
- url = url_parse(src)
- if not url.scheme:
- src = self.record.url_to("!" + src, base_url=get_ctx().base_url)
- src = escape(src)
- text = escape(text)
- if title:
- title = escape(title)
- return '<img src="%s" alt="%s" title="%s">' % (src, text, title)
- return '<img src="%s" alt="%s">' % (src, text)
+ class ImprovedRenderer(mistune.Renderer):
+ def link(self, link, title, text):
+ return _render_link(link, text, title, record=self.record)
+
+ def image(self, src, title, text):
+ return _render_image(src, text, title, record=self.record)
+
+else:
+
+ class ImprovedRenderer(mistune.HTMLRenderer):
+ def link(self, link, text=None, title=None):
+ return _render_link(link, text, title, record=self.record)
+
+ def image(self, src, alt=None, title=None):
+ return _render_image(src, alt, title, record=self.record)
+
+
+def _render_link(link, text=None, title=None, record=None):
+ if record is not None:
+ url = url_parse(link)
+ if not url.scheme:
+ link = record.url_to("!" + link, base_url=get_ctx().base_url)
+ link = escape(link)
+ if not title:
+ return '<a href="%s">%s</a>' % (link, text)
+ title = escape(title)
+ return '<a href="%s" title="%s">%s</a>' % (link, title, text)
+
+
+def _render_image(src, alt="", title=None, record=None):
+ if record is not None:
+ url = url_parse(src)
+ if not url.scheme:
+ src = record.url_to("!" + src, base_url=get_ctx().base_url)
+ src = escape(src)
+ alt = escape(alt)
+ if title:
+ title = escape(title)
+ return '<img src="%s" alt="%s" title="%s">' % (src, alt, title)
+ return '<img src="%s" alt="%s">' % (src, alt)
class MarkdownConfig:
@@ -59,7 +79,9 @@ def make_markdown(env):
env.plugin_controller.emit("markdown-config", config=cfg)
renderer = cfg.make_renderer()
env.plugin_controller.emit("markdown-lexer-config", config=cfg, renderer=renderer)
- return mistune.Markdown(renderer, **cfg.options)
+ if _old_mistune:
+ return mistune.Markdown(renderer, **cfg.options)
+ return mistune.create_markdown(renderer=renderer, **cfg.options)
def markdown_to_html(text, record=None):
--- a/setup.cfg
+++ b/setup.cfg
@@ -37,7 +37,7 @@ install_requires =
Flask
inifile>=0.4.1
Jinja2>=3.0
- mistune>=0.7.0,<2
+ mistune>=0.7.0,<3
pip
python-slugify
requests[security]