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

推荐订阅源

GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
J
Java Code Geeks
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
宝玉的分享
宝玉的分享
Jina AI
Jina AI

博客园 - 工具人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 组件