Class HtmlUtils

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

public class HtmlUtils extends Object
Utilities for conversion from/to HTML and XML used in Freeplane: In scripts available as "global variable" htmlUtils.
  • Method Details

    • getInstance

      public static HtmlUtils getInstance()
    • htmlToPlain

      public static String htmlToPlain(String text)
      equivalent to htmlToPlain(text, strictHTMLOnly=true, removeNewLines=true)
      See Also:
    • htmlToPlain

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

      public static String htmlToPlain(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.
    • htmlToPlain

      public static String htmlToPlain(String text, boolean strictHTMLOnly, boolean removeNewLines, String bulletPointReplacement)
    • isHtmlNode

      @Deprecated public static boolean isHtmlNode(String text)
      Deprecated.
    • textToHTML

      public static String textToHTML(String text)
    • isHtml

      public static boolean isHtml(String text)
    • plainToHTML

      public static String plainToHTML(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 String removeAllTagsFromString(String text)
    • removeHtmlTagsFromString

      public static String removeHtmlTagsFromString(String text)
      Removes all tags (<..>) from a string if it starts with "<html>..." to make it compareable.
    • toXMLEscapedText

      public static String toXMLEscapedText(String text)
    • toXMLEscapedTextExpandingWhitespace

      public static String toXMLEscapedTextExpandingWhitespace(String text)
    • toXMLUnescapedText

      public static String toXMLUnescapedText(String text)
    • unescapeHTMLUnicodeEntity

      public static String unescapeHTMLUnicodeEntity(String text)
    • unicodeToHTMLUnicodeEntity

      public static String unicodeToHTMLUnicodeEntity(String text)
    • getMaximalOriginalPosition

      public static int getMaximalOriginalPosition(int pI, 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, ArrayList<HtmlUtils.IndexPair> pListOfIndices)
    • getReplaceResult

      public static String getReplaceResult(Pattern pattern, String text, 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 String toHtml(String xhtmlText)
    • objectToHtml

      public static String objectToHtml(Object object)
    • iconToHtml

      public static String iconToHtml(Icon icon)
    • imageToHtml

      public static String imageToHtml(RenderedImage image)
    • toXhtml

      public static String toXhtml(String htmlText)
    • endOfText

      public static int endOfText(String html)
    • combineTextWithExceptionInfo

      public static String combineTextWithExceptionInfo(String text, Exception ex)
    • element

      public static String element(String name, String content)
    • element

      public static String element(String name, Map<String,String> attributes, String content)
    • extractRawBody

      public static String extractRawBody(String text)
    • getURLOfExistingLink

      public static String getURLOfExistingLink(HTMLDocument doc, int pos)
      Gets the string URL of an existing link, or null if none.
    • getCurrentLinkElement

      public static Element getCurrentLinkElement(HTMLDocument doc, int pos)
    • isEmpty

      public static boolean isEmpty(String newText)
    • toHTMLEscapedText

      public static String toHTMLEscapedText(String s)
    • join

      public static String join(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