简体   繁体   English

如何将带有内容文件夹的HMTL文件转换为自包含的HTML文件

[英]How to convert HMTL file with content folder to a self-contained HTML file

How do I convert an HTML file with content folder to a self-contained HTML file which can be viewed from anywhere with its images etc. 如何将带有内容文件夹的HTML文件转换为自包含的HTML文件,可以从任何地方查看其文件等。

How can it be done so that its also Editable and stays self-contained post-edit. 如何才能使其也可以编辑并保持自包含的后期编辑。

I basically need to make HTML file based documentation which can be viewed from anywhere. 我基本上需要制作基于HTML文件的文档,可以从任何地方查看。 Unfortunately it HAS to be HTML, otherwise I would have made PDFs 不幸的是它是HTML,否则我会制作PDF

Thanks 谢谢

The most direct way is to convert all asset urls to data: urls . 最直接的方法是将所有资产网址转换为data:网址 (There are online coverters available that will take a provided asset and produce a data: url from it.) (有可用的在线变换器将获取提供的资产并生成data:来自它的URL。)

A possibly simpler way is to convert image and font urls to data: urls while instead inlining scripts and css. 一种可能更简单的方法是将图像和字体URL转换为data: urls而不是内联脚本和css。


Edit: Possibly of interest: inliner , a Node utility for doing this kind of thing. 编辑:可能有兴趣: inliner ,一个用于做这种事情的Node实用程序。 "Turns your web page to a single HTML file with everything inlined". “将您的网页变为单个HTML文件,内嵌所有内容”。 Also performs a number of minifying optimizations. 还执行许多缩小优化。

I don't know exactly what you're envisioning, but HTML was never meant to be fully self-contained. 我不确切地知道你想象的是什么,但HTML从来就不是完全独立的。 There may be some loopholes that allow it in the end, but to my knowledge there are no premade tools that do this 'conversion'. 可能有一些漏洞最终允许它,但据我所知,没有预制工具可以实现这种“转换”。 It would require the following things: 这需要以下几点:

  • Converting all linked style sheets and scripts to inline style sheets and scripts. 将所有链接的样式表和脚本转换为内联样式表和脚本。 This means that whenever there's a <script src="http://url.to/foo.js"></script> you'll have to download foo.js and include it as such: <script type="text/javascript"> [this is the content of foo.js] </script> . 这意味着只要有<script src="http://url.to/foo.js"></script>您就必须下载foo.js并将其包含在内: <script type="text/javascript"> [this is the content of foo.js] </script> Something similar applies to CSS and other linked source files. 类似的东西适用于CSS和其他链接的源文件。
  • Downloading all linked media (images mostly, I presume) and converting them to blobs (a service that provides you with a base64 blob you can use within a HTML file is https://www.base64-image.de/ ). 下载所有链接的媒体(主要是我假设的图像)并将它们转换为blob(为您提供可在HTML文件中使用的base64 blob的服务是https://www.base64-image.de/ )。 This means replacing <img src="http://url.to/image.jpg" /> with <img src="data:image/png;base64,[converted image data goes here] /> . So there's gonna be some manual labour involved there, but it probably can be done (almost) fully. 这意味着用<img src="http://url.to/image.jpg" /> <img src="data:image/png;base64,[converted image data goes here] />替换<img src="http://url.to/image.jpg" /> <img src="data:image/png;base64,[converted image data goes here] /> 。所以会有那里涉及一些体力劳动,但它可能(几乎)完全完成。

Possibly there's a way to accomplish what you're wanting to do another way though, what exactly is your reason for wanting this? 可能有一种方法可以完成你想要做的另一种方式,你究竟想要这个的原因是什么?

Here's another option: write your documentation in markup, then use a tool such as "Marked 2" ( http://marked2app.com ) to convert to self-contained html. 这是另一种选择:在标记中编写文档,然后使用诸如“Marked 2”( http://marked2app.com )之类的工具转换为自包含的 html。 Works slick. 工作光滑。 Plus you can go back and edit the markup any time you need to update your documentation, then simply re-export your html file. 此外,您可以在需要更新文档时返回并编辑标记,然后只需重新导出html文件即可。

You can use pandoc , it has an option to create self-contained html files https://pandoc.org/MANUAL.html#option--self-contained . 您可以使用pandoc ,它可以选择创建自包含的html文件https://pandoc.org/MANUAL.html#option--self-contained

If you start with html , this is the command. 如果你从html开始,这就是命令。

pandoc in.html --self-contained -o out.html

This tool can do a lot more things, for example, you can also generate html from markdown files or generate pdf s instead. 这个工具可以做更多的事情的东西,例如,您还可以生成html的降价文件或生成pdf !而非。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM