Ajout de classes aux liens dans le corps du message pour le style

Existe-t-il un moyen d’éviter que Discourse reformatte un lien d’ancrage comme nous souhaitons l’afficher, c’est-à-dire sous forme de bouton avec un style spécifique ?

Le message est publié avec la propriété .raw (j’ai essayé d’utiliser .cooked, mais cela ne semble pas pris en charge, malgré ce que l’API indique).

En publiant :
<a aria-label="homepage-link" href="http://blablabla...">View Homepage</a>

Cela s’affiche dans le message Discourse, ou dans la description de la catégorie, sous la forme :
<div class="cooked"><a>View Homepage</a></div>

J’ai également essayé :

[View this page][http://blablabla]

Et cela a été converti en :
<div class="cooked"><a href="http://blablabla" class="onebox" target="_blank">http://blablabla</a></div>

Cependant, si je pouvais simplement obtenir :
<div class="cooked"><a href="http://blablabla" class="onebox" target="_blank">View this page</a></div>

Je pourrais éventuellement le cibler via CSS depuis l’élément body pour appliquer le style de bouton CSS dont nous avons besoin.

Resolved I think…

[view this page](http://blablabla)

Target CSS using:

body.<insert name of top category here>-* div.cooked a

However

If someone has a solution for the above it would be a little cleaner and easier to add our own classes to the <a> link and avoid top Category.

Thanks in advance.

The way to do that is to use something like

For example

[wrap=link-button][Link Text](http://meta.discourse.org)[/wrap]

renders as

and the markup is

<div class="d-wrap" data-wrap="link-button">
  <p>
    <a href="http://meta.discourse.org">Link Text</a>
  </p>
</div>

and you can then style it in CSS using

[data-wrap="link-button"] {
  a {
    // styles for the link
  }
}

You can change [wrap=link-button] to any value you want like

[wrap=custom-button]
or
[wrap=home-link]
or
[wrap=foobar]

and then use that to target the link like the example above.

8 « J'aime »

@Johani Very interesting!!! Thanks for your work on this, we will look into this option, it would be great to have in the API docs on Post raw property settings in the future. Or a central doc that groups/defines all possibilities with Post’s UPDATE:/POST: property