Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Anchor Tags with  


Reply


4 Posts   2424 Views

Avatar
edwardlewis

Community Member, 32 Posts

17 August 2011 at 9:04pm

I have tried adding some anchor tags using the editor and cant work out how to do it.. whenever I put them in, it creates a link with a space in there, eg:

<a name="name-of-link">&nbsp;</a>

Is there a reason for this or a way to stop it?

Avatar
martimiz

Forum Moderator, 1105 Posts

17 August 2011 at 10:20pm

I think this a TinyMCE issue rather then a SilverStripe one. TinyMCE is set to not accept emty tags like that, so it'll add a non-breakable space to it. If you really want it removed you should probably look on the TinyMCE forums...

But on some browsers an empty anchor tag wouldn't even work. Would it be a good idea to move the anchor to a spot where the space doesn't hurt, like at the end of an article title?

Avatar
Jedateach

Forum Moderator, 232 Posts

24 November 2011 at 2:31pm

Edited: 24/11/2011 2:32pm

I have a similar problem where the anchor tags are showing an underlined space.

html produced by tinymce/ss insert link:

<h2><a name="myanchor">&nbsp;</a>My heading here</h2>


produces:

_My heading here

Avatar
martimiz

Forum Moderator, 1105 Posts

25 November 2011 at 12:42am

Edited: 25/11/2011 12:42am

An anchor tag is just another <a>...</a> tag and by default these appear underlined, even for spaces... So apart from getting rid of the added $nbsp; all together, you'll probably have to handle this in css.

Btw: you can disable the automatic addition of the nonbreakable space from an empty anchor. In cms/config.php:

valid_elements' => "@[id|class|style|title],#a[id|rel|...

becomes

valid_elements' => "@[id|class|style|title],a[id|rel|...

But (some?) browsers will now show the text to the right of the anchor as a link, thinking you must have misplaced the anchor's end tag - all this apart from the discussion that there shouldn't be any empty tags in HTML. Replace the &nbsp; with a <!-- anchor --> will not work: /sapphire/javascript/tinyMCE_improvements.js->sapphiremce_cleanup() will strip them out. So again, wherever possible I just put my anchors to the right of the text...