javascript - Globally Replace The / Character -


fiddle - http://codepen.io/mikethedj4/pen/bcjun

enter image description here

i've been working on website designer tablet , it's ready release, have 1 problem.

you see while i'm adjusting style properties nice visual style default browser adds css modifications of element style attribute. i'm sure of aware of.

i've been able remove style attribute mirroring whole canvas's html div , removing style in div designing area/canvas still works intended.

what i'm trying grab , mirror textarea while grabbing it's children. can see in fiddle on codepen. question how can grab it's children's css while showing seen in screenshot.

edit:
tried this, grab first element...

$('.preview').children().prop("tagname").tolowercase() + '.' + $('.preview').children().prop("classname") + ' {\n ' +  $('.preview').children().attr('style').replace(/;/g,";\n") + '}' 

recently gave try...

$('.hidden-preview').html($('.preview').html()); $('.hidden-preview').children("*").html(""); $(".hidden-preview *").removeattr('contenteditable'); $(".code").val($(".hidden-preview").html().replace(/>/g,'').replace(/</g,'').replace(/style="/g,'{\n ').replace(/class="/g,'.').replace(/"/g,'').replace(/;/g,';\n') + "}\n\n"); 

it seems work best, can't rid of / closing element in i'm trying add closing css bracket }.

example...

.replace(/ //g,'}') 

any appreciated.

you need few modifications: rid of closing tags' opening bracket:

.replace(/<\/?/g,'')  

the \/? optional (and escaped) /

use extract style:

.replace(/style="([^"]+)"/g,'{\n $1 } ') 

this captures non " character , reference \1 style="foo" becomes {\nfoo}

lose replacement " , appending of } end

(i've updated fiddle)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -