如何将所有资源为一个HTML文件? [英] How to include all resources into one html file?

查看:232
本文介绍了如何将所有资源为一个HTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有任何C#库或任何自由的工具,它可以与许多引用的资源一个HTML文件转换成一个全合一的HTML文件?



其主要任务是只有一个文件,这意味着我需要包括




  1. 的Javascript外部文件 - 这可能意味着全部替换脚本标签
    以「内容脚本」标签引用的文件中读取的src'按属性

  2. 图片 - 取代SRC =picture.png数据URI - 像SRC =数据:图像/ PNG; BASE64,encodedContent ......

  3. CSS文件

  4. 可能是我忘了什么事:)



本HTML文件必须在所有浏览器可读的,这就是为什么我不能使用MHT文件格式

解决方案

您可以使用 HTML敏捷包去读/写html文件。 HTML敏捷支持XPath,所以你可以得到你想要修改的节点列表。



使用这个工具,改变图像标记的属性值应该很容易。您还可以得到外部JS引用列表,阅读它们,然后相应地更新脚本标记。


is there any c# library or any free tool which can convert a html file with many referenced resources into a one "all-in-one" html file?

The main task is to have only one file, it means I need to include

  1. Javascript external files - this will probably mean replace all 'script' tags with 'src' attribute by 'script' tags with content read from referenced file.
  2. Images - replace src="picture.png" with data uri - something like src="data:image/png;base64,encodedContent..."
  3. CSS files
  4. may be i forgot something :)

This HTML file must be readable in all browsers, that's why I cannot use MHT file format (unreadable on Safari, iPad...)

解决方案

You can use HTML Agility Pack to go read/write the html document. HTML Agility supports XPath so you can get a list of nodes you want to modify.

Using this, changing the attribute value of image tags should be easy. You can also get a list of external js references, read them and then update the script tag accordingly.

这篇关于如何将所有资源为一个HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