Skip to content

Commit

Permalink
Process is good
Browse files Browse the repository at this point in the history
  • Loading branch information
yves-chevallier committed Aug 15, 2024
1 parent 47d56bf commit 611b91a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 47 deletions.
14 changes: 7 additions & 7 deletions docs/css/callout.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

:root {
--ycr-bubble-bg-color: #92c6ce1a;
--ycr-bubble-icon-color: #0d545f;
Expand Down Expand Up @@ -52,7 +51,7 @@
margin: 0 0.2em;
white-space: nowrap;
font-weight: 300 !important;
color: var(--md-code-fg-color) !important;
color: var(--ycr-bubble-icon-color) !important;
font-family: var(--md-code-font-family);
}

Expand All @@ -61,12 +60,13 @@
border: .075rem solid var(--ycr-bubble-fg-color--hover);
}


.ycr-regex code {
all: unset;
color: var(--ycr-bubble-icon-color) !important;
text-decoration: none;
}

a.ycr-callout:focus code,a.ycr-callout:hover code {
background-color: transparent !important;
}
a.ycr-regex:focus code,
a.ycr-regex:hover code {
background: inherit;
background-color: transparent;
}
38 changes: 23 additions & 15 deletions docs/js/navcolor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
document$.subscribe(async function(el) {
document$.subscribe(async function (el) {
const ul = el.querySelector('.md-tabs__list');
if (!ul) {
return;
Expand All @@ -13,20 +13,28 @@ document$.subscribe(async function(el) {
}
const href = a.getAttribute('href');

if (href.includes('/course-c/')) {
color = 'red'
config = {
'default': {
'/course-c/': 'red',
'/course-cpp/': 'cyan',
'/course-python/': 'green',
'/environment/': 'gray',
'default': 'red'
},
'slate': {
'/course-c/': 'black',
'/course-cpp/': 'cyan',
'/course-python/': 'green',
'/environment/': 'gray',
'default': 'black'
}
}
else if (href.includes('/course-cpp/')) {
color = 'cyan'
}
else if (href.includes('/course-python/')) {
color = 'green'
}
else if (href.includes('/environment/')) {
color = 'gray'
}
else {
color = 'red'

let scheme = document.querySelector('body').getAttribute('data-md-color-scheme');
for (let key in config[scheme]) {
if (href.includes(key)) {
color = config[scheme][key];
document.querySelector('body').setAttribute('data-md-color-primary', color);
}
}
document.querySelector('body').setAttribute('data-md-color-primary', color);
});
8 changes: 6 additions & 2 deletions hooks/latex/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ def __init__(self, output_path=Path("build"), config={}):
self.render_hr,
self.render_br,
# Prior escaping LaTeX special characters
self.render_regex,
self.render_codeblock,
self.render_codeinline,
self.render_math,
self.render_math_block,
self.render_regex,
self.render_unicode,
self.render_navigable_string,
self.render_emoji,
Expand Down Expand Up @@ -284,7 +284,11 @@ def render_regex(self, soup: Tag, **kwargs):
class="ycr-regex" target="_blank">/.../</a>
"""
for a in soup.find_all("a", class_=["ycr-regex"]):
code = self.get_safe_text(a)
if code_tag := a.find("code"):
code = self.get_safe_text(code_tag)
else: # Fallback to text
code = self.get_safe_text(a)

code = code.replace("&", "\\&").replace("#", "\\#")
self.apply(a, "regex", code, url=safe_quote(a.get("href", "")))
return soup
Expand Down
1 change: 0 additions & 1 deletion hooks/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def handleMatch(self, m, data):
el.set("class", classes)
el.set("target", target)
el.text = f"`{regex}`"

return el, m.start(0), m.end(0)


Expand Down
19 changes: 11 additions & 8 deletions hooks/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
U+XXXX with a tag
"""

from xml.etree import ElementTree as etree

from markdown.extensions import Extension
from markdown.inlinepatterns import InlineProcessor

BASE_URL = 'https://symbl.cc/fr/'
BASE_URL = "https://symbl.cc/fr/"


class UnicodeProcessor(InlineProcessor):
def handleMatch(self, m, data):
unicode_code = m.group(1)
el = etree.Element("a")
el.set('href', f'{BASE_URL}/{unicode_code}')
el.set('class', 'ycr-callout ycr-unicode')
el.set('target', '_blank')
el.text = f'U+{unicode_code}'
el.set("href", f"{BASE_URL}/{unicode_code}")
el.set("class", "ycr-callout ycr-unicode")
el.set("target", "_blank")
el.text = f"{unicode_code}"
return el, m.start(0), m.end(0)


class UnicodeExtension(Extension):
def extendMarkdown(self, md):
UNICODE_RE = r'\bU\+([0-9A-F]{4,5})\b'
UNICODE_RE = r"\bU\+([0-9A-F]{4,5})\b"
unicode_pattern = UnicodeProcessor(UNICODE_RE, md)
md.inlinePatterns.register(unicode_pattern, 'unicode', 175)
md.inlinePatterns.register(unicode_pattern, "unicode", 175)


def on_config(config):
config['markdown_extensions'].append(UnicodeExtension())
config["markdown_extensions"].append(UnicodeExtension())
19 changes: 12 additions & 7 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ site_name: Le C pour l'ingénieur
site_url: https://heig-tin-info.github.io/handbook/
site_author: Yves Chevallier
site_description: |
Un manuel pour apprendre le langage C en partant de zéro.
Cours d'informatique pour les étudiants en ingénierie du département des
technologies industrielles à la HEIG-VD. Ce cours concerne le langage C et
les outils associés.
copyright: >
Copyright &copy; 2019 - 2024 HEIG-VD Yves Chevallier
<a href="#__consent">Changer les paramètres des cookies</a>
Expand All @@ -15,7 +17,10 @@ repo_name: heig-tin-info/handbook
repo_url: https://github.com/heig-tin-info/handbook
edit_uri: edit/master/docs/
docs_dir: !ENV [DOCS, docs]

validation:
omitted_files: warn
absolute_links: warn
unrecognized_links: warn
theme:
name: material
language: fr
Expand Down Expand Up @@ -49,16 +54,16 @@ theme:
- toc.follow
palette:
- scheme: default
#media: "(prefers-color-scheme: light)"
media: "(prefers-color-scheme: light)"
toggle:
icon: material/lightbulb
name: Switch to dark mode
primary: red
accent: light blue
- scheme: slate
#media: "(prefers-color-scheme: dark)"
primary: red
accent: light blue
media: "(prefers-color-scheme: dark)"
primary: black
accent: lime
toggle:
icon: material/lightbulb-outline
name: Switch to light mode
Expand Down Expand Up @@ -131,7 +136,7 @@ plugins:
markdown_extensions:
- toc:
toc_depth: 3
permalink: true
permalink: "¤"
- pymdownx.betterem:
smart_enable: all
- tables
Expand Down
15 changes: 8 additions & 7 deletions overrides/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
top: 0;
right: 0;
width: 40rem;
position:absolute;
position: absolute;
transform: translateX(5rem);
height: 100vh;
overflow: hidden;
Expand All @@ -93,20 +93,21 @@
<div class="mdx-hero">
<!-- Hero content -->
<div class="mdx-hero__content">
<h1>Un cours d'informatique pour ingénieur</h1>
<h1>Un cours d'informatique pour ingénieurs</h1>
<p>{{ config.site_description }}.</p>
<a href="{{ page.next_page.url | url }}" title="{{ page.next_page.title | e }}"
class="md-button md-button--primary">
Cours
Cours en ligne
</a>
<a href="{{ 'tools/' | url }}" title="Configuration de votre environnement de travail" class="md-button">
Environnement de travail
<a href="https://github.com/heig-tin-info/handbook/releases/latest/download/output-print.pdf"
title="Télécharger le PDF" class="md-button">
Télécharger le PDF
</a>
</div>
</div>
<!-- Hero image -->
<div class="mdx-hero__image">
<img src="assets/images/hero.png" alt="" draggable="false">
<img src="assets/images/hero.png" alt="" draggable="false">
</div>
</div>
</section>
Expand All @@ -116,4 +117,4 @@ <h1>Un cours d'informatique pour ingénieur</h1>
{% block content %}{% endblock %}

<!-- Application footer -->
{% block footer %}{% endblock %}
{% block footer %}{% endblock %}

0 comments on commit 611b91a

Please sign in to comment.