有没有一种方法可以在不直接使用 Style class 的情况下自动格式化文本?

Is there a way to auto-format text with out using the Style class directly;

String test = "Hello -this is a string of text";

像这样:... 每当在 itext 7 TextParagraph 中使用该文本字符串时,它会使 "this" italic 或某些设置 Style .

几乎使用特殊字符使 Text 与某个 Style 一起出现,使用 itext7:

我需要这样的东西,因为该程序的用户希望将某些单词设为 斜体

用户输入 TextArea 定义 String。 我保存了字符串,然后只需制作一个 TextParagraph 来保存该字符串:

            Cell location = new Cell()
                    .add(new Paragraph(test);

我虽然考虑使用 TextFlow,但它不适用于 itext7,因为它使用 JavafX CSS。

我想到了这个,它有效但不是那么漂亮...

private Paragraph formatText(String string) {

    Paragraph paragraph = new Paragraph();

        Stream.of(string)
            .map(w -> w.split(" "))
            .flatMap(Arrays::stream)
            .forEach(w -> {
                Text word;

                if (w.startsWith("~")) {
                    String replace = w.replace("~", "");
                    word = new Text(replace);
                    word.setItalic();   

                } else if (w.startsWith("*")) {                 
                    String replace = w.replace("*", "");
                    word = new Text(replace);
                    word.setItalic();       

                } else {                    
                    word = new Text(w);
                }

                paragraph.add(word);                    
            });

    return paragraph;

}