如何使用 bash 脚本或命令删除内部样式 (<style></style>)?
How to delete internal style (<style></style>) with bash script or command?
我正在努力实现最终自动化,以便在 project/folder 拥有的每个 html 页面中使用 CriticalCSS。
到目前为止,我已经能够通过此工作流程对每个 html 页面进行批评CSS:
https://github.com/Macleykun/voxsiren.net/blob/main/.github/workflows/criticalCSS.yml
但是,我遇到的唯一问题是如果新 html 是 added/changed。因此关键CSS发生了变化。
- 关键CSS添加另一个标签添加新的CSS
- 如果 html 是 removed/no 更长的关键 CSS css 留在原地。
我唯一的目标是做到以下几点:
检测到以:开头并以以下结尾的行
删除该行(我更喜欢批量处理,但如果有人建议在 python/etc 中这样做)。也可以。
我希望有人能够帮助我解决这个问题,甚至可以指出来源 material 供我研究以了解更多信息!
我尝试删除这种内部CSS:https://github.com/Macleykun/criticaltest/blob/main/404.html#L135
但是想要保留这个
https://github.com/Macleykun/criticaltest/blob/main/404.html#L11
取决于
https://github.com/Macleykun/criticaltest/blob/main/404.html#L134
例如:
<style>
bal bla bla
</style>
完好无损
但
<style>bal bla bla</style>
已删除
My only goal is to do the following:
Detect a line starting with: <style>
and ending with </style>
Remove the line
So that for example:
<style>
bal bla bla
</style>
is intact but
<style>bal bla bla</style>
is removed
如果您使用 sed
,您必须确保作为地址表达式一部分的分隔符前面有 \
:
sed -i '/<style>.*<\/style>$/d' file
我正在努力实现最终自动化,以便在 project/folder 拥有的每个 html 页面中使用 CriticalCSS。
到目前为止,我已经能够通过此工作流程对每个 html 页面进行批评CSS: https://github.com/Macleykun/voxsiren.net/blob/main/.github/workflows/criticalCSS.yml
但是,我遇到的唯一问题是如果新 html 是 added/changed。因此关键CSS发生了变化。
- 关键CSS添加另一个标签添加新的CSS
- 如果 html 是 removed/no 更长的关键 CSS css 留在原地。
我唯一的目标是做到以下几点:
检测到以:开头并以以下结尾的行 删除该行(我更喜欢批量处理,但如果有人建议在 python/etc 中这样做)。也可以。
我希望有人能够帮助我解决这个问题,甚至可以指出来源 material 供我研究以了解更多信息!
我尝试删除这种内部CSS:https://github.com/Macleykun/criticaltest/blob/main/404.html#L135 但是想要保留这个 https://github.com/Macleykun/criticaltest/blob/main/404.html#L11 取决于 https://github.com/Macleykun/criticaltest/blob/main/404.html#L134
例如:
<style>
bal bla bla
</style>
完好无损
但
<style>bal bla bla</style>
已删除
My only goal is to do the following:
Detect a line starting with:
<style>
and ending with</style>
Remove the line
So that for example:
<style> bal bla bla </style>
is intact but
<style>bal bla bla</style>
is removed
如果您使用 sed
,您必须确保作为地址表达式一部分的分隔符前面有 \
:
sed -i '/<style>.*<\/style>$/d' file