NAME

HTML::Hyphenate - insert soft hyphens into HTML

VERSION

This document describes HTML::Hyphenate version v1.1.9.

SYNOPSIS

use HTML::Hyphenate;

$hyphenator = new HTML::Hyphenate();
$html_with_soft_hyphens = $hyphenator->hyphenated($html);

$hyphenator->html($html);
$hyphenator->style($style); # czech or german

$hyphenator->min_length(10);
$hyphenator->min_pre(2);
$hyphenator->min_post(2);
$hyphenator->default_lang('en-us');
$hyphenator->default_included(1);
$hyphenator->classes_included(['shy']);
$hyphenator->classes_excluded(['noshy']);

DESCRIPTION

Most HTML rendering engines used in web browsers don't figure out by themselves how to hyphenate words when needed, but we can tell them how they might do it by inserting soft hyphens into the words.

SUBROUTINES/METHODS

HTML::Hyphenate->new()

Constructs a new HTML::Hyphenate object.

$hyphenator->hyphenated()

Returns the HTML including the soft hyphens.

$hyphenator->html();

Gets or sets the HTML to hyphenate.

$hyphenator->style();

Gets or sets the style to use for pattern usages in TeX::Hyphen. Can be czech or german.

$hyphenator->min_length();

Gets or sets the minimum word length required for having soft hyphens inserted. Defaults to 10 characters.

$hyphenator->min_pre(2);

Gets or sets the minimum amount of characters in a word preserved before the first soft hyphen. Defaults to 2 characters.

$hyphenator->min_post(2);

Gets or sets the minimum amount of characters in a word preserved after the last soft hyphen. Defaults to 2 characters.

$hyphenator->default_lang('en-us');

Gets or sets the default pattern to use when no language can be derived from the HTML.

$hyphenator->default_included();

Gets or sets if soft hyphens should be included in the whole tree by default. This can be used to insert soft hyphens only in parts of the HTML having specific class names.

$hyphenator->classes_included();

Gets or sets a reference to an array of class names that will have soft hyphens inserted.

$hyphenator->classes_excluded();

Gets or sets a reference to an array of class names that will not have soft hyphens inserted.

$hyphenator->register_tex_hyphen(lang, TeX::Hyphen)

Registers a TeX::Hyphen object to handle the language defined by lang.

CONFIGURATION AND ENVIRONMENT

The output is generated by Mojo::DOM so the environment variable MOJO_DOM_CSS_DEBUG can be set to debug it's CSS selection process.

DEPENDENCIES

INCOMPATIBILITIES

This module has the same limits as TeX::Hyphen, TeX::Hyphen::Pattern and Mojo::DOM. Tests might fail if the patterns used for them are updated and change the test result.

DIAGNOSTICS

This module uses Log::Log4perl for logging when it's resurrected.

  • It warns when a language encountered in the HTML is not supported by TeX::Hyphen::Pattern

BUGS AND LIMITATIONS

  • Perfect hyphenation can be more complicated than just inserting a hyphen somewhere in a word, and sometimes requires semantics to get it right. For example cafeetje should be hyphenated as cafe-tje and not cafee-tje and buurtje can be hyphenated as buur-tje or buurt-je, depending on it's meaning. While HTML could provide a bit more context - mainly the language being used - than plain text to handle these issues, the initial purpose of this module is to make it possible for HTML rendering engines that support soft hyphens to be able to break long words over multiple lines to avoid unwanted overflow.

  • The hyphenation doesn't get better than TeX::Hyphenate and it's hyphenation patterns provide.

  • The round trip from HTML source via Mojo::DOM to HTML source might introduce changes to the source, for example accented characters might be transformed to HTML encoded entity equivalents or Boolean attributes are converted to a different notation.

Please report any bugs or feature requests at Bitbucket.

AUTHOR

Roland van Ipenburg, <roland@rolandvanipenburg.com>

LICENSE AND COPYRIGHT

Copyright (C) 2009-2021, Roland van Ipenburg

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.0 or, at your option, any later version of Perl 5 you may have available.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.