|
1 |
| -import re |
2 | 1 | from urllib.parse import urlparse
|
3 | 2 |
|
4 | 3 | from django.conf import settings
|
|
25 | 24 | }
|
26 | 25 | BLOG_DOCUTILS_SETTINGS.update(getattr(settings, "BLOG_DOCUTILS_SETTINGS", {}))
|
27 | 26 |
|
28 |
| -# List copied from: |
29 |
| -# https://github.com/Python-Markdown/markdown/blob/3.8/markdown/core.py#L112 |
30 |
| -_MD_ESCAPE_CHARS = "\\`*_{}[]>()#+-.!" |
31 |
| -_MD_ESCAPE_REGEX = re.compile(f"[{re.escape(_MD_ESCAPE_CHARS)}]") |
32 |
| - |
33 | 27 |
|
34 | 28 | def _md_slugify(value, separator):
|
35 | 29 | # matches the `id_prefix` setting of BLOG_DOCUTILS_SETTINGS
|
36 | 30 | return "s" + separator + _md_title_slugify(value, separator)
|
37 | 31 |
|
38 | 32 |
|
39 |
| -def _md_escape(s): |
40 |
| - # Add a backslash \ before any reserved characters |
41 |
| - return _MD_ESCAPE_REGEX.sub(r"\\\g<0>", s) |
42 |
| - |
43 |
| - |
44 |
| -def _rst_escape(s): |
45 |
| - # New lines mess up rst, it's easier to replace them with spaces. |
46 |
| - return s.replace("\n", " ") |
47 |
| - |
48 |
| - |
49 | 33 | class EntryQuerySet(models.QuerySet):
|
50 | 34 | def published(self):
|
51 | 35 | return self.active().filter(pub_date__lte=timezone.now())
|
@@ -89,9 +73,9 @@ def img(self, url, alt_text):
|
89 | 73 | """
|
90 | 74 | CF = type(self)
|
91 | 75 | return {
|
92 |
| - CF.REST: f".. image:: {url}\n :alt: {_rst_escape(alt_text)}", |
| 76 | + CF.REST: f".. image:: {url}\n :alt: {alt_text}", |
93 | 77 | CF.HTML: format_html('<img src="{}" alt="{}">', url, alt_text),
|
94 |
| - CF.MARKDOWN: f"", |
| 78 | + CF.MARKDOWN: f"", |
95 | 79 | }[self]
|
96 | 80 |
|
97 | 81 |
|
|
0 commit comments