crieur 1.9.1__py3-none-any.whl → 1.10.0__py3-none-any.whl

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.

crieur/__init__.py CHANGED
@@ -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
crieur/generator.py CHANGED
@@ -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
 
crieur/plugins.py ADDED
@@ -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)
@@ -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,8 +1,9 @@
1
- crieur/__init__.py,sha256=puCj4_kji3yq03piHwqm8C6Xfe3FDO-v0-pfv95slI8,77
1
+ crieur/__init__.py,sha256=O8TcYHRBh9cCuyhUXFklX555xLzv9Z1Bzo6NbVUvJQE,78
2
2
  crieur/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
3
3
  crieur/cli.py,sha256=trYYSwcYsyPoWluZSVLoSA-8w86uQy3Wnw_w6724g8k,5809
4
- crieur/generator.py,sha256=druWYkgrSzdWnRJDQkLT-EuabdMib_nw1tdIS1fGLPM,4745
4
+ crieur/generator.py,sha256=FPj-W7-d20KUTe9fGjFApZoBMeEFO2TM57c1zuGgaOs,4799
5
5
  crieur/models.py,sha256=gBQx-3OFAsksfxH-OHI8Tm1J5YAwxyvfkQfoQkl5TP8,9328
6
+ crieur/plugins.py,sha256=UquWD5QpQWKjlYSowC00CqJaMdrltaFmGX87EzOzjmA,3375
6
7
  crieur/typography.py,sha256=zZHJLZ8aUslMuiNX6z4buKNDZuj7gcrUxcIGACWmIHw,2759
7
8
  crieur/utils.py,sha256=kIdxpd5LgVv13Lx2aEXzjQttBDtcppRlwNsH0vwX8f0,1566
8
9
  crieur/statics/pico.css,sha256=VdrimW9PLcEIzqJ__s062OrwBj_Jb6jZIwbtdqOtM-w,93407
@@ -12,8 +13,8 @@ crieur/templates/base.html,sha256=4ZOLAnmle0_m8Y3lWT6wcH8f-_7SymxEDeIUzDQNnks,16
12
13
  crieur/templates/homepage.html,sha256=7YG7kA4AFuyrSuqWeFAVj09ogwsybE7w0-NKMLWms5s,2994
13
14
  crieur/templates/keyword.html,sha256=Hv3Ep3R6oN5pBw14gfQT-aeqEiuFiatmVZLWn5hR1e4,428
14
15
  crieur/templates/numero.html,sha256=F7hCaAHJ1WRWxD_zfhJzyLaiwXblJWJF7DUTy41Mnu8,1849
15
- crieur-1.9.1.dist-info/METADATA,sha256=WJJ2fhQNWspEhZkozJpbk48Er0USIMDXCCVkohn-Q4Q,45269
16
- crieur-1.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
- crieur-1.9.1.dist-info/entry_points.txt,sha256=edmbmPxs9QXyvSMpPJBDPGw3vZOJEKqXJhysYNx3QSM,43
18
- crieur-1.9.1.dist-info/licenses/LICENSE,sha256=F5acw9_laHeyi4wPmQyf_ttyz81VqCIwScwO8C1FhXU,34519
19
- crieur-1.9.1.dist-info/RECORD,,
16
+ crieur-1.10.0.dist-info/METADATA,sha256=s-B0VdShODsfSvAeTVVHDi4jreOEtZhNvrUYpnvw5-U,45270
17
+ crieur-1.10.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
18
+ crieur-1.10.0.dist-info/entry_points.txt,sha256=edmbmPxs9QXyvSMpPJBDPGw3vZOJEKqXJhysYNx3QSM,43
19
+ crieur-1.10.0.dist-info/licenses/LICENSE,sha256=F5acw9_laHeyi4wPmQyf_ttyz81VqCIwScwO8C1FhXU,34519
20
+ crieur-1.10.0.dist-info/RECORD,,