From 129b001205bcc81b3e1fbc4791642352275585fb Mon Sep 17 00:00:00 2001 From: Lino Galiana <33896139+linogaliana@users.noreply.github.com> Date: Mon, 26 Dec 2022 20:36:01 +0100 Subject: [PATCH] CSS for ipynb (#337) * test * env * warning * Automated changes * Automated changes * header * Automated changes * Automated changes * header * Automated changes * Automated changes * pencil * Automated changes * Automated changes Co-authored-by: github-actions[bot] --- build/pimp_notebook.py | 94 +++++++++++++++++++ .../modelisation/0_preprocessing/index.qmd | 21 +++-- 2 files changed, 105 insertions(+), 10 deletions(-) diff --git a/build/pimp_notebook.py b/build/pimp_notebook.py index 8c8053e16..6157ca1aa 100644 --- a/build/pimp_notebook.py +++ b/build/pimp_notebook.py @@ -12,6 +12,94 @@ def transform_note_reference(re_find, content_note=False): return note_html +def replace_pattern( + string, pattern, + rules_general, + rules_specific, + box_type = "warning", + put_in_pattern = True + ): + rules = rules_general + [rules_specific[box_type]] + rules_inline = " ".join(rules) + empty="" + if put_in_pattern is True: + pattern_find = pattern.format(box_type, empty) + pattern_repl = pattern.format(box_type, f' style="{rules_inline}"') + else: + pattern_find = pattern.format(empty) + pattern_repl = pattern.format(f' style="{rules_inline}"') + return re.sub(pattern_find, pattern_repl, string) + +def box_for_jupyter(tweak_md, btype): + rules_general_box = [ + 'color: rgba(0,0,0,.8);', + 'background-color: white;', + 'margin-top: 1em;', + 'margin-bottom: 1em;', + 'margin:1.5625emauto;', + 'padding:0 .6rem .8rem!important;overflow:hidden;', + 'page-break-inside:avoid;', + 'border-radius:.25rem;', + 'box-shadow:0 .2rem .5rem rgba(0,0,0,.05),0 0 .05rem rgba(0,0,0,.1);', + 'transition:color .25s,background-color .25s,border-color .25s ;', + 'border-right: 1px solid #dee2e6 ;', + 'border-top: 1px solid #dee2e6 ;', + 'border-bottom: 1px solid #dee2e6 ;' + ] + rules_specific_box = { + "danger": "border-left: .2rem solid #ff0039;", + "warning": "border-left:.2rem solid #ffc10780;", + "info": "border-left:.2rem solid #007bff80;", + "success": "border-left:.2rem solid #3fb618;" + } + rules_general_heading = [ + "margin-bottom: 15px !important;", + "margin-top: 0rem;", + "font-weight:600;", + "font-size: 1.1rem;", + "padding-top: .2em;", + "padding-bottom: .2em;" + ] + rules_specific_heading = { + "danger": "background-color: #dc3545;", + "warning": "background-color: #fff6dd;", + "info": "background-color: #e7f2fa;", + "success": "background-color: #ecf8e8;" + } + + pattern_box = r'\n```\n:::" if l.startswith("{{% /box") else l for l in tweak_md] tweak_md = "\n".join(tweak_md) + # FORCE CSS INSIDE DEFINITION + tweak_md = box_for_jupyter(tweak_md, "warning") + tweak_md = box_for_jupyter(tweak_md, "info") + tweak_md = box_for_jupyter(tweak_md, "success") + tweak_md = box_for_jupyter(tweak_md, "danger") + # FOOTNOTES p = re.compile("\[\^[0-9]+\]:") list_match = list(p.finditer(tweak_md)) diff --git a/content/course/modelisation/0_preprocessing/index.qmd b/content/course/modelisation/0_preprocessing/index.qmd index d7ce45470..2e545073f 100644 --- a/content/course/modelisation/0_preprocessing/index.qmd +++ b/content/course/modelisation/0_preprocessing/index.qmd @@ -26,6 +26,7 @@ plotly: true bibliography: ../../../../reference.bib --- + ::: {.cell .markdown} ```{python} #| echo: false @@ -106,8 +107,8 @@ pour [réviser `pandas`](#pandas) : ::: {.cell .markdown} ```{=html} -