惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - 工具人Kim哥

mysql数据库备份命令大全 Vue获取url网址参数的两种方法 在vscode下编译vue神坑40% building 过不去 PHP获取本周的每一天的时间 vue元素对齐方式 一个身高体重测量工具(BMI测量工具) 一个不错的常用小工具站点 Fiddler使用 不错的SDL源码分析 unity3d中获得物体的size PPT文化 Unity消息 Unity3D中的UnitySendMessage方法的使用 Android性能优化之渲染 问题记录 VS2012项目中使用CocoStudio相关文件的设置 国际金融基础知识 Nutch 安装文档 sed linux 命令
HTML代码格式化实现方式
工具人Kim哥 · 2023-07-10 · via 博客园 - 工具人Kim哥

开发过程中,经常遇到html被压缩了无法查看,需要对html进行格式化,

或者html写的比较乱,需要格式化, 那么HTML格式化的方式有哪些?

总结下来有几种:

1.手动编辑:使用编辑器手动对HTML代码进行格式化和缩进。
2.在线工具:使用在线HTML格式化工具,如Code Beautify、HTML Formatter等。
3.文本编辑器插件:使用文本编辑器插件,如Notepad++等。
4.代码编辑器:使用代码编辑器,如Sublime Text、Atom等,这些编辑器都有插件或扩展可用于格式化HTML代码。
5.命令行工具:使用命令行工具,如HTML Tidy、HTML Beautifier等。
6.自动化工具:使用自动化工具,如Gulp、Grunt等,这些工具可以自动化地格式化HTML代码

其实,基本上没有必要自己实现,比如 这些在线工具可以直接实现, 直接打开:

https://www.guud.cn/tools/html-formatter.html

查看源码可知,使用的是

 1 /*
 2   源码地址
 3   https://www.guud.cn/tools/html-formatter.html
 4 */
 5 var options = {
 6     "indent_size": indent_size,
 7     "indent_char": indent_char,
 8     "max_preserve_newlines": "5",
 9     "preserve_newlines": true,
10    "keep_array_indentation": false,
11    "break_chained_methods": false,
12    "indent_scripts": "normal",
13    "brace_style": "collapse",
14    "space_before_conditional": true,
15    "unescape_strings": false,
16    "jslint_happy": false,
17    "end_with_newline": end_with_newline,
18    "wrap_line_length": wrap_line_length,
19    "indent_inner_html": indent_inner_html,
20    "comma_first": false,
21    "e4x": false,
22    "indent_empty_lines": false
23 };
24 
25 
26 sFormat = html_beautify(text, options);


使用的是 beautify-html 组件