Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7852147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:21:10+00:00 2026-06-02T19:21:10+00:00

I am using a utility called FresherEditor which uses the ContentEditable plugin for jQuery

  • 0

I am using a utility called FresherEditor which uses the ContentEditable plugin for jQuery to create an editable document in the browser window. I then need to take that output and generate SVG graphics from the rules obtained by parsing the HTML governed style into CSS.

The freshereditor will produce output that looks somewhat like:

<div>
  <p>
   <i>
    <u>
     <b>
      <font face="Verdana">
       Hello, World!
      </font>
     </b>
    </u>
   </i>
  </p>
</div>

When what I would prefer is something that looks like:

<div>
 <p style="font-weight: bold; font-style: italic; text-decoration: underline; font-family: Verdana;">
  Hello, World!
 </p>
</div>

Any suggestions would be helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:21:11+00:00Added an answer on June 2, 2026 at 7:21 pm

    This was a very fun problem; thanks! Following are scripts that add html2style() and style2html() methods. The test case shows that you can convert between the two with no visual change (though the ordering of the element nesting may be different after a round trip).

    Test Case Showing These Working

    http://jsfiddle.net/GaPBS/

    Converting Nested HTML Phrase Elements to Style Attributes

    (function(scope){
      var HTML2CSS = {
        strong: function(e){ this.style.fontWeight = "bold";                  },
        b:      function(e){ this.style.fontWeight = "bold";                  },
        em:     function(e){ this.style.fontStyle = "italic";                 },
        i:      function(e){ this.style.fontStyle = "italic";                 },
        font:   function(e){ this.style.fontFamily = e.getAttribute('face');  },
        u:      function(e){ this.style.textDecoration += ' underline';       },
        strike: function(e){ this.style.textDecoration += ' line-through';    }
      };
      scope.html2style = function(root){
        for (var name in HTML2CSS){
          var elements = root.querySelectorAll(name);
          var styler   = HTML2CSS[name];
          for (var i=elements.length;i--;){
            var toKill = elements[i],
                parent = toKill.parentNode;
            // Only swap out nodes that are the sole element child of the parent
            if (!toKill.nextElementSibling && !toKill.previousElementSibling){
              parent.removeChild(toKill);
              // Move contents into the parent
              for (var kids=toKill.childNodes,j=kids.length;j--;){
                parent.insertBefore(kids[j],parent.firstChild);
              }
              // Merge existing styles from this node onto the parent
              parent.style.cssText += toKill.style.cssText;  
              // Hard set the style for this node onto the parent
              styler.call(parent,toKill);
            }
          }
        }
      }
    })(this);
    

    Converting Style Attributes to Nested HTML Phrase Elements

    (function(scope){
      var CSS2HTML = {
        "fontWeight:bold":             "b",
        "fontStyle:italic":            "i",
        "textDecoration:underline":    "u",
        "textDecoration:line-through": "strike",
        "font-family:*":                function(value){ var e=document.createElement('font'); e.setAttribute('face',value); return e; }
      };
      scope.style2html = function(root){
        var leaf = root;
        for (var style in CSS2HTML){
          var elName = CSS2HTML[style],
              parts  = style.split(':'),
              name   = parts[0],
              wild   = parts[1]=="*",
              regex  = !wild && new RegExp("(^|\\s)"+parts[1]+"(\\s|$)"),
              before = root.style[name];
          if (before && (wild || regex.test(before))){
            var el = (typeof elName==='function') ? elName(before) : document.createElement(elName);
            for (var kids=leaf.childNodes,j=kids.length;j--;){
              el.insertBefore(kids[j],el.firstChild);
            }
            leaf = leaf.appendChild(el);
            root.style[name]=wild ? "" : before.replace(regex,"");
          }
        }
        if (root.getAttribute('style')=="") root.removeAttribute('style');
      }
    })(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Jquery has utility a function called ' extend ' which can be used to
I want to create a windows utility application, which can be called anytime from
I'm using the openssl utility of debian in order to create a certificate. The
I'm considering using this jquery utility as a possible solution, but I want to
I need to create javascript library which will be called from other javascript code.
I'm using a utility called UrlReplacer to enable the configuration of friendly Urls for
I am using an interface called Predicate which is used for sifting through Collections.
I'm using the jQuery plugin Uploadify to upload videos to my server. As soon
I'm using the Utility Application template to build my app. Having a hard time
I'm developing a twitter messaging utility using Twitter API (twitterizer). But since I'm within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.