Icône Discourse

:discourse2: Summary Discourse Icon allows you to use icons from your SVG icon subset in a post.
:eyeglasses: Preview Preview on Discourse Theme Creator
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-icon
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

Install this theme component

Features

Usage:

[wrap=icon id=square][/wrap]

Example:
This is the icon and the icon.

This is the [wrap=icon id=far-square][/wrap] icon and the [wrap=icon id=pencil][/wrap] icon.

Note: if the icon doesn’t show it’s because it’s not in your subset. If you are admin you can add it in your site settings: svg icon subset.


:discourse2: Hosted by us? Theme components are available to use on our Standard, Business, and Enterprise plans.

Last edited by @kelv 2025-04-28T07:23:04Z

Last checked by @Muhammed_EKİCİ 2024-12-02T09:46:54Z

Check documentPerform check on document:
31 « J'aime »

Awesome! This is iconic!

(meta has many many themes, but luckily thanks to @kris.kotlarek we have an add to all themes button… got to sort out progress there, cause it takes a while to do its magic)

13 « J'aime »

Yes didnt want to add to all for now, as I just finished coding it :grin: but will do now

Edit: oh already done

10 « J'aime »

Thanks, that’s super fun! :sunglasses:

I never got into BB script tags, nor have I hand-coded FontAwesome, so the practice of using an empty tag pair has always seemed strange to me. Is that by popular convention, or is there a webcraft reason for using tag pairs? Also, can they have stuff between them, does that affect the text?

3 « J'aime »

There are multiple causes here.

First when I wrote the wrap BBCode feature, @sam explicitly asked to me support 3 formats:

[wrap=foo][/wrap]
[wrap=foo]bar[/wrap]
[wrap=foo]
bar
[/wrap] 

This is done to be consistent with our existing BBCode usage in Discourse.

I could have a better syntax as: [icon=times] but then it would have to be a plugin and not a theme component.

As an experimentation, I think it’s fine as it is today, and if people were to use it a lot, we could think of having a plugin do this with a more concise syntax.

Another idea I have had is to add an API to add autocompletes symbol in the composer just like we have fore users/categories/emojis… But I’m afraid this would be a nightmare with multiple components choosing their own symbol…

5 « J'aime »

Oh! I need to add support for another bbcode and those) thought that I’d use this as a starting point, but you’re saying that the wrap stuff is handled in core, which explains why I can’t find how it’s handled by your theme component.

My current solution is to use the linked words component and an ugly regex, but I’m still struggling to add the necessary classes to the links.

3 « J'aime »

Yes read this topic to know more:

4 « J'aime »

Right I’ve looked at it a dozen times. And printed out the code for your component and stared at it for hours, trying to understand if the degree to which it’s javascript or ember that I don’t understand. I can’t add a [foo] tag without a plugin? Or can I some how replace wrap in your code with foo to cover my new bbcode?

1 « J'aime »

No you can’t. Because part of it is server side. If you want your own custom BBCode you will have to write a plugin and look at how wrap is implemented for example:

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/pretty-text/engines/discourse-markdown/d-wrap.js.es6

5 « J'aime »

Thanks! It’s starting to make sense. I’ve not had this much trouble learning a new language since C++ and objective Pascal in 1990.

My current regex hack almost works. I’ll need to decide whether to go the plugin route or stick with my hack (and figure out how to add the classes).

At least now I understand why I can’t find that wrap in the theme component!

3 « J'aime »

I can think of a few possible syntax layouts to add to the wrap plugin for this:

[wrap=foo /]
[wrap/=foo]

(mimicing XML’s self-closing tags) but those are both fairly ugly :confused:

Anyone got amazing ideas for something that looks okay?

3 « J'aime »

yeh not a big fan of these :confused:

6 « J'aime »

J’ai trouvé un gros bug…

Si vous utilisez un « icon wrap » puis que vous mettez en surbrillance la citation, l’image résultante est énormément agrandie :

  • Utilisez un « icon wrap » dans une phrase d’une publication. Par exemple : Ceci est une icône [wrap=icon id=far-check-square][/wrap]
  • Mettez en surbrillance le texte pertinent et cliquez sur « Citer »
  • L’icône devient super grande dans l’extrait cité

Voici à quoi ressemble la syntaxe lorsqu’elle est citée en surbrillance :

[quote="JammyDodger, post:1, topic:294, full:true"]
Ceci est une icône ![](/svg-sprite/grumpy.jammydodger.monster/icon/222222/far-check-square.svg)
[/quote]

Ceci est une réponse où elle devient énorme

Cependant, la citer en utilisant la bulle de dialogue dans la barre de format fonctionne très bien.

4 « J'aime »

Comment faites-vous pour mettre en surbrillance la citation de l’icône ? Sur mon site de test, l’icône est ignorée.

Je ne suis pas sûr ? J’utilise juste la souris.

Quel navigateur utilisez-vous ?

En utilisant la souris, j’ai testé avec Chrome et Firefox, et je n’ai pas pu sélectionner l’icône. :thinking:


EDIT :

Si vous encapsulez une icône indisponible dans le sous-ensemble actuel, cela créera une image SVG à la place.
Ensuite, vous pourrez la citer.

1 « J'aime »

Pouvez-vous fournir un exemple ? Votre capture d’écran montre une case à cocher cochée et je n’ai aucun problème à la sélectionner sur mon instance de test (ainsi que d’autres icônes probablement non utilisées par Discourse comme x-ray).

1 « J'aime »

Je vois le problème. Le composant recherche en vérifiant s’il existe un wrapper avec la classe d-wrap ; mais il n’y a pas de wrapper si l’icône fournie ne provient pas du sous-ensemble. Il crée une image en SVG à la place.

Par exemple :

SVG, icône dans le sous-ensemble

Image en SVG, icône non incluse dans le sous-ensemble

Si vous citez les images, le composant ne fait rien, car il n’y a pas de wrapper (et l’image est convertie en markdown, ce qui donne une image sans aucune classe)

1 « J'aime »

Est-ce que cela signifie que je dois avoir un champ svg_icons dans settings.yml disponible dans mon thème ? Ou pourrais-je utiliser n’importe quel champ svg_icons disponible à partir de n’importe quel composant de thème activé ? Et si tel est le cas, serait-il judicieux d’ajouter ce champ à ce composant de thème ?

svg_icons:
  default: ''
  type: 'list'
  list_type: 'compact'

Parce que d’après mon expérience, les icônes SVG sont transformées en balises <img /> et elles n’héritent pas de currentColor lorsque le schéma de couleurs est modifié :
Veuillez comparer le paragraphe Exemple :

2 « J'aime »

Le rendu en mode sombre pourrait-il être amélioré ?

J’aimerais avoir les mêmes couleurs que dans l’interface :

3 « J'aime »