pyodide-mkdocs-theme 0.1.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.
Files changed (72) hide show
  1. pyodide_mkdocs_theme/__init__.py +34 -0
  2. pyodide_mkdocs_theme/__main__.py +166 -0
  3. pyodide_mkdocs_theme/__version__.py +1 -0
  4. pyodide_mkdocs_theme/pyodide_macros/__init__.py +21 -0
  5. pyodide_mkdocs_theme/pyodide_macros/exceptions.py +25 -0
  6. pyodide_mkdocs_theme/pyodide_macros/html_builder/__init__.py +45 -0
  7. pyodide_mkdocs_theme/pyodide_macros/html_builder/_html_builder.py +145 -0
  8. pyodide_mkdocs_theme/pyodide_macros/macros/IDEs/__init__.py +121 -0
  9. pyodide_mkdocs_theme/pyodide_macros/macros/IDEs/ide.py +576 -0
  10. pyodide_mkdocs_theme/pyodide_macros/macros/IDEs/ide_files_data.py +427 -0
  11. pyodide_mkdocs_theme/pyodide_macros/macros/__init__.py +19 -0
  12. pyodide_mkdocs_theme/pyodide_macros/macros/autres.py +226 -0
  13. pyodide_mkdocs_theme/pyodide_macros/macros/isolated_components.py +126 -0
  14. pyodide_mkdocs_theme/pyodide_macros/macros/qcm.py +318 -0
  15. pyodide_mkdocs_theme/pyodide_macros/pages_and_ides_configs.py +194 -0
  16. pyodide_mkdocs_theme/pyodide_macros/parsing.py +115 -0
  17. pyodide_mkdocs_theme/pyodide_macros/paths_utils.py +130 -0
  18. pyodide_mkdocs_theme/pyodide_macros/plugin/__init__.py +19 -0
  19. pyodide_mkdocs_theme/pyodide_macros/plugin/config.py +197 -0
  20. pyodide_mkdocs_theme/pyodide_macros/plugin/maestro_IDE.py +342 -0
  21. pyodide_mkdocs_theme/pyodide_macros/plugin/maestro_base_and_indent.py +324 -0
  22. pyodide_mkdocs_theme/pyodide_macros/plugin/maestro_extras.py +61 -0
  23. pyodide_mkdocs_theme/pyodide_macros/plugin/maestro_tools.py +94 -0
  24. pyodide_mkdocs_theme/pyodide_macros/plugin/pyodide_macros_plugin.py +256 -0
  25. pyodide_mkdocs_theme/pyodide_macros/pyodide_logger.py +99 -0
  26. pyodide_mkdocs_theme/pyodide_macros/scripts_templates.py +5 -0
  27. pyodide_mkdocs_theme/pyodide_macros/tools_and_constants.py +229 -0
  28. pyodide_mkdocs_theme/templates/__init__.py +19 -0
  29. pyodide_mkdocs_theme/templates/main.html +96 -0
  30. pyodide_mkdocs_theme/templates/mkdocs_theme.yml +39 -0
  31. pyodide_mkdocs_theme/templates/partials/copyright.html +24 -0
  32. pyodide_mkdocs_theme/templates/partials/footer.html +50 -0
  33. pyodide_mkdocs_theme/templates/partials/social.html +16 -0
  34. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/0_buttonsAndCounter-scripts.js +302 -0
  35. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/ace-editor-scripts.js +179 -0
  36. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/ide-extrahead.css +172 -0
  37. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/images/icons8-check-64.png +0 -0
  38. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/images/icons8-download-64.png +0 -0
  39. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/images/icons8-play-64.png +0 -0
  40. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/images/icons8-restart-64.png +0 -0
  41. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/images/icons8-save-64.png +0 -0
  42. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/images/icons8-upload-64.png +0 -0
  43. pyodide_mkdocs_theme/templates/pyodide-mkdocs/IDE-and-buttons/z_doLast-subscriptions-scripts.js +58 -0
  44. pyodide_mkdocs_theme/templates/pyodide-mkdocs/README.md +9 -0
  45. pyodide_mkdocs_theme/templates/pyodide-mkdocs/actions/0_tasks-scripts.js +194 -0
  46. pyodide_mkdocs_theme/templates/pyodide-mkdocs/actions/genericCodeRunner-scripts.js +461 -0
  47. pyodide_mkdocs_theme/templates/pyodide-mkdocs/error-logs-generator-scripts.js +260 -0
  48. pyodide_mkdocs_theme/templates/pyodide-mkdocs/js-libs/README.md +3 -0
  49. pyodide_mkdocs_theme/templates/pyodide-mkdocs/js-libs/globalsAndTools/0_config-libs.js +130 -0
  50. pyodide_mkdocs_theme/templates/pyodide-mkdocs/js-libs/globalsAndTools/functools-libs.js +213 -0
  51. pyodide_mkdocs_theme/templates/pyodide-mkdocs/js-libs/globalsAndTools/jsLogger-libs.js +57 -0
  52. pyodide_mkdocs_theme/templates/pyodide-mkdocs/js-libs/globalsAndTools/securedPagesData-libs.js +106 -0
  53. pyodide_mkdocs_theme/templates/pyodide-mkdocs/js-libs/globalsAndTools/z_globalGuiButtons-libs.js +66 -0
  54. pyodide_mkdocs_theme/templates/pyodide-mkdocs/js-libs/globalsAndTools/z_header-btns-extrahead.css +46 -0
  55. pyodide_mkdocs_theme/templates/pyodide-mkdocs/js-libs/mathjax-libs.js +54 -0
  56. pyodide_mkdocs_theme/templates/pyodide-mkdocs/perPageScripts/README.md +3 -0
  57. pyodide_mkdocs_theme/templates/pyodide-mkdocs/perPageScripts/start-pyodide.css +64 -0
  58. pyodide_mkdocs_theme/templates/pyodide-mkdocs/perPageScripts/start-pyodide.js +212 -0
  59. pyodide_mkdocs_theme/templates/pyodide-mkdocs/pyoditeur-extrahead.css +163 -0
  60. pyodide_mkdocs_theme/templates/pyodide-mkdocs/terminal/css/0_cdn-terminal-replacement-extrahead.css +1343 -0
  61. pyodide_mkdocs_theme/templates/pyodide-mkdocs/terminal/css/terminal-extrahead.css +56 -0
  62. pyodide_mkdocs_theme/templates/pyodide-mkdocs/terminal/terminal-helpers-scripts.js +172 -0
  63. pyodide_mkdocs_theme/templates/pyodide-mkdocs/terminal/terminal-scripts.js +159 -0
  64. pyodide_mkdocs_theme/templates/pyodide-mkdocs/terminal/z_doLast_terminal-scripts.js +50 -0
  65. pyodide_mkdocs_theme/templates/qcm/.qcm-circle.svg +76 -0
  66. pyodide_mkdocs_theme/templates/qcm/qcm-extrahead.css +174 -0
  67. pyodide_mkdocs_theme/templates/qcm/qcm-scripts.js +349 -0
  68. pyodide_mkdocs_theme-0.1.0.dist-info/LICENSE +674 -0
  69. pyodide_mkdocs_theme-0.1.0.dist-info/METADATA +64 -0
  70. pyodide_mkdocs_theme-0.1.0.dist-info/RECORD +72 -0
  71. pyodide_mkdocs_theme-0.1.0.dist-info/WHEEL +4 -0
  72. pyodide_mkdocs_theme-0.1.0.dist-info/entry_points.txt +6 -0
