
#########
HTMLUtils
#########


****
NAME
****


Kernel::System::HTMLUtils - creating and modifying html strings


***********
DESCRIPTION
***********


A module for creating and modifying html strings.


****************
PUBLIC INTERFACE
****************


new()
=====


Don't use the constructor directly, use the ObjectManager instead:


.. code-block:: perl

     my $HTMLUtilsObject = $Kernel::OM->Get('Kernel::System::HTMLUtils');



ToAscii()
=========


convert an HTML string to an ASCII string


.. code-block:: perl

     my $Ascii = $HTMLUtilsObject->ToAscii( String => $String );



ToHTML()
========


convert an ASCII string to an HTML string


.. code-block:: perl

     my $HTMLString = $HTMLUtilsObject->ToHTML(
         String                     => $String,
         ReplaceDoubleSpace         => 0,       # replace &nbsp;&nbsp; with "  ", optional 1 or 0 (defaults to 1)
         DoNotReplaceWithParagraphs => 0,       # this is additional feature required due to CKEditor 5 using
                                                # rule of paragraphs being the "core" selector
                                                # inside it's text data
                                                 # do not replace end of lines with paragraphs
                                                 # usually used to parse string (for example for template)
                                                 # before fixing paragrapth for ckeditor 5
                                                 # IMPORTANT!
                                                 # if enabled, then after string processing you need
                                                 # to execute "ToHTMLFixHardBreaks" function!
     );



ToHTMLReplaceWithParagraphs()
=============================


replace & fix hard breaks/paragraphs for ckeditor 5


.. code-block:: perl

     my $HTMLString = $HTMLUtilsObject->ToHTMLReplaceWithParagraphs(
         String => $String,
     );



RTEContentCssDefaultFromSysconfigGet()
======================================


get RTE css content styles from system configuration


.. code-block:: perl

     my $RTEContentCssDefault = $HTMLUtilsObject->RTEContentCssDefaultFromSysconfigGet();



RTEContentCssInternalGet()
==========================


get internal RTE css content styles from path


.. code-block:: perl

     my $RTEContentCss = $HTMLUtilsObject->RTEContentCssInternalGet(
         UserType => 'Agent' # required
     );



DocumentComplete()
==================


check and e. g. add <html> and <body> tags to given html string


.. code-block:: perl

     my $HTMLDocument = $HTMLUtilsObject->DocumentComplete(
         String   => $String,  # required
         Charset  => $Charset, # required
         UserType => 'Agent'   # optional
     );



DocumentStrip()
===============


remove html document tags from string


.. code-block:: perl

     my $HTMLString = $HTMLUtilsObject->DocumentStrip(
         String  => $String,
     );



DocumentCleanup()
=================


perform some sanity checks on HTML content


.. code-block:: perl

  -  Replace <blockquote> by using
     "<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt" type="cite">"
     because of cross mail client and browser compatibility.
 
  -  If there is no HTML doctype present, inject the HTML5 doctype, because it is compatible with HTML4
     and causes the browsers to render the content in standards mode, which is safer.
 
     $HTMLBody = $HTMLUtilsObject->DocumentCleanup(
         String => $HTMLBody,
     );



TruncateBodyQuote()
===================


Strips document content to the limited number of lines.


.. code-block:: perl

     $Body = $HTMLUtilsObject->TruncateBodyQuote(
         Body       => $Body,
         Limit      => 10000,
         HTMLOutput => 1|0,
     );



LinkQuote()
===========


detect links in HTML code, add \ ``a href``\  if missing


.. code-block:: perl

     my $HTMLWithLinks = $HTMLUtilsObject->LinkQuote(
         String    => $HTMLString,
         Target    => 'TargetName', # content of target="?", e. g. _blank
         TargetAdd => 1,            # add target="_blank" to all existing "<a href"
     );


also string ref is possible


.. code-block:: perl

     my $HTMLWithLinksRef = $HTMLUtilsObject->LinkQuote(
         String => \$HTMLStringRef,
     );



Safety()
========


To remove/strip active html tags/addons (JavaScript, \ ``applet``\ s, \ ``embed``\ s and \ ``object``\ s)
from html strings.


.. code-block:: perl

     my %Safe = $HTMLUtilsObject->Safety(
         String         => $HTMLString,
         NoApplet       => 1,
         NoObject       => 1,
         NoEmbed        => 1,
         NoSVG          => 1,
         NoImg          => 1,
         NoIntSrcLoad   => 0,
         NoExtSrcLoad   => 1,
         NoJavaScript   => 1,
         ReplacementStr => 'string',          # optional, string to show instead of applet, object, embed, svg and img tags
     );


also string ref is possible


.. code-block:: perl

     my %Safe = $HTMLUtilsObject->Safety(
         String       => \$HTMLStringRef,
         NoApplet     => 1,
         NoObject     => 1,
         NoEmbed      => 1,
         NoSVG        => 1,
         NoImg        => 1,
         NoIntSrcLoad => 0,
         NoExtSrcLoad => 1,
         NoJavaScript => 1,
     );


returns


.. code-block:: perl

     my %Safe = (
         String  => $HTMLString, # modified html string (scalar or ref)
         Replace => 1,           # info if something got replaced
     );



EmbeddedImagesExtract()
=======================


extracts embedded images with data-URLs from an HTML document.


.. code-block:: perl

     $HTMLUtilsObject->EmbeddedImagesExtract(
         DocumentRef    => \$Body,
         AttachmentsRef => \@Attachments,
     );


Returns nothing. If embedded images were found, these will be appended
to the attachments list, and the image data URL will be replaced with a
\ ``cid:``\  URL in the document.




