org.freeplane.core.util

## Class HtmlUtils

- java.lang.Object
- - org.freeplane.core.util.HtmlUtils

-     public class HtmlUtils
      extends java.lang.Object

  Utilities for conversion from/to HTML and XML used in Freeplane: In scripts available as "global variable" `htmlUtils`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `HtmlUtils.IndexPair`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `combineTextWithExceptionInfo(java.lang.String text, java.lang.Exception ex)`
    `static java.lang.String` | `element(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> attributes, java.lang.String content)`
    `static java.lang.String` | `element(java.lang.String name, java.lang.String content)`
    `static int` | `endOfText(java.lang.String html)`
    `static java.lang.String` | `extractRawBody(java.lang.String text)`
    `static javax.swing.text.Element` | `getCurrentLinkElement(javax.swing.text.html.HTMLDocument doc, int pos)`
    `static HtmlUtils` | `getInstance()`
    `static int` | `getMaximalOriginalPosition(int pI, java.util.ArrayList<HtmlUtils.IndexPair> pListOfIndices)`
    `static int` | `getMinimalOriginalPosition(int pI, java.util.ArrayList<HtmlUtils.IndexPair> pListOfIndices)`
    `static java.lang.String` | `getReplaceResult(java.util.regex.Pattern pattern, java.lang.String text, java.lang.String replacement)` Replaces text in node content without replacing tags. fc, 19.12.06: This method is very difficult.
    `static java.lang.String` | `getURLOfExistingLink(javax.swing.text.html.HTMLDocument doc, int pos)` Gets the string URL of an existing link, or null if none.
    `static java.lang.String` | `htmlToPlain(java.lang.String text)` equivalent to htmlToPlain(text, strictHTMLOnly=true, removeNewLines=true)
    `static java.lang.String` | `htmlToPlain(java.lang.String text, boolean strictHTMLOnly)` equivalent to htmlToPlain(text, strictHTMLOnly, removeNewLines=true)
    `static java.lang.String` | `htmlToPlain(java.lang.String text, boolean strictHTMLOnly, boolean removeNewLines)` removes html markup and entities, partly and where appropriate by replacing it by plaintext equivalents like <li> → '*'.
    `static boolean` | `isEmpty(java.lang.String newText)`
    `static boolean` | `isHtml(java.lang.String text)`
    `static boolean` | `isHtmlNode(java.lang.String text)` Deprecated.
    `static java.lang.String` | `join(java.lang.String... texts)` Join arbitrary texts to html.
    `static java.lang.String` | `plainToHTML(java.lang.String text)` transforms `&, <, >, \n` and whitespace by their HTML counterpart and encloses the whole text in {@code ...
    `static java.lang.String` | `removeAllTagsFromString(java.lang.String text)`
    `static java.lang.String` | `removeHtmlTagsFromString(java.lang.String text)` Removes all tags (<..
    `static java.lang.String` | `textToHTML(java.lang.String text)`
    `static java.lang.String` | `toHtml(java.lang.String xhtmlText)`
    `static java.lang.String` | `toHTMLEscapedText(java.lang.String s)`
    `static java.lang.String` | `toXhtml(java.lang.String htmlText)`
    `static java.lang.String` | `toXMLEscapedText(java.lang.String text)`
    `static java.lang.String` | `toXMLEscapedTextExpandingWhitespace(java.lang.String text)`
    `static java.lang.String` | `toXMLUnescapedText(java.lang.String text)`
    `static java.lang.String` | `unescapeHTMLUnicodeEntity(java.lang.String text)`
    `static java.lang.String` | `unicodeToHTMLUnicodeEntity(java.lang.String text)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getInstance

          public static HtmlUtils getInstance()

    - #### htmlToPlain

          public static java.lang.String htmlToPlain(java.lang.String text)

      equivalent to htmlToPlain(text, strictHTMLOnly=true, removeNewLines=true)
      See Also:
        `htmlToPlain(String, boolean, boolean)`

    - #### htmlToPlain

          public static java.lang.String htmlToPlain(java.lang.String text,
                                                     boolean strictHTMLOnly)

      equivalent to htmlToPlain(text, strictHTMLOnly, removeNewLines=true)
      See Also:
        `htmlToPlain(String, boolean, boolean)`

    - #### htmlToPlain

          public static java.lang.String htmlToPlain(java.lang.String text,
                                                     boolean strictHTMLOnly,
                                                     boolean removeNewLines)

      removes html markup and entities, partly and where appropriate by replacing it by plaintext equivalents like <li> → '*'.
      Parameters:
        `strictHTMLOnly` - if true does nothing unless the text starts with <html>
        `removeNewLines` - set to false to keep all blank lines.

    - #### isHtmlNode

          @Deprecated
          public static boolean isHtmlNode(java.lang.String text)

      Deprecated.

    - #### textToHTML

          public static java.lang.String textToHTML(java.lang.String text)

    - #### isHtml

          public static boolean isHtml(java.lang.String text)

    - #### plainToHTML

          public static java.lang.String plainToHTML(java.lang.String text)

      transforms `&, <, >, \n` and whitespace by their HTML counterpart and encloses the whole text in `<html><body><p>...</p></body></html>`.

    - #### removeAllTagsFromString

          public static java.lang.String removeAllTagsFromString(java.lang.String text)

    - #### removeHtmlTagsFromString

          public static java.lang.String removeHtmlTagsFromString(java.lang.String text)

      Removes all tags (<..>) from a string if it starts with "<html>..." to make it compareable.

    - #### toXMLEscapedText

          public static java.lang.String toXMLEscapedText(java.lang.String text)

    - #### toXMLEscapedTextExpandingWhitespace

          public static java.lang.String toXMLEscapedTextExpandingWhitespace(java.lang.String text)

    - #### toXMLUnescapedText

          public static java.lang.String toXMLUnescapedText(java.lang.String text)

    - #### unescapeHTMLUnicodeEntity

          public static java.lang.String unescapeHTMLUnicodeEntity(java.lang.String text)

    - #### unicodeToHTMLUnicodeEntity

          public static java.lang.String unicodeToHTMLUnicodeEntity(java.lang.String text)

    - #### getMaximalOriginalPosition

          public static int getMaximalOriginalPosition(int pI,
                                                       java.util.ArrayList<HtmlUtils.IndexPair> pListOfIndices)

      Returns:
        the maximal index i such that pI is mapped to i by removing all tags from the original input.

    - #### getMinimalOriginalPosition

          public static int getMinimalOriginalPosition(int pI,
                                                       java.util.ArrayList<HtmlUtils.IndexPair> pListOfIndices)

    - #### getReplaceResult

          public static java.lang.String getReplaceResult(java.util.regex.Pattern pattern,
                                                          java.lang.String text,
                                                          java.lang.String replacement)

      Replaces text in node content without replacing tags. fc, 19.12.06: This method is very difficult. If you have a simpler method, please supply it. But look that it complies with FindTextTests!!!

    - #### toHtml

          public static java.lang.String toHtml(java.lang.String xhtmlText)

    - #### toXhtml

          public static java.lang.String toXhtml(java.lang.String htmlText)

    - #### endOfText

          public static int endOfText(java.lang.String html)

    - #### combineTextWithExceptionInfo

          public static java.lang.String combineTextWithExceptionInfo(java.lang.String text,
                                                                      java.lang.Exception ex)

    - #### element

          public static java.lang.String element(java.lang.String name,
                                                 java.lang.String content)

    - #### element

          public static java.lang.String element(java.lang.String name,
                                                 java.util.Map<java.lang.String,java.lang.String> attributes,
                                                 java.lang.String content)

    - #### extractRawBody

          public static java.lang.String extractRawBody(java.lang.String text)

    - #### getURLOfExistingLink

          public static java.lang.String getURLOfExistingLink(javax.swing.text.html.HTMLDocument doc,
                                                              int pos)

      Gets the string URL of an existing link, or null if none.

    - #### getCurrentLinkElement

          public static javax.swing.text.Element getCurrentLinkElement(javax.swing.text.html.HTMLDocument doc,
                                                                       int pos)

    - #### isEmpty

          public static boolean isEmpty(java.lang.String newText)

    - #### toHTMLEscapedText

          public static java.lang.String toHTMLEscapedText(java.lang.String s)

    - #### join

          public static java.lang.String join(java.lang.String... texts)

      Join arbitrary texts to html. Plain text arguments will be transformed via `plainToHTML(String)`, i.e. newlines and other special characters will be translated to their HTML counterpart and wrapped in a paragraph (<p></p>).

             // plain + html -> <html><body><p>text1</p>text2</body></html>
             HtmlUtils.join("text1", "", "<html><body>text2</body></html>");
             // insert an empty paragraph (<p></p>) between two strings:
             HtmlUtils.join("text1", "", "text2");
             // this will insert two paragraphs:
             HtmlUtils.join("text1", "\n", "text2");

      Parameters:
        `texts` - either html (starting with <HTML> or <html>) or plain text.
      Returns:
        html