簡體   English   中英

鏡像HTML的CSS Attr到Codemirror(插入新行)

[英]Mirror HTML's CSS Attr To Codemirror (insert new line)

小提琴 - http://jsfiddle.net/Mukdf/

今天我決定將一個html的css attr鏡像到Codemirror,以查看它是否可以渲染干凈的CSS而不是一行。

這是被鏡像到Codemirror的CSS ...

display: inherit; position: absolute; top: 20px; left: 19px; margin: 10px; width: 340px; height: 234px; padding: 1em; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; font-family: arial; line-height: normal; color: rgb(255, 255, 255); border: 0px dashed rgb(0, 255, 255); border-top-left-radius: 0em; border-top-right-radius: 0em; border-bottom-right-radius: 0em; border-bottom-left-radius: 0em; background-color: rgb(0, 34, 102); text-shadow: rgb(255, 255, 255) 0px 0px 8px; overflow: visible; z-index: 0;

我試着把它顯示出來......

display: inherit; 
position: absolute; 
top: 20px; 
left: 19px; 
margin: 10px; 
width: 340px; 
height: 234px; 
padding: 1em; 
font-style: normal; 
font-variant: normal; 
font-weight: normal; 
font-size: 14px; 
font-family: arial; 
line-height: normal; 
color: rgb(255, 255, 255); 
border: 0px dashed rgb(0, 255, 255); 
border-top-left-radius: 0em; 
border-top-right-radius: 0em; 
border-bottom-right-radius: 0em; 
border-bottom-left-radius: 0em; 
background-color: rgb(0, 34, 102); 
text-shadow: rgb(255, 255, 255) 0px 0px 8px; 
overflow: visible; 
z-index: 0;

我知道這是可能的我只是不知道如何去做。 我想找; 並用相同的字符替換它,但在末尾添加換行符。

任何幫助是極大的贊賞。

這是我的JQuery / JS ......

$('.div-style').val($('.box').attr('style'));

$('.code').each(function() {
    CodeMirror(this, {
        value: $('.div-style').val(),
        mode: 'text/css',
        lineNumbers: true,
        lineWrapping: true,
        readOnly: true
    });
});

將所有分號更改為分號后跟換行符的全局替換將是:

$('.div-style').val().replace(/;/g,";\n")

雖然你會注意到在所有行的開頭留下了一個空格,但是第一行是因為你的輸入在每個分號后面都有一個空格: http//jsfiddle.net/Mukdf/1/

也許這個:

$('.div-style').val().replace(/;\s?/g,";\n")

演示: http//jsfiddle.net/Mukdf/2/

或者/;\\s*/g如果要在每個分號后允許任意數量的空格(包括零)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM