Answers.Body: <p>The template engine (<a href="http://twig.sensiolabs.org/" rel="nofollow">Twig</a>) doesn't do anything like that – my guess is that the links only <em>appear</em> to render like your second example, because you're looking at the markup in your browser's dev tools, and modern browsers (e.g. Chrome) do a pretty good job of rendering invalid HTML.</p>
  
  <p>Take a look at the raw source code (i.e. "View source" in your browser), and I suspect the actual rendered HTML will look exactly like your first example.</p>
  
  <p>In any case, nesting <code>&lt;a&gt;</code> tags is not allowed and a very bad idea – so I'd recommend not doing it all :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-26T16:14:15.177Z
Answers.Text: If you ignore the phrase "template engine" , I think what he's asking is not about Twig but actually Redactor.    If you paste the snippet mentioned into source code mode, Redactor will do exactly as he mentions. I can see how some users might think that's part of the the "template engine."
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-26T16:45:42.913Z
Answers.Text: @RitterKnight You might be right, and you should add an additional answer - if the OP is talking about Redactor, it might be that turning off the "Purify HTML?" option for the Rich Text field will do the trick. Still a bad idea, though :)
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-26T10:45:16.063Z
Answers.LastActivityDate: 2016-08-26T15:40:36.543Z
Answers.LastEditDate: 2016-08-26T15:40:36.543Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <p>Redactor is, very sensibly, correcting your invalid html. <strong>You can't have links inside links</strong>, the spec does not allow it: <a href="https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element">https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element</a></p>
  
  <p>Even if Redactor didn't do this, the browser will treat your invalid html as invalid and take a best guess at reconstructing it to form valid html; probably with varying results.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-30T10:44:56.253Z
Answers.LastActivityDate: 2016-08-30T10:44:56.253Z
Answers.UserDisplayName: Seth Warburton
Body: <p>I have a little issue with Redactor. Whenever I have a link within a link: </p>
  
  <pre><code>&lt;a href="#"&gt;main link &lt;a href="#"&gt;link within link&lt;/a&gt; &lt;/a&gt;
  </code></pre>
  
  <p>Redactor automatically modifies it to this:</p>
  
  <pre><code>&lt;a href="#"&gt;main link&lt;/a&gt; &lt;a href="#"&gt;link within link&lt;/a&gt;
  </code></pre>
  
  <p>Is there a way to stop this auto-modification?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-26T16:15:26.780Z
Comments.Text: Redactor, Craft's rich text editor, actually does this, not the "template engine" (Twig). Is that what you mean?
Comments.UserDisplayName: RitterKnight
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-26T16:48:10.317Z
Comments.Text: As this is a Twig related question (or possibly, Redactor, as per @RitterKnight's comment) I think this question is absolutely relevant and shouldn't be closed.
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-27T22:10:38.623Z
Comments.Text: @MatsMikkelRummelhoff: Agreed, great catch. Voting to "leave open", and I'll edit the question to better reflect Redactor's role.
Comments.UserDisplayName: Lindsey D
Tags: <redactor>
Title: Redactor splitting nested <a> tags
ThreadText: # Redactor splitting nested <a> tags
  
  (Asked by: username_0 on 2016-08-26)
  
  I have a little issue with Redactor. Whenever I have a link within a link:
  
  ```
  <a href="#">main link <a href="#">link within link</a> </a>
  
  ```
  
  Redactor automatically modifies it to this:
  
  ```
  <a href="#">main link</a> <a href="#">link within link</a>
  
  ```
  
  Is there a way to stop this auto-modification?
  
  **Tags:** redactor
  
  > **Comments:**
  > **username_1**: Redactor, Craft's rich text editor, actually does this, not the "template engine" (Twig). Is that what you mean?  
  > **username_2**: As this is a Twig related question (or possibly, Redactor, as per @username_1's comment) I think this question is absolutely relevant and shouldn't be closed.  
  > **username_3**: @username_2: Agreed, great catch. Voting to "leave open", and I'll edit the question to better reflect Redactor's role.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-08-26. Score: 6
  
  The template engine ([Twig](http://twig.sensiolabs.org/)) doesn't do anything like that – my guess is that the links only *appear* to render like your second example, because you're looking at the markup in your browser's dev tools, and modern browsers (e.g. Chrome) do a pretty good job of rendering invalid HTML.
  
  Take a look at the raw source code (i.e. "View source" in your browser), and I suspect the actual rendered HTML will look exactly like your first example.
  
  In any case, nesting `<a>` tags is not allowed and a very bad idea – so I'd recommend not doing it all :)
  
  > **Comments:**
  > **username_1**: If you ignore the phrase "template engine" , I think what he's asking is not about Twig but actually Redactor.    If you paste the snippet mentioned into source code mode, Redactor will do exactly as he mentions. I can see how some users might think that's part of the the "template engine."  
  > **username_2**: @username_1 You might be right, and you should add an additional answer - if the OP is talking about Redactor, it might be that turning off the "Purify HTML?" option for the Rich Text field will do the trick. Still a bad idea, though :)  
  
  ---
  
  ### Answer by username_4 on 2016-08-30. Score: 5
  
  Redactor is, very sensibly, correcting your invalid html. **You can't have links inside links**, the spec does not allow it: <https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element>
  
  Even if Redactor didn't do this, the browser will treat your invalid html as invalid and take a best guess at reconstructing it to form valid html; probably with varying results.
  
  
  ---
  
  