简体   繁体   English

在 Firefox 或 Chrome Inspector 中复制显示的 HTML(保持缩进和格式)

[英]Copy HTML in Firefox or Chrome Inspector as displayed (maintaining indentation and formatting)

I would like to know if there is a way, either in the inspector (developer tools) of Firefox or Chrome, to copy html exactly like the dev tool is displaying it.我想知道是否有办法在 Firefox 或 Chrome 的检查器(开发人员工具)中完全像开发工具显示的那样复制 html。

A lot of pages don't have well formatted code.许多页面没有格式良好的代码。 If you go to "View Source Code" (CTRL+U) it's sometimes a mess.如果您转到“查看源代码”(CTRL+U),有时会一团糟。 The dev tools of both browser do a very neat formatting and indentation, but I cannot figure out how to copy it.两个浏览器的开发工具都做了非常整洁的格式和缩进,但我不知道如何复制它。

For example, the code looks like this in the inspector:例如,检查器中的代码如下所示:

[Formatted code in Firefox dev tool] [Firefox 开发工具中的格式化代码]

Pasted to sublime text, it is just one long line of code:粘贴到崇高的文本,它只是一行代码:

<div class="mod_customnav block"><a href="startseite.html#skipNavigation50" class="invisible">Navigation überspringen</a><ul class="level_1"><li class="verband first"><a href="vereine.html" title="Die Vereine im Badischen Sportschützenverband" class="verband first">Vereine</a></li><li class="geschaeftsstelle"><a href="oeffnungzeiten.html" title="Die Öffnungszeiten der Geschäftsstelle" class="geschaeftsstelle">Öffnungzeiten</a></li><li class="geschaeftsstelle"><a href="anfahrtsplan.html" title="So finden Sie uns" class="geschaeftsstelle">Anfahrtsplan</a></li><li class="formulare"><a href="waffenrecht.html" title="Waffenrechtliche Formulare" class="formulare">Waffenrecht</a></li><li><a href="sitemap.html" title="Die Website im Überblick">Sitemap</a></li><li><a href="kontakt.html" title="Kontaktformular">Nachricht an uns</a></li><li class="last"><a href="impressum.html" title="Impressum" class="last">Impressum</a></li></ul><a id="skipNavigation50" class="invisible">&nbsp;</a></div>

As far as I know, there is no way to copy the HTML in a formatted way.据我所知,没有办法以格式化的方式复制 HTML。 Though, at least for the Firefox DevTools exists a feature request asking to allow to select the elements shown within the tree , so you can copy them.尽管如此,至少对于 Firefox DevTools 存在一个功能请求,要求允许选择树中显示的元素,因此您可以复制它们。 I'm not sure, though, whether this is meant to copy the elements in a formatted way or also just copies the HTML source.不过,我不确定这是否意味着以格式化的方式复制元素,还是只是复制 HTML 源代码。

Having said that, there are online tools like the Free Online HTML Formatter , which allow to do that.话虽如此,有一些在线工具,例如Free Online HTML Formatter ,可以做到这一点。

Theres an Sublime plugin which you can install Ctrl + O (shortcut to open search field for plugins i guess can't test now) "%Formater%" just type that in and install that HTML formatter plugin it should sort your code automatically.有一个 Sublime 插件,您可以安装 Ctrl + O(打开插件搜索字段的快捷方式,我想现在无法测试)“%Formater%”只需输入并安装该 HTML 格式化程序插件,它应该自动对您的代码进行排序。 Or use Atom.io, Brackets或者使用 Atom.io, Brackets

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM