question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I remove inline styles from generated HTML

See original GitHub issue

Apologies if I am missing something here. Adding <li> items in the editor creates <span style="line-height: 1.4em; background-color: initial;">. How do I stop the styles from being added, or at least stop it from submitting with the styles?

Great editor, btw 😃

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
kntmrkmcommented, Nov 18, 2015

In my case. Temporary hack is below. but it’s very dirty. I’m waiting for better solution.

function cleanUpWasteCode($textarea) {
    var textReplaced = $textarea.val();
    textReplaced = textReplaced.replace(/<strong><br><\/strong>/g, '<br>');
    textReplaced = textReplaced.replace(/<p><br><\/p>/g, '<br>');
    textReplaced = textReplaced.replace(/<strong><\/strong>/g, '');
    textReplaced = textReplaced.replace(/<p><\/p>/g, ''); // put last.

    // for chrome bug. https://github.com/Alex-D/Trumbowyg/issues/103
    textReplaced = textReplaced.replace(/ ?face=[\d\D]* ?/g, '');
    textReplaced = textReplaced.replace(/ ?font-family:[\d\D]*; ?/g, '');
    textReplaced = textReplaced.replace(/ ?font-family:[\d\D]*; ?/g, '');
    textReplaced = textReplaced.replace(/ ?font-size:[\d\D]*; ?/g, '');
    textReplaced = textReplaced.replace(/ ?font-weight:[\d\D]*; ?/g, '');
    textReplaced = textReplaced.replace(/ ?line-height:[\d\D]*; ?/g, '');
    textReplaced = textReplaced.replace(/ ?background-color:[\d\D]*; ?/g, '');
    textReplaced = textReplaced.replace(/ ?color:[\d\D]*; ?/g, '');

    textReplaced = textReplaced.replace(/ ?id="null" ?/g, '');
    textReplaced = textReplaced.replace(/ ?text-align: left; ?/g, '');
    textReplaced = textReplaced.replace(/ style=""/g, '');
    textReplaced = textReplaced.replace(/<>/g, '');
    $textarea.val(textReplaced);
  }

  options = {
    lang: 'ja',
    semantic: true, resetCss: true,
    removeformatPasted: true, // ver. 2.0.0
    fullscreenable: false,
    autogrow: true,
    btns: btns, closable: false
  };

  $('.markdown').trumbowyg(options)
    .on('tbwblur', function() {
      cleanUpWasteCode($(this));
    });
0reactions
Alex-Dcommented, Aug 16, 2016

Can’t reproduce each time, sorry I don’t have the time to fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove inline styles - Html-cleaner.com
Using inline styles means that the styles of the elements are not given by classes or ids but it's specified within the HTML...
Read more >
Remove inline css of an HTML elements - javascript
Use the removeAttribute method, if you want to delete all the inline style you added manually with javascript. element.
Read more >
How to Fix & Remove Inline CSS - YouTube
Learn how to fix inline CSS in your code, and speed up both your development time and website in the process. Test your...
Read more >
How to clear all inline styles from an HTML element - Evan Hahn
In short: set the styles to the empty string to clear all styles (for example, myElement.style.cssText = ""; ).
Read more >
remove-style - npm
You can pass HTML strings as argument to Remove-Style to remove inline styles. In that case, Remove-Style returns the removed styles' HTML ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found