Class Ruby<T extends Ruby<T>>


public class Ruby<T extends Ruby<T>> extends StyledElement<T>
Represents an HTML <ruby> element that displays East Asian characters with pronunciation annotations.

The <ruby> element is a container for ruby annotations, which are small text annotations displayed above or beside characters to indicate pronunciation or meaning. This is commonly used in Japanese (furigana), Chinese (pinyin/zhuyin), and Korean texts to aid reading comprehension.

The <ruby> element restricts its content to base text (via addText(String)), Rt elements for annotations, and Rp elements for fallback parentheses. Use the typed methods to add children.

Features:

  • Container for ruby annotation markup
  • Supports pronunciation guides for East Asian characters
  • Contains base text, <rt> (ruby text), and <rp> (parentheses) elements
  • Displays annotations above or beside the base text
  • Commonly used for furigana, pinyin, and other phonetic guides
  • Provides graceful degradation for unsupported browsers

Usage:


 // Japanese kanji with furigana
 Ruby word = new Ruby();
 word.addText("日本");  // Base text: "Japan" in kanji
 word.addElement(new Rp("("));
 Rt pronunciation = new Rt();
 pronunciation.addText("にほん");  // Pronunciation in hiragana
 word.addElement(pronunciation);
 word.addElement(new Rp(")"));
 // Displays: 日本 with にほん above (or 日本(にほん) in unsupported browsers)

 // Multiple characters with individual annotations
 Ruby sentence = new Ruby();
 sentence.addText("今");
 Rt rt1 = new Rt();
 rt1.addText("いま");
 sentence.addElement(rt1);
 sentence.addText("日");
 Rt rt2 = new Rt();
 rt2.addText("ひ");
 sentence.addElement(rt2);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Ruby

      public Ruby()
      Constructs a new Ruby element.

      Creates an HTML <ruby> element that serves as a container for base text and its pronunciation annotations. Child elements should include the base text, <rt> elements for annotations, and optionally <rp> elements for fallback parentheses.

  • Method Details

    • addText

      public void addText(String text)
      Adds base text content to the ruby element.

      The base text is the character or text that will receive the ruby annotation.

      Overrides:
      addText in class Element<T extends Ruby<T>>
      Parameters:
      text - the base text content
    • addText

      public void addText(Text text)
      Adds a pre-configured Text element as base text content.
      Overrides:
      addText in class Element<T extends Ruby<T>>
      Parameters:
      text - the Text element to add
    • removeAllElements

      public void removeAllElements()
      Removes all child elements and text from this ruby element.
      Overrides:
      removeAllElements in class Element<T extends Ruby<T>>