如何使用Java以编程方式将网页的内部样式表转换为内联样式表?

时间:2022-05-29 05:38:41

Is there a ready-made tool or utility that does that already

是否有现成的工具或实用程序

1 个解决方案

#1


You could just open the CSS file and just embed its content into a style tag.

您只需打开CSS文件,然后将其内容嵌入到样式标记中即可。

It should not be that hard:

它不应该那么难:

FileReader frCSS = new FileReader("your_css.css");
FileReader frHTML = new FileReader("your_html.html");
FileWriter output = new FileWriter("result.html");

Then parse frHTML and copy its content to output until you find the head opening tag. When you do, open a style tag and copy all contents from frCSS. Then, close the style tag and copy the remaining portion of frHTML.

然后解析frHTML并将其内容复制到输出,直到找到head开头标记。执行此操作时,打开样式标记并从frCSS复制所有内容。然后,关闭样式标记并复制frHTML的剩余部分。

It's not pretty, but it can be done.

它不漂亮,但可以做到。

#1


You could just open the CSS file and just embed its content into a style tag.

您只需打开CSS文件,然后将其内容嵌入到样式标记中即可。

It should not be that hard:

它不应该那么难:

FileReader frCSS = new FileReader("your_css.css");
FileReader frHTML = new FileReader("your_html.html");
FileWriter output = new FileWriter("result.html");

Then parse frHTML and copy its content to output until you find the head opening tag. When you do, open a style tag and copy all contents from frCSS. Then, close the style tag and copy the remaining portion of frHTML.

然后解析frHTML并将其内容复制到输出,直到找到head开头标记。执行此操作时,打开样式标记并从frCSS复制所有内容。然后,关闭样式标记并复制frHTML的剩余部分。

It's not pretty, but it can be done.

它不漂亮,但可以做到。