GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.96k stars 395 forks source link

Inline bold and italic styles are not handled #428

Closed mansooraziz closed 7 years ago

mansooraziz commented 7 years ago

Pressing ‘Bold’ button in tools just add or remove <b> tag around selected text. It doesn’t work well If there is a span tag with bold style

For example: I have a span <span style=”font-weight:bold”>Some Text</span>

If I select all the text and click on Bold button it will convert this to <span style=”font-weight:bold”><b>Some Text</b></span> Which doesn’t do anything as the text was already bold. Clicking on Bold again removes the <b> tags and again the text remains same as before i.e. Bold

Same issue is with Italic

Actually we are having this problem because we are converting the html to word and word to html using aspoes, and when we get the html from word, the <b> tags are converted to style=”font-weight:bold”. Here the editor fails to recognise if it’s bold or not.

Not sure how can I fix this. I think isApplied function should also look for style tag. and apply function should also apply on style tag

Can you please let me know if anything can be done? This is a very basic feature that is supposed to work and is require in our application.

anthonyjb commented 7 years ago

The <b> is a semantic tag and not the same as <span style="font-weight: bold;">, all that should happen when you select the bold tool when selecting a span tag (styled bold or otherwise) is it should wrap/unwrap that tag with a bold tag.

I would recommend you convert the relevant span tags before pasting them into the page.

This isn't a bug with editor - at least not in how I interpret what you're stating the issue is here.