2013-12-16 63 views
2

我使用未格式化的CSS字符串填充我的CodeMirror textarea。我無法控制這個CSS的格式。自動格式CodeMirror

未格式化的CSS例子

position: absolute; top: 66px; left: 746px; width: 399px; height: 353px; background-color: pink; 

當我設置該字符串作爲CodeMirror textarea的價值,它看起來像這樣:

enter image description here

我希望它看起來像這樣:

enter image description here

我試過AutoFormatDateRange但我認爲該功能已被刪除?

回答

0

你應該可以使用.autoFormatRange(),但我認爲你的CSS必須包裝在<style></style>標籤CodeMirror知道如何格式化你的字符串。

編輯

我沒用過CodeMirror這樣我自己,但在這裏插入您的字符串沒有工作:

http://codemirror.net/2/demo/formatting.html

<style></style>包裝時它又被格式化爲預期。

+2

.autoFormatRange()是/lib/util/formatting.js中的一個擴展,從版本3.11(2013年3月20日)開始已被刪除。我已經嘗試在v3.20中使用該代碼,它部分工作,但有一個錯誤,我不想調試。 – secretwep