Answers.Body: <p>You could put the class on the parent element, and then target <code>.Bibliography &gt; ul</code> in your css.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-21T17:05:22.613Z
Answers.LastActivityDate: 2014-08-21T17:05:22.613Z
Answers.UserDisplayName: Marion Newlevant
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-29T12:24:17.980Z
Answers.Text: 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 }}
  ```
Answers.UserDisplayName: Andrea DeMers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-29T13:17:12.287Z
Answers.Text: @AndreaDeMers please see my update to the answer
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-20T09:07:03.663Z
Answers.LastActivityDate: 2017-09-29T13:32:11.180Z
Answers.LastEditDate: 2017-09-29T13:32:11.180Z
Answers.UserDisplayName: carlcs
Body: <p>What's a good way to add attributes (classes etc.) to the HTML elements returned from the <code>markdown</code> filter?</p>
  
Tags: <templating><css>
Title: Markdown filter, how to add HTML attributes?
ThreadText: # 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 `<ul>` 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({'<ul>': '<ul class="Bibliography">'})|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**: @username_2 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.
  
  
  ---
  
  