Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mn4367 committed May 6, 2018
1 parent 5a556da commit 37dbba0
Show file tree
Hide file tree
Showing 12 changed files with 2,606 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
backup
dependencies
lib
out
htmlresemb.exe
htmlresemb
18 changes: 9 additions & 9 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
MIT License
The MIT License (MIT)

Copyright (c) 2018 idesis GmbH
Copyright (c) 2018 idesis GmbH, Rellinghauser Straße 334F, D-45136 Essen, http://www.idesis.de

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# HTML Resource Embedder

HTML Resource Embedder (`htmlresemb`) tries to embed all external resources like CSS, JavaScript and
image files into an HTML document. It reads the content of those files and modifies the corresponding
tags (`link`, `style` and `img`) accordingly. CSS and JavaScript files are embedded into a CDATA
section, so in most cases there shouldn't be a problem with characters like `>` in the resource files.
Image files will be converted to a Base64 encoded data URI.

The resulting document is in most cases "portable", that is, it can be copied/moved to other locations
without breaking the layout. Please note that currently embedding of font files isn't supported. This
may be added in the future but can be a license problem depending on the font.

## Usage

```bash
htmlresemb -i <infile> -o <outfile> [options]
```

- `<infile>`\
Use <infile> for input. If `-i <infile>` is ommitted, input is read from stdin. In this case a
document root path must be supplied via `-docroot`, otherwise loading of resources referenced in
the document is impossible.

- `<outfile>`\
Use `<outfile>` for output. If `-o <outfile>` is ommitted, output goes to stdout.

**Available options (others are silently ignored):**

- `-h, --help`\
Print help message and exit.

- `-docroot <path>`\
A path which is used to resolve relative filenames. Relative paths and environment variables can be
used in `path`.

- `-css`\
Embed CSS files.

- `-js`\
Embed JavaScript files.

- `-img`\
Embed image files.


If none of the switches `-css`, `-js` and `-img` is used, *all* resources will be embedded.

**Return values:**

- **0** &emsp;Success.
- **1** &emsp;Invalid/incomplete options or `-h` / `--help` was used.
- **2** &emsp;An error occured.

Warning or error messages during processing are written to stderr.


## Status

`htmlresemb` is by no means a perfect solution, it's a very quick spin off from one of our other
internal projects. In general it does it's best and should just work, but it hasn't been tested with
many different documents. For example encodings other than UTF-8 will fail (mostly). Reading of the
source document is done with an XML parser, so this also may fail completely (although `htmlresemb`
tries to fix broken HTML to some extent). Also the output document might contain slightly different
whitespace.


## Development

`htmlresemb` is written in Free Pascal, the Mac and Windows binaries (see [Releases](../../releases/))
were created with compiler version 2.6.4 and Lazarus 1.4.4. You also need the `LazUtils` package
(part of FPC) and [Internet Tools](https://github.com/benibela/internettools). The Internet Tools
version used for `htmlresemb` is available as a Zip file in the [Releases](../../releases/) section.

The source code contains a slightly modified
version of `xmlwriter.pas` to overcome indenting and whitespace problems when creating the result
document. If you want to use a newer compiler version this maybe no longer necessary, but it's very
likely that you have to change larger parts of the source code due to the new Unicode string
handling in FPC 3.x. The Lazarus project file depends on `strip` as a post compile command, on the Mac
this should be available if the Apple developer tools are installed, on Windows using Cygwin/MinGW is
one possible solution.


## Credits

- [Free Pascal](https://www.freepascal.org)
- [Lazarus](https://www.lazarus-ide.org)
- [Benito van der Zander](http://www.benibela.de) (Internet Tools)

## License

MIT © [idesis GmbH](http://www.idesis.de), Rellinghauser Straße 334F, D-45136 Essen

See the `LICENSE` file for details.
137 changes: 137 additions & 0 deletions htmlresemb.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="htmlresemb"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<UseVersionInfo Value="True"/>
<AutoIncrementBuild Value="True"/>
<MinorVersionNr Value="9"/>
<BuildNr Value="10"/>
<StringTable CompanyName="idesis GmbH" FileDescription="Embed external resources into HTML files" InternalName="idesis HTML Resource Embedder" LegalCopyright="@2018 idesis GmbH" OriginalFilename="htmlresemb" ProductName="HTML Resource Embedder" ProductVersion="0.9"/>
</VersionInfo>
<BuildModes Count="2">
<Item1 Name="Mac" Default="True"/>
<Item2 Name="Windows">
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="htmlresemb"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<Optimizations>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
</Debugging>
</Linking>
<Other>
<ExecuteAfter>
<Command Value="strip.exe $(ProjPath)htmlresemb.exe"/>
</ExecuteAfter>
</Other>
</CompilerOptions>
</Item2>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="LazUtils"/>
</Item1>
<Item2>
<PackageName Value="internettools"/>
</Item2>
</RequiredPackages>
<Units Count="6">
<Unit0>
<Filename Value="htmlresemb.pas"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="uHTMLResEmb.pas"/>
<IsPartOfProject Value="True"/>
</Unit1>
<Unit2>
<Filename Value="uOptions.pas"/>
<IsPartOfProject Value="True"/>
</Unit2>
<Unit3>
<Filename Value="uUtil.pas"/>
<IsPartOfProject Value="True"/>
</Unit3>
<Unit4>
<Filename Value="uXMLWriter.pas"/>
<IsPartOfProject Value="True"/>
</Unit4>
<Unit5>
<Filename Value="uMain.pas"/>
<IsPartOfProject Value="True"/>
</Unit5>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="htmlresemb"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<Optimizations>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
</Debugging>
</Linking>
<Other>
<ExecuteAfter>
<Command Value="strip $(ProjPath)htmlresemb"/>
</ExecuteAfter>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>
Loading

0 comments on commit 37dbba0

Please sign in to comment.