mkdocs-entangled-plugin 0.5.0__tar.gz → 0.6.0__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.
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-entangled-plugin
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Plugin for MkDocs helping with rendering Entangled (entangled.github.io) projects.
5
5
  Author-email: Johan Hidding <j.hidding@esciencecenter.nl>
6
6
  License-Expression: Apache-2.0
7
7
  License-File: LICENSE
8
8
  Requires-Python: <4,>=3.12
9
- Requires-Dist: entangled-cli<3,>=2.2
9
+ Requires-Dist: entangled-cli<3,>=2.4
10
10
  Requires-Dist: mawk<0.2,>=0.1.7
11
11
  Requires-Dist: mkdocs<2,>=1.4.2
12
12
  Description-Content-Type: text/markdown
@@ -8,18 +8,12 @@ from mkdocs.config.defaults import MkDocsConfig
8
8
  from mkdocs.structure.pages import Page
9
9
  from mkdocs.structure.files import Files
10
10
 
11
- from entangled.document import ReferenceMap, Content, PlainText, ReferenceId, CodeBlock, document_to_text
12
- from entangled.properties import get_attribute, Id, Attribute, Class
13
- from entangled.hooks import get_hooks
14
- from entangled.config import config
11
+ from entangled.model import ReferenceMap, Content, PlainText, ReferenceId, CodeBlock, content_to_text
12
+ from entangled.model.properties import get_attribute, Id, Attribute, Class
13
+ from entangled.config import ConfigUpdate, read_config
14
+ from entangled.interface import Context, read_markdown
15
15
  from repl_session import read_session
16
16
 
17
- config.read()
18
-
19
- # The Entangled config needs to be read before importing the Markdown reader
20
- # This is very bad I know, and should be fixed in some future version.
21
- from entangled.markdown_reader import read_markdown_string
22
-
23
17
 
24
18
  type ContentFilter = Callable[[ReferenceMap, Content], Iterable[Content]]
25
19
  type CodeBlockFilter = Callable[[ReferenceMap, ReferenceId], Iterable[Content]]
@@ -35,6 +29,10 @@ def codeblock_filter(f: CodeBlockFilter) -> ContentFilter:
35
29
  return _foo
36
30
 
37
31
 
32
+ def document_to_text(refs: ReferenceMap, content: Iterable[Content]) -> str:
33
+ return "".join(map(lambda c: content_to_text(refs, c)[0], content))
34
+
35
+
38
36
  def iter_bind[T, U](lst: Iterable[T], f: Callable[[T], Iterable[U]]) -> Iterable[U]:
39
37
  return chain(*map(f, lst))
40
38
 
@@ -49,9 +47,10 @@ def compose_filters(*args: ContentFilter) -> ContentFilter:
49
47
  return reduce(compose_filter, args, lambda _, c: [c])
50
48
 
51
49
 
52
- def read_markdown(text: str) -> tuple[ReferenceMap, list[Content]]:
53
- hooks = get_hooks()
54
- return read_markdown_string(text, hooks=hooks)
50
+ def read_single_markdown(ctx: Context, text: str) -> tuple[ReferenceMap, list[Content]]:
51
+ refs = ReferenceMap()
52
+ content, _ = read_markdown(ctx, refs, text)
53
+ return refs, content
55
54
 
56
55
 
57
56
  @codeblock_filter
@@ -60,7 +59,7 @@ def add_title(reference_map: ReferenceMap, r: ReferenceId) -> list[Content]:
60
59
  Changes the `open_line` member of a `CodeBlock` to reflect accepted
61
60
  MkDocs syntax, adding a `title` attribute.
62
61
  """
63
- codeblock: CodeBlock = reference_map.get_codeblock(r)
62
+ codeblock: CodeBlock = reference_map[r]
64
63
 
65
64
  ids = [p.value for p in codeblock.properties if isinstance(p, Id)]
66
65
  classes = [p.value for p in codeblock.properties if isinstance(p, Class)]
@@ -93,7 +92,7 @@ def add_title(reference_map: ReferenceMap, r: ReferenceId) -> list[Content]:
93
92
  if title:
94
93
  open_line += " " + str(Attribute("title", title))
95
94
 
96
- open_line += "}"
95
+ open_line += "}\n"
97
96
 
98
97
  codeblock.open_line = open_line
99
98
  return [r]
@@ -104,11 +103,12 @@ def include_repl_output(reference_map: ReferenceMap, r: ReferenceId) -> list[Con
104
103
  """
105
104
  Takes any codeblock that has the `repl` class and append its pre-computed output.
106
105
  """
107
- codeblock: CodeBlock = reference_map.get_codeblock(r)
106
+ codeblock: CodeBlock = reference_map[r]
108
107
  if Class("repl") not in codeblock.properties:
109
108
  return [r]
110
109
 
111
- first: CodeBlock = next(iter(reference_map.by_name(r.name)))
110
+ ref = next(iter(reference_map.select_by_name(r.name)))
111
+ first: CodeBlock = reference_map[ref]
112
112
  session_filename = get_attribute(first.properties, "session")
113
113
  assert session_filename is not None
114
114
  session_path: Path = Path(session_filename)
@@ -132,6 +132,7 @@ def include_repl_output(reference_map: ReferenceMap, r: ReferenceId) -> list[Con
132
132
 
133
133
 
134
134
  def on_page_markdown(markdown: str, *, page: Page, config: MkDocsConfig, files: Files) -> str:
135
- reference_map, content = read_markdown(markdown)
135
+ context = Context() | read_config()
136
+ reference_map, content = read_single_markdown(context, markdown)
136
137
  filtered_content = iter_bind(content, partial(compose_filters(add_title, include_repl_output), reference_map))
137
138
  return document_to_text(reference_map, filtered_content)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mkdocs-entangled-plugin"
3
- version = "0.5.0"
3
+ version = "0.6.0"
4
4
  description = "Plugin for MkDocs helping with rendering Entangled (entangled.github.io) projects."
5
5
  authors = [{ name = "Johan Hidding", email = "j.hidding@esciencecenter.nl" }]
6
6
  requires-python = ">=3.12,<4"
@@ -8,7 +8,7 @@ readme = "README.md"
8
8
  license = "Apache-2.0"
9
9
  dependencies = [
10
10
  "mkdocs>=1.4.2,<2",
11
- "entangled-cli>=2.2,<3",
11
+ "entangled-cli>=2.4,<3",
12
12
  "mawk>=0.1.7,<0.2",
13
13
  ]
14
14
 
@@ -42,3 +42,7 @@ testpaths = [
42
42
 
43
43
  [tool.mypy]
44
44
  packages = ["mkdocs_entangled"]
45
+
46
+ [tool.uv.sources]
47
+ entangled-cli = { git = "https://github.com/entangled/entangled.py" }
48
+