2014-11-14 63 views
-2

如果你看一下Refactor JS demo,如果你點擊按鈕來顯示顯示內容的HTML源代碼Redactor JS如何管理顯示縮進代碼?

Redactor JS HTML View Button

...你可以看到一個良好的idented版本驗證碼:

enter image description here

幾乎所有的富文本編輯器/ WYSIWYG編輯器,我知道會顯示只有一行的代碼(沒有任何縮進)。

我無法理解這是如何完成的。你有什麼想法?

編輯:

現在看來,這不是很清楚。我的問題是這些細節文本如何被技術美化? 我知道jsbeautifier或那種真正包裝每行代碼的樣式的工具。 但是,如果您只是花時間去實際的鏈接並查看源代碼,則會看到正常的一行textarea顯示的很好,沒有任何顯着的CSS。

HTML

<textarea id="redactor" style="display: block; height: 797px;" dir="ltr"><h2>The Last of The Mohicans</h2> <p><em>by James Fenimore Cooper​​</em></p> <p>Winding its way among countless islands, and imbedded in mountains, the "holy lake" extended a dozen leagues still further to the south. With the high plain that there interposed itself to the further passage of the water, commenced a portage of as many miles, which conducted the adventurer to the banks of the Hudson, at a point where, with the usual obstructions of the rapids, or rifts, as they were then termed in the language of the country, the river became navigable to the tide.​</p> <p><img src="/img/redactor-image.jpg" width="1400" height="582"></p> <p>"Come," he said, with a good-humored smile; "the buck that will take to the water must be headed, and not followed."</p> <p>The route taken by Hawkeye lay across those sandy plains, relived by occasional valleys and swells of land, which had been traversed by their party on the morning of the same day, with the baffled Magua for their guide. The sun had now fallen low toward the distant mountains; and as their journey lay through the interminable forest, the heat was no longer oppressive. Their progress, in consequence, was proportionate; and long before the twilight gathered about them, they had made good many toilsome miles on their return.​</p> </textarea> 

以上是顯示良好預期,以及我的問題是爲什麼呢?/怎麼樣?

+1

請告訴你爲什麼downvote,我覺得這是一個合法的問題。 – lapin

+2

不是我的失望,但很難理解HTML格式化程序的優點。最簡單的,如果我們假設代碼以一條長線開始,找到所有結束標籤並在它們後面添加換行符。 – JJJ

+0

請訪問https://github.com/beautify-web/js-beautify查看http://jsbeautifier.org/(也可以美化HTML)及其源文件。 – Nit

回答

0

唯一的問題是,你用Firebug看,它似乎顯示textarea的原始內容,而不是它的當前值。

在控制檯中運行document.getElementById("redactor").value,你會看到它格式化,就像你看到的(這個格式是沒有什麼特別的其他評論已經指出的那樣)