markdown_convert 1.2.52__tar.gz → 1.2.53__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/PKG-INFO +1 -1
  2. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/default.css +2 -1
  3. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/modules/convert.py +1 -1
  4. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/modules/extras.py +36 -11
  5. markdown_convert-1.2.53/markdown_convert/modules/overrides.py +36 -0
  6. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/pyproject.toml +3 -1
  7. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/.gitignore +0 -0
  8. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/LICENSE +0 -0
  9. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/README.md +0 -0
  10. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/__init__.py +0 -0
  11. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/__main__.py +0 -0
  12. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/code.css +0 -0
  13. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/modules/__init__.py +0 -0
  14. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/modules/autoinstall.py +0 -0
  15. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/modules/constants.py +0 -0
  16. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/modules/resources.py +0 -0
  17. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/modules/transform.py +0 -0
  18. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/modules/utils.py +0 -0
  19. {markdown_convert-1.2.52 → markdown_convert-1.2.53}/markdown_convert/modules/validate.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: markdown_convert
3
- Version: 1.2.52
3
+ Version: 1.2.53
4
4
  Summary: Convert Markdown files to PDF from your command line.
5
5
  Project-URL: homepage, https://github.com/Julynx/markdown_convert
6
6
  Author-email: Julio Cabria <juliocabria@tutanota.com>
@@ -517,7 +517,8 @@ math {
517
517
  }
518
518
 
519
519
  /* Vega-Lite charts*/
520
- .vega-lite {
520
+ div.vega-lite,
521
+ div.vega {
521
522
  display: flex;
522
523
  justify-content: center;
523
524
  align-items: center;
@@ -9,7 +9,6 @@ import time
9
9
  from datetime import datetime
10
10
  from pathlib import Path
11
11
 
12
- import markdown2
13
12
  from playwright.sync_api import sync_playwright
14
13
 
15
14
  from .autoinstall import ensure_chromium
@@ -19,6 +18,7 @@ from .constants import (
19
18
  MARKDOWN_EXTENSIONS,
20
19
  PDF_PARAMS,
21
20
  )
21
+ from .overrides import markdown2
22
22
  from .resources import get_code_css_path, get_css_path, get_output_path
23
23
  from .transform import (
24
24
  create_html_document,
@@ -3,10 +3,12 @@ Extras are defined as helper functions called by
3
3
  render_extra_features from transform.py
4
4
  """
5
5
 
6
+ import json
7
+ import re
8
+
6
9
  import vl_convert as vlc
10
+ from bs4 import BeautifulSoup, Tag
7
11
  from ruamel.yaml import YAML
8
- from bs4 import Tag, BeautifulSoup
9
- import re
10
12
 
11
13
 
12
14
  class ExtraFeature:
@@ -162,28 +164,51 @@ class TocExtra(ExtraFeature):
162
164
 
163
165
  class VegaExtra(ExtraFeature):
164
166
  """
165
- Extra feature for rendering Vega-Lite diagrams from YAML.
167
+ Extra feature for rendering Vega-Lite diagrams from JSON or YAML.
166
168
  """
167
169
 
168
- pattern = r"(?s)<pre><code>\$schema: https://vega\.github\.io(?P<content>.*?)</code></pre>"
170
+ pattern = (
171
+ r"<pre[^>]*>"
172
+ r"<code[^>]*class=[\"'][^\"]*language-vega[^\"]*[\"'][^>]*>"
173
+ r"(?P<content>.*?)"
174
+ r"</code>"
175
+ r"</pre>"
176
+ )
169
177
  run_before_stash = True
170
178
 
171
179
  def replace(match, html):
172
180
  """
173
- Render a tag for a vega lite diagram YAML.
181
+ Render a tag for a vega lite diagram from JSON or YAML.
174
182
 
175
183
  Args:
176
- match (re.Match): Element identified as a vega lite diagram YAML.
184
+ match (re.Match): Element identified as a vega lite diagram.
177
185
  html (str): The full HTML content.
178
186
 
179
187
  Returns:
180
188
  str: SVG tag representing the vega lite diagram.
181
189
  """
182
- schema_line = "$schema: https://vega.github.io"
183
- yaml = YAML()
184
- spec = yaml.load(schema_line + match.group("content"))
185
- tag = vlc.vegalite_to_svg(spec)
186
- return f"<div class='vega-lite'>{tag}</div>"
190
+ content = match.group("content")
191
+ spec = None
192
+
193
+ try:
194
+ spec = json.loads(content)
195
+ except (json.JSONDecodeError, TypeError):
196
+ try:
197
+ yaml = YAML(typ="safe")
198
+ spec = yaml.load(content)
199
+ except Exception as exc:
200
+ print(f"WARNING: Failed to parse Vega-Lite spec: {exc}")
201
+ return match.group(0)
202
+
203
+ if spec is None:
204
+ return match.group(0)
205
+
206
+ try:
207
+ tag = vlc.vegalite_to_svg(spec)
208
+ return f"<div class='vega-lite'>{tag}</div>"
209
+ except Exception as exc:
210
+ print(f"WARNING: Failed to convert Vega-Lite spec to SVG: {exc}")
211
+ return match.group(0)
187
212
 
188
213
 
189
214
  def apply_extras(extras: set[ExtraFeature], html, before_stash=False):
@@ -0,0 +1,36 @@
1
+ """
2
+ Overrides for markdown2.
3
+ """
4
+
5
+ import markdown2
6
+
7
+
8
+ def tags(self, lexer_name: str) -> tuple[str, str]:
9
+ """
10
+ Overrides markdown2.FencedCodeBlocks.tags
11
+
12
+ Provides support for the fenced code blocks language attribute without
13
+ the need to have the highlightjs-lang extension enabled.
14
+ """
15
+ pre_class = self.md._html_class_str_from_tag("pre")
16
+ if lexer_name:
17
+ code_class = f' class="{lexer_name} language-{lexer_name}"'
18
+ else:
19
+ code_class = self.md._html_class_str_from_tag("code")
20
+ return (f"<pre{pre_class}><code{code_class}>", "</code></pre>")
21
+
22
+
23
+ def _convert_double_match(self, match):
24
+ """
25
+ Overrides markdown2.Latex._convert_double_match
26
+
27
+ Fixes bug #674 of latex macros that start with backslash n not being
28
+ properly rendered.
29
+ """
30
+ return self.converter.convert(match.group(1).replace("\n", " "), display="block")
31
+
32
+
33
+ # Apply overrides on module import and expose markdown2
34
+ markdown2.FencedCodeBlocks.tags = tags
35
+ markdown2.Latex._convert_double_match = _convert_double_match
36
+ __all__ = ["markdown2"]
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "markdown_convert"
7
- version = "1.2.52"
7
+ version = "1.2.53"
8
8
  description = "Convert Markdown files to PDF from your command line."
9
9
  authors = [
10
10
  { name = "Julio Cabria", email = "juliocabria@tutanota.com" },
@@ -50,6 +50,7 @@ include = [
50
50
  "markdown_convert/modules/utils.py",
51
51
  "markdown_convert/modules/validate.py",
52
52
  "markdown_convert/modules/autoinstall.py",
53
+ "markdown_convert/modules/overrides.py",
53
54
  ]
54
55
 
55
56
  [tool.hatch.build.targets.wheel]
@@ -68,6 +69,7 @@ include = [
68
69
  "markdown_convert/modules/utils.py",
69
70
  "markdown_convert/modules/validate.py",
70
71
  "markdown_convert/modules/autoinstall.py",
72
+ "markdown_convert/modules/overrides.py",
71
73
  ]
72
74
 
73
75
  [dependency-groups]