crieur 1.9.1__tar.gz → 1.10.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.

Potentially problematic release.


This version of crieur might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: crieur
3
- Version: 1.9.1
3
+ Version: 1.10.0
4
4
  Summary: A Static Revue Generator.
5
5
  Project-URL: Homepage, https://gitlab.huma-num.fr/ecrinum/crieur
6
6
  Project-URL: Issues, https://gitlab.huma-num.fr/ecrinum/crieur/-/issues
@@ -1,4 +1,4 @@
1
1
  from pathlib import Path
2
2
 
3
- VERSION = "1.9.1"
3
+ VERSION = "1.10.0"
4
4
  ROOT_DIR = Path(__file__).parent
@@ -15,7 +15,12 @@ from .typography import typographie
15
15
  from .utils import neighborhood
16
16
 
17
17
  locale.setlocale(locale.LC_ALL, "")
18
- mistune_plugins = ["footnotes", "superscript", "table"]
18
+ mistune_plugins = [
19
+ "footnotes",
20
+ "superscript",
21
+ "table",
22
+ "crieur.plugins.inline_footnotes",
23
+ ]
19
24
  md = mistune.create_markdown(plugins=mistune_plugins, escape=False)
20
25
 
21
26
 
@@ -0,0 +1,110 @@
1
+ from typing import Any, Dict, List, Match, Union
2
+
3
+ from mistune.core import BlockState
4
+
5
+ __all__ = ["inline_footnotes"]
6
+
7
+ # https://michelf.ca/projects/php-markdown/extra/#footnotes
8
+ INLINE_FOOTNOTE = r"\^\[(?P<footnote_inlined>[^\]]*)\]"
9
+
10
+
11
+ def parse_inline_footnote(
12
+ inline: "InlineParser", m: Match[str], state: "InlineState"
13
+ ) -> int:
14
+ key = m.group("footnote_inlined")
15
+ notes = state.env.get("inline_footnotes")
16
+ if not notes:
17
+ notes = []
18
+ if key not in notes:
19
+ notes.append(key)
20
+ state.env["inline_footnotes"] = notes
21
+ state.append_token(
22
+ {
23
+ "type": "footnote_ref",
24
+ "raw": key,
25
+ "attrs": {"index": notes.index(key) + 1},
26
+ }
27
+ )
28
+ return m.end()
29
+
30
+
31
+ def parse_footnote_item(
32
+ block: "BlockParser", key: str, index: int, state: BlockState
33
+ ) -> Dict[str, Any]:
34
+ return {
35
+ "type": "footnote_item",
36
+ "children": [{"type": "paragraph", "text": key}],
37
+ "attrs": {"key": key, "index": index},
38
+ }
39
+
40
+
41
+ def md_footnotes_hook(
42
+ md: "Markdown", result: Union[str, List[Dict[str, Any]]], state: BlockState
43
+ ) -> Union[str, List[Dict[str, Any]]]:
44
+ notes = state.env.get("inline_footnotes")
45
+ if not notes:
46
+ return result
47
+
48
+ children = [
49
+ parse_footnote_item(md.block, k, i + 1, state) for i, k in enumerate(notes)
50
+ ]
51
+ state = BlockState()
52
+ state.tokens = [{"type": "footnotes", "children": children}]
53
+ output = md.render_state(state)
54
+ return result + output # type: ignore[operator]
55
+
56
+
57
+ def render_inline_footnote_ref(renderer: "BaseRenderer", key: str, index: int) -> str:
58
+ i = str(index)
59
+ html = '<sup class="footnote-ref" id="fnref-' + i + '">'
60
+ return html + '<a href="#fn-' + i + '">' + i + "</a></sup>"
61
+
62
+
63
+ def render_inline_footnotes(renderer: "BaseRenderer", text: str) -> str:
64
+ return '<section class="footnotes">\n<ol>\n' + text + "</ol>\n</section>\n"
65
+
66
+
67
+ def render_inline_footnote_item(
68
+ renderer: "BaseRenderer", text: str, key: str, index: int
69
+ ) -> str:
70
+ i = str(index)
71
+ back = '<a href="#fnref-' + i + '" class="footnote">&#8617;</a>'
72
+ text = text.rstrip()[:-4] + back + "</p>"
73
+ return '<li id="fn-' + i + '">' + text + "</li>\n"
74
+
75
+
76
+ def inline_footnotes(md: "Markdown") -> None:
77
+ """A mistune plugin to support inline footnotes, spec defined at
78
+ https://michelf.ca/projects/php-markdown/extra/#footnotes
79
+
80
+ Here is an example:
81
+
82
+ .. code-block:: text
83
+
84
+ That's some text with a footnote.^[And that's the footnote.]
85
+
86
+ It will be converted into HTML:
87
+
88
+ .. code-block:: html
89
+
90
+ <p>That's some text with a footnote.<sup class="footnote-ref" id="fnref-1"><a href="#fn-1">1</a></sup></p>
91
+ <section class="footnotes">
92
+ <ol>
93
+ <li id="fn-1"><p>And that's the footnote.<a href="#fnref-1" class="footnote">&#8617;</a></p></li>
94
+ </ol>
95
+ </section>
96
+
97
+ :param md: Markdown instance
98
+ """
99
+ md.inline.register(
100
+ "inline_footnote",
101
+ INLINE_FOOTNOTE,
102
+ parse_inline_footnote,
103
+ before="link",
104
+ )
105
+ md.after_render_hooks.append(md_footnotes_hook)
106
+
107
+ if md.renderer and md.renderer.NAME == "html":
108
+ md.renderer.register("footnote_ref", render_inline_footnote_ref)
109
+ md.renderer.register("footnote_item", render_inline_footnote_item)
110
+ md.renderer.register("footnotes", render_inline_footnotes)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes