<p>You could put the class on the parent element, and then target <code>.Bibliography &gt; ul</code> in your css.</p>

CC BY-SA 3.0
2014-08-21T17:05:22.613Z
2014-08-21T17:05:22.613Z
Marion Newlevant
<p>This is what I currently do to add a class <code>Bibliography</code> to all generated <code>&lt;ul&gt;</code> tags from my <code>articleBibliography</code> field. Because there's never other content in this field, I'm save to replace them all.</p>

<pre><code>{{ entry.articleBibliography|markdown|replace({'&lt;ul&gt;': '&lt;ul class="Bibliography"&gt;'})|raw }}
</code></pre>

<p>--</p>

<p><strong>Update:</strong>
You can also use the awesome Retcon plugin for this, it’s using DomDocument internally so the result should be more reliable.</p>

<pre><code>{{ entry.articleBibliography|markdown|retconAttr('ul', {'class': 'Bibliography'}) }}
</code></pre>

CC BY-SA 3.0
2017-09-29T12:24:17.980Z
How can I add a class to an anchor? This works, but I obviously don't want to hardcode `href` and `title`. Any ideas?
```
{{ block.text|markdown|replace({'<a href="http://example.com" title="example.com">': '<a href="http://example.com" class="my-class" title="example.com">'})|raw }}
```
Andrea DeMers
CC BY-SA 3.0
2017-09-29T13:17:12.287Z
@AndreaDeMers please see my update to the answer
carlcs
CC BY-SA 3.0
2014-08-20T09:07:03.663Z
2017-09-29T13:32:11.180Z
2017-09-29T13:32:11.180Z
carlcs
<p>What's a good way to add attributes (classes etc.) to the HTML elements returned from the <code>markdown</code> filter?</p>

<templating><css>
Markdown filter, how to add HTML attributes?
# Markdown filter, how to add HTML attributes?

(Asked by: username_0 on 2014-08-20)

What's a good way to add attributes (classes etc.) to the HTML elements returned from the `markdown` filter?

**Tags:** templating, css


---

## 2 answers

### Answer by username_0 on 2014-08-20. Score: 6 | Accepted answer

This is what I currently do to add a class Bibliography to all generated  tags from my articleBibliography field. Because there's never other content in this field, I'm save to replace them all.
{{ entry.articleBibliography|markdown|replace({'': ''})|raw }}

--
Update:
You can also use the awesome Retcon plugin for this, it’s using DomDocument internally so the result should be more reliable.
{{ entry.articleBibliography|markdown|retconAttr('ul', {'class': 'Bibliography'}) }}

> **Comments:**
> **username_2**: How can I add a class to an anchor? This works, but I obviously don't want to hardcode `href` and `title`. Any ideas? ``` {{ block.text|markdown|replace({'<a href="http://example.com" title="example.com">': '<a href="http://example.com" class="my-class" title="example.com">'})|raw }} ```  
> **username_0**: @AndreaDeMers please see my update to the answer  

---

### Answer by username_1 on 2014-08-21. Score: 2

You could put the class on the parent element, and then target `.Bibliography > ul` in your css.


---

