Skip to content

Ajout du composant DSFR "highlight" #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Pour une démonstration, voir la [GitHub Pages](https://codegouvfr.github.io/ele
- [Partie blog du site de DiaLog](https://dialog.beta.gouv.fr/blog/fr/) (code source : https://github.com/MTES-MCT/dialog/tree/main/blog)
- [Site de la start-up Médiation Logement](https://mediationlogement.beta.gouv.fr/) (code source : https://github.com/betagouv/mediation-logement)
- [Portail du BARRI du CISIRH](https://cisirh.github.io/portail-barri/fr/) (code source : https://github.com/CISIRH/portail-barri)
- [Site du service Fonds de cartes]() (code source : https://github.com/betagouv/fonds-de-cartes)

## Licence

Expand Down
6 changes: 6 additions & 0 deletions _includes/components/highlight.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% if not highlight %}{% set highlight = params %}{% endif %}
<div class="fr-highlight">
<p>
{{ highlight.description }}
</p>
</div>
10 changes: 10 additions & 0 deletions content/fr/blog/posts/md-cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ Les parents d’enfants de 11 à 14 ans n’ont aucune démarche à accomplir :

[Voir aussi](/fr/blog/mise-en-avant/#exemple-d-utilisation-dans-un-fichier-markdown-md){.fr-link .fr-fi-arrow-right-line .fr-link--icon-right}

## La mise en exergue

```md
:::highlight
Les parents d’enfants de 11 à 14 ans n’ont aucune démarche à accomplir : les CAF versent <strong>automatiquement</strong> l’ARS aux familles déjà allocataires qui remplissent les conditions.
:::
```

[Voir aussi](/fr/blog/mise-en-exergue/#exemple-d-utilisation-dans-un-fichier-markdown-md){.fr-link .fr-fi-arrow-right-line .fr-link--icon-right}

<br>

La syntaxe utilisée pour le [cartouche](https://www.11ty.dev/docs/data-frontmatter/) en début de fichier est communément le [YAML](https://learnxinyminutes.com/docs/yaml/).
Expand Down
40 changes: 40 additions & 0 deletions content/fr/blog/posts/mise-en-exergue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Mise en exergue
description: Comment intégrer une mise en exergue dans une page du site ?
date: git Last Modified
tags:
- DSFR
- composant
---
Chaque composant peut être inclus dans un fichier Nunjucks `.njk` ou Markdown `.md`.

## Utilisation

### Exemple d'utilisation dans un fichier Markdown `.md`

Seule la description est disponible.

```md
:::highlight
Contenu **Mardown**
:::
```

### Exemple d'utilisation dans un fichier Nunjucks `.njk`

```njk
{% raw %}
{% from "components/component.njk" import component with context %}
{{ component("highlight", {
description: "Contenu <strong>HTML</strong>"
}) }}
{% endraw %}
```

## Rendu

:::highlight
Contenu **Mardown**
:::

[Voir aussi la page du composant sur le site du DSFR](https://www.systeme-de-design.gouv.fr/composants-et-modeles/composants/mise-en-exergue){.fr-link .fr-fi-arrow-right-line .fr-link--icon-right}
4 changes: 4 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ module.exports = function (eleventyConfig) {
mdLib.use(markdownItContainer, 'callout', customMarkdownContainers.callout(mdLib));
});

eleventyConfig.amendLibrary("md", mdLib => {
mdLib.use(markdownItContainer, 'highlight', customMarkdownContainers.highlight(mdLib));
});

eleventyConfig.amendLibrary("md", mdLib => {
mdLib.use(markdownItContainer, 'quote', customMarkdownContainers.quote(mdLib));
});
Expand Down
24 changes: 24 additions & 0 deletions markdown-custom-containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ module.exports = {
}
}
},
highlight: () => {
const re = /^highlight$/;
return {
validate: (params) => {
return params.trim().match(re);
},

render: (tokens, idx) => {
if (tokens[idx].nesting === 1) {
// opening tag
return `
<div class="fr-highlight">
<p>
`;
} else {
// closing tag
return `
</p>
</div>
\n`;
}
}
}
},
quote: md => {
const re = /^quote(\s+.*)?$/
let params = undefined;
Expand Down