Cross-Platform Way of Creating Safari Webarchives

痞子三分冷 提交于 2019-11-29 06:38:41

To expand on what Ben said: CFLite (the cross-platform open-source subset of Core Foundation) ships with a plist parser. If you can link against that, it should be quite simple to work with .webarchive files, which are simply property lists that concatenate all files (HTML, CSS, etc.) into one.

There are other libraries as well, such as Mac-PropertyList on CPAN for Perl.

I believe the format for .webarchives is officially undocumented, but it's just a plist. You can open it in the Property List Editor and examine its contents. Shouldn't be to hard to replicate most, if not all, of what's in there.

Tried textutil, but that only uses the Cocoa text system and as such fails at css, js and such.

There's a nice GitHub project: https://github.com/takebayashi/STWebArchiver

It uses Webkit to write .webarchive files. Needs some customization for your needs…

Webarchive creation is part of Webkit luckily, as such you can use the following for working with them on the Mac:

http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/WebKit/Classes/WebArchive_Class/Reference/Reference.html

Or, use this sourcecode to understand the format in usage:

http://trac.webkit.org/browser/trunk/WebKit/mac/WebView/WebArchive.mm

It's not cross-plattform, but on the Mac

textutil -convert webarchive whatever.html

does the job. Not sure whether you can easily include images etc. though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!