@@ -0,0 +1,34 @@
1
+ """
2
+ Pyodide-MkDocs-Theme is a theme for MkDocs that allows building websites integrating, on the client side:
3
+
4
+ - IDEs (code editor),
5
+ - Interactive Python consoles,
6
+ - An online judge for testing user-written functions, associated with corrections and remarks,
7
+ - And some other features (qcms, ...).
8
+
9
+ ## Guarantees:
10
+
11
+ - No cookies
12
+ - No registration
13
+ - Created by teachers for teachers
14
+
15
+ This project is a redesign of the prototype [`pyodide-mkdocs`](https://bouillotvincent.gitlab.io/pyodide-mkdocs/) initially created by [Vincent Bouillot](https://gitlab.com/bouillotvincent/).
16
+
17
+ ## How it works:
18
+
19
+ The technology enabling this feat is called [Pyodide](https://pyodide.org/en/stable/). It is associated with JavaScript elements, such as [jquery.terminal](https://terminal.jcubic.pl/api_reference.php) and [ACE Editor](https://ace.c9.io/).
20
+
21
+ Pyodide uses WebAssembly to bridge between Python and JavaScript and provide an environment for manipulating the JavaScript DOM with Python, or vice versa for manipulating Python from JavaScript.
22
+
23
+
24
+ ## Links:
25
+
26
+ * [GitLab repository](https://gitlab.com/frederic-zinelli/pyodide-mkdocs-theme)
27
+ * [Documentation](http://frederic-zinelli.gitlab.io/pyodide-mkdocs-theme/) (french only)
28
+
29
+
30
+
31
+ ![IDE capture example](http://frederic-zinelli.gitlab.io/pyodide-mkdocs-theme/assets/pyodide-mkdocs-theme-ex.png)
32
+
33
+ """
34
+
@@ -0,0 +1,166 @@
1
+ """
2
+ pyodide-mkdocs-theme
3
+ Copyleft GNU GPLv3 🄯 2024 Frédéric Zinelli
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program.
17
+ If not, see <https://www.gnu.org/licenses/>.
18
+ """
19
+
20
+ from argparse import ArgumentParser
21
+ from .__version__ import __version__
22
+
23
+
24
+
25
+ parser = ArgumentParser(
26
+ 'pyodide_mkdocs_theme',
27
+ description="Scripts for pyodide-mkdocs-theme",
28
+ epilog="""Copyleft GNU GPLv3 🄯 2024 Frédéric Zinelli
29
+
30
+ This program comes with ABSOLUTELY NO WARRANTY."""
31
+ )
32
+ parser.add_argument(
33
+ '-V', '--version', action='version', version=f'pyodide-mkdocs-theme {__version__}'
34
+ )
35
+ parser.add_argument(
36
+ '-yml', action='store_true', help='Print a base configuration for the mkdocs.yml file.'
37
+ )
38
+
39
+ def main():
40
+ args = parser.parse_args()
41
+ print(args)
42
+
43
+ if args.yml:
44
+ display_yml()
45
+
46
+
47
+
48
+
49
+ def display_yml():
50
+ print('''
51
+ # Voici un exemple presque complet de configuration pour un fichier
52
+ # mkdocs.yml utilisant pyodide-mkdocs-theme.
53
+
54
+ site_url: "{>> L'adresse de votre site web ici <<}"
55
+ site_name: "{>> Titre pour votre site <<}"
56
+ # site_description: "(optionnel)"
57
+ # repo_url: "(optionnel)"
58
+ # edit_uri: "(optionnel)"
59
+
60
+ # Copyright "CC BY-NC-SA"
61
+ copyright: |
62
+ <p xmlns:cc="http://creativecommons.org/ns#"
63
+ xmlns:dct="http://purl.org/dc/terms/">Partage ou adaptation possible selon les conditions de la
64
+ licence <a
65
+ href="http://creativecommons.org/licenses/by-nc-sa/4.0/?ref=chooser-v1"
66
+ target="_blank" rel="license noopener noreferrer"
67
+ style="display:inline-block;"> CC BY-NC-SA 4.0 <img
68
+ style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
69
+ src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img
70
+ style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
71
+ src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img
72
+ style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
73
+ src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img
74
+ style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
75
+ src="https://mirrors.creativecommons.org/presskit/icons/sa.svg?ref=chooser-v1"></a></p>
76
+
77
+
78
+ docs_dir: docs
79
+
80
+ nav:
81
+ - "Accueil": index.md
82
+ # - ...
83
+
84
+ # Pour supprimer certains fichiers markdown de la navigation (pattern shell):
85
+ # not_in_nav: |
86
+ # */**/*.md
87
+
88
+ theme:
89
+ name: pyodide-mkdocs-theme
90
+
91
+ # features:
92
+ # - navigation.instant # Ne surtout pas activer cette option !
93
+
94
+
95
+ markdown_extensions:
96
+
97
+ # Extensions indispensables pour le thème:
98
+ - md_in_html # !!REQUIS!!
99
+ - admonition # !!REQUIS!! Blocs colorés: !!! info "ma remarque"
100
+ - attr_list # !!REQUIS!! Un peu de CSS et des attributs HTML, ex: { #id .class style="display:none" }
101
+ - pymdownx.details # !!REQUIS!! Admonition: ??? -> peuvent se déplier ; ???+ -> peuvent se replier.
102
+ - pymdownx.emoji: # !!REQUIS!! Émojis: :boom:
103
+ emoji_index: !!python/name:material.extensions.emoji.twemoji
104
+ emoji_generator: !!python/name:material.extensions.emoji.to_svg
105
+ - pymdownx.highlight # !!REQUIS!! Coloration syntaxique du code
106
+ - pymdownx.inlinehilite # !!REQUIS!! Coloration syntaxique pour les "code spans": `#!python code_python`
107
+ - pymdownx.snippets: # !!REQUIS!! Inclusion de fichiers externe.
108
+ check_paths: true # Fortement conseillé...
109
+ - pymdownx.superfences # !!REQUIS!!
110
+ - pymdownx.arithmatex: # !!REQUIS!!
111
+ generic: true
112
+ - pymdownx.striphtml:
113
+ strip_js_on_attributes: false # !!REQUIS!!
114
+ strip_attributes: "" # !!REQUIS!!
115
+
116
+
117
+ # Extensions conseillées:
118
+ - meta
119
+ - abbr
120
+ - def_list # Les listes de définition.
121
+ - footnotes # Notes[^1] de bas de page. [^1]: ma note.
122
+ - pymdownx.caret # Passage ^^souligné^^ ou en ^exposant^.
123
+ - pymdownx.mark # Passage ==surligné==.
124
+ - pymdownx.tilde # Passage ~~barré~~ ou en ~indice~.
125
+ - pymdownx.tasklist: # Cases à cocher - [ ] et - [x]
126
+ custom_checkbox: false
127
+ clickable_checkbox: true
128
+ - pymdownx.tabbed: # Volets glissants: === "Mon volet"
129
+ alternate_style: true # Meilleure compatibilité pour mobiles
130
+ slugify: !!python/object/apply:pymdownx.slugs.slugify
131
+ kwds:
132
+ case: lower
133
+ - pymdownx.keys # Touches du clavier: ++ctrl+d++
134
+ - toc:
135
+ toc_depth: 0 # Si vous voulez supprimer la ToC (table of content) de la page
136
+
137
+
138
+ # Configuration minimale pour les plugins
139
+ plugins:
140
+ - awesome-pages: # Pas indispensable, mais... (pip install mkdocs-awesome-pages-plugin)
141
+ collapse_single_pages: true
142
+
143
+ - material/search # Les plugins de material-mkdocs doivent être préfixés!
144
+
145
+ - exclude: # (pip install mkdocs-exclude)
146
+ glob: # Patterns identifiant des pages à ne pas inclure dans le build.
147
+ - sous_dossier/**/*REM.md # Les fichiers de remarques DOIVENT être exclus
148
+ - sous_dossier/**/*.py # Les fichiers python DOIVENT être exclus
149
+
150
+ - exclude-search: # (pip install mkdocs-exclude-search)
151
+ exclude: # Pour les fichiers inclus dans le build, que la recherche ne doit pas indexer
152
+ - bac_a_sable.md
153
+
154
+ - pyodide_macros # !!REQUIS!!
155
+
156
+
157
+ validation: # Si mkdocs est lancé en mode strict (mkdocs ... --strict), les warnings lèveront une erreur
158
+ omitted_files: warn
159
+ unrecognized_links: warn
160
+
161
+ ''')
162
+
163
+
164
+
165
+ if __name__ == '__main__':
166
+ main()
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,21 @@
1
+ """
2
+ pyodide-mkdocs-theme
3
+ Copyleft GNU GPLv3 🄯 2024 Frédéric Zinelli
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program.
17
+ If not, see <https://www.gnu.org/licenses/>.
18
+ """
19
+
20
+
21
+ from .plugin.pyodide_macros_plugin import PyodideMacrosPlugin
@@ -0,0 +1,25 @@
1
+ """
2
+ pyodide-mkdocs-theme
3
+ Copyleft GNU GPLv3 🄯 2024 Frédéric Zinelli
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program.
17
+ If not, see <https://www.gnu.org/licenses/>.
18
+ """
19
+
20
+ from mkdocs.exceptions import ConfigurationError
21
+
22
+
23
+ class PyodideConfigurationError(ConfigurationError):
24
+ """ Something went wrong in the Pyodide theme itself """
25
+
@@ -0,0 +1,45 @@
1
+ """
2
+ pyodide-mkdocs-theme
3
+ Copyleft GNU GPLv3 🄯 2024 Frédéric Zinelli
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program.
17
+ If not, see <https://www.gnu.org/licenses/>.
18
+ """
19
+
20
+ """
21
+ Objects to facilitate building html elements.
22
+
23
+ Usage:
24
+ Import the module as a namespace and use the functions. This allows to keep the type
25
+ hints, the docstrings and the function signature when coding.
26
+ """
27
+ # Using a package to control what functions/elements are seen through autocompletion
28
+ # suggestions when coding.
29
+
30
+ # pylint: disable=all
31
+
32
+ from ._html_builder import (
33
+ input,
34
+ img,
35
+
36
+ a,
37
+ button,
38
+ code,
39
+ div,
40
+ script,
41
+ span,
42
+ svg,
43
+ terminal,
44
+ tooltip,
45
+ )
@@ -0,0 +1,145 @@
1
+ """
2
+ pyodide-mkdocs-theme
3
+ Copyleft GNU GPLv3 🄯 2024 Frédéric Zinelli
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program.
17
+ If not, see <https://www.gnu.org/licenses/>.
18
+ """
19
+
20
+ # pylint: disable=all
21
+
22
+ from typing import Dict, Optional
23
+
24
+
25
+
26
+
27
+
28
+
29
+ def html_builder_factory(template:str, allow_content):
30
+ def tagger(tag:str):
31
+ def html_builder(
32
+ content:str="",
33
+ *,
34
+ id:str='', kls:str="", attrs: Dict[str, str]=None,
35
+ **kwargs
36
+ ) -> str:
37
+ """
38
+ Build a the code for the given tag element.
39
+ The id and kls named arguments, and also all keyword arguments have precedence over the
40
+ content of the attrs dict. This dict allow to define hyphen separated attributes (like
41
+ "data-max_size" and so on).
42
+
43
+ NOTE: Using the @content argument on "mono tags" will raise ValueError.
44
+ """
45
+ if not allow_content and content:
46
+ raise ValueError(f"Cannot use content on {tag!r} tags ({content=!r})")
47
+
48
+ attrs = attrs or {}
49
+ attrs.update(kwargs)
50
+ if id: attrs['id'] = id
51
+ if kls: attrs['class'] = kls
52
+
53
+ attributes = " ".join(
54
+ f'{ name }="{ value }"' #if name!='onclick' else f'{ name }={ value }'
55
+ for name,value in attrs.items()
56
+ )
57
+ code = template.format(tag=tag, content=content, attributes=attributes)
58
+ return code
59
+
60
+ return html_builder
61
+ return tagger
62
+
63
+
64
+
65
+ mono_tag = html_builder_factory("<{tag} {attributes} />", False)
66
+ bi_tag = html_builder_factory("<{tag} {attributes}>{content}</{tag}>", True)
67
+
68
+
69
+
70
+
71
+ input = mono_tag('input')
72
+ img = mono_tag('img')
73
+
74
+ a = bi_tag('a')
75
+ button = bi_tag('button')
76
+ code = bi_tag('code')
77
+ div = bi_tag('div')
78
+ script = bi_tag('script')
79
+ span = bi_tag('span')
80
+ svg = bi_tag('svg')
81
+
82
+
83
+
84
+
85
+ def tooltip(txt:str, width_em:Optional[int]=None, shift:int=50):
86
+ """
87
+ Generic CodEx tooltip builder. If width_em is falsy, use automatic width.
88
+ Th @shift argument is the % to use for the translation, 0% means the tooltip will got on the
89
+ right, 100% means it will go on the left. With 50 (default), it's centered below the original element
90
+ """
91
+ dct = {
92
+ 'kls': 'tooltiptext',
93
+ 'style': f'--tool_shift: {shift}%;',
94
+ }
95
+ if width_em:
96
+ dct['style'] += f"width:{ width_em }em;"
97
+
98
+ return span(txt, **dct)
99
+
100
+
101
+
102
+
103
+
104
+ def terminal(term_id:str, kls:str, n_lines_h:int, **kw):
105
+ """
106
+ Build a terminal div with its button. If n_lines_h is falsy, the height of the div isn't
107
+ handled. Otherwise, it's the mac of n_lines_h and 5.
108
+ """
109
+
110
+ tip = tooltip(
111
+ "Tronquer ou non le feedback dans les terminaux (sortie standard & stacktrace / relancer le code pour appliquer)",
112
+ width_em=16, shift=90
113
+ )
114
+ btn_div = div(
115
+ _BTN_STDOUT_SVG + tip,
116
+ kls="stdout-ctrl tooltip"
117
+ )
118
+ if n_lines_h:
119
+ n_lines_h = max(n_lines_h, 5)
120
+ kw['style'] = f"--n-lines:{ n_lines_h };" + kw.get('style','')
121
+ kw['style'] = 'line-height:24px;' + kw.get('style','')
122
+
123
+ term_div = div(btn_div, id=term_id, kls=kls, **kw)
124
+ return term_div
125
+
126
+
127
+ _BTN_STDOUT_SVG = '''
128
+ <svg viewBox="0 0 24 24" fill="none"
129
+ stroke="var(--md-default-fg-color)" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
130
+ xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
131
+ <g>
132
+ <path d="M 4,21.4 V 2.6 C 4,2.3 4.3,2 4.6,2 h 11.65 c 0.16,0 0.31,0.06 0.42,0.18 l 3.15,3.15 C 19.94,5.44 20,5.59 20,5.75 V 21.4 C 20,21.73 19.73,22 19.4,22 H 4.6 C 4.3,22 4,21.73 4,21.4 Z" />
133
+ <path d="M 16,5.4 V 2.35 C 16,2.16 16.16,2 16.35,2 c 0.09,0 0.18,0.03 0.25,0.10 l 3.29,3.29 C 19.96,5.46 20,5.55 20,5.65 20,5.84 19.84,6 19.65,6 H 16.6 C 16.27,6 16,5.73 16,5.4 Z" />
134
+ <path d="m 8,9.25 h 8" />
135
+ <path d="M 7.9,13.25 H 15.9"/>
136
+ <path d="M 7.9,11.25 H 14.4" />
137
+ <path d="M 7.9,19.25 H 14.4" />
138
+ <path d="m 7.9,15.25 h 8" />
139
+ <path d="M 7.9,17.25 H 11.9" />
140
+ <path d="m 8,5.25 h 4" />
141
+ <path d="m 8,7.25 h 4" />
142
+ </g>
143
+ <g><path class="stdout-x-ray-svg" d="M 3,11.4 v 6 L 21,13.8 V 7.7 Z" style="fill:var(--md-default-bg-color);stroke-width:0;" /></g>
144
+ </svg>
145
+ '''.replace('\n',' ') # needed otherwise insertion in admonitions fails... XD
@@ -0,0 +1,121 @@
1
+ """
2
+ pyodide-mkdocs-theme
3
+ Copyleft GNU GPLv3 🄯 2024 Frédéric Zinelli
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program.
17
+ If not, see <https://www.gnu.org/licenses/>.
18
+ """
19
+
20
+ # pylint: disable=invalid-name, missing-module-docstring
21
+
22
+
23
+ from functools import wraps
24
+ import re
25
+ from typing import Literal, Optional, Union
26
+
27
+ from ...tools_and_constants import ScriptSection
28
+ from ...parsing import build_code_fence
29
+ from ...plugin.maestro_IDE import MaestroIDE
30
+ from .ide_files_data import IdeFilesExtractor
31
+ from .ide import Ide
32
+
33
+
34
+
35
+
36
+
37
+ def _IDE_maker(env:MaestroIDE, mode:str):
38
+ """
39
+ @script_name: Partial path from the directory holding the sujet.md file, to the one holding
40
+ all the other required files, ending with the common prefix for the exercice.
41
+ Ex: "exo" to extract: "exo.py", "exo_corr.py", "exo_test.py", ...
42
+ "sub_exA/exo" for: "sub_exA/exo.py", "sub_exA/exo_corr.py", ...
43
+ @MAX: Number of tries before the solution becomes visible (default=5).
44
+ @SANS: String of spaces or coma separated python functions or modules/packages the
45
+ user cannot use. By default, nothing is forbidden.
46
+ - Every string section that matches a builtin callable forbid that function
47
+ by replacing it with another function which will raise an error if called
48
+ - Every string section prefixed with a fot forbids a method call. Here a
49
+ simple string containment check is done opn the user's code, to check it
50
+ does not contain the desired method name with the dot before it.
51
+ - Any other string section is considered as a module name and doing an
52
+ import (in any way/syntax) involving that name will raise an error.
53
+ @SIZE: Max number of lines of the IDE (default=30).
54
+ @ID: Optional. To use to differentiate two IDEs using the same python root file.
55
+ @WHITE: String of spaces or coma separated python modules/packages that have to be
56
+ preloaded before the code restrictions (@SANS) are applied.
57
+ @LOGS: If True, failing assertions without feedback during the private tests will
58
+ be augmented automatically with the code of the assertion itself. If None,
59
+ use the global `show_code_on_failed_assertions` plugin value, defined in
60
+ `mkdocs.yml`, to determine what to do (default=None).
61
+ @REC_LIMIT: Setup a specific recursion limit value for the runtime (-1 if not used)
62
+ @TERM_H: Number of lines to use for the terminal size (ignored for vertical terminals)
63
+ """
64
+
65
+ @wraps(_IDE_maker)
66
+ def wrapped(
67
+ script_name: str = "",
68
+ MAX: Union[int, Literal["+"]] = 5,
69
+ SANS: str = "",
70
+ SIZE: int = 30,
71
+ ID: int = None,
72
+ WHITE: str = "",
73
+ LOGS: Optional[bool] = None,
74
+ REC_LIMIT: int = -1,
75
+ TERM_H: int = 10,
76
+ ) -> str:
77
+ return Ide(
78
+ env, script_name, mode, MAX, SANS, SIZE, WHITE, ID, LOGS, REC_LIMIT, TERM_H
79
+ ).make_ide()
80
+
81
+ wrapped.__name__ = wrapped.__qualname__ = 'IDE' + mode.strip('_')
82
+ return wrapped
83
+
84
+
85
+
86
+
87
+ def IDE(env:MaestroIDE):
88
+ """ To build editor+terminal on 2 rows """
89
+ return _IDE_maker(env, "")
90
+
91
+
92
+ def IDEv(env:MaestroIDE):
93
+ """ To build editor+terminal on 2 columns """
94
+ return _IDE_maker(env, "_v")
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ def section(env:MaestroIDE):
103
+ """
104
+ Insert the given section from the python file.
105
+ Note: To use only on python scripts holding all the sections for the IDE macros. For regular
106
+ files, use the `py` macro or regular code fences with file inclusions (for performances
107
+ reasons).
108
+ """
109
+ @wraps(section)
110
+ def _section(script_name:str, section_name:ScriptSection, ID:Optional[int]=None):
111
+ file_data = IdeFilesExtractor(env, script_name)
112
+ content = file_data.get_section(section_name)
113
+
114
+ id_pattern = "" if ID is None else rf",\s*ID\s*=\s*{ ID }\b\s*"
115
+ macro_pattern = rf"""['"]{ script_name }['"]\s*,\s*['"]{ section_name }['"]{ id_pattern }"""
116
+ ide_jinja_reg = re.compile( rf"section\(\s*{ macro_pattern }" )
117
+ indent = env.get_indent_in_current_page(ide_jinja_reg)
118
+ out = build_code_fence(content, indent, lang='python')
119
+ return out
120
+
121
+ return _section