模版定义:
渲染结果:
占位符字符串:
代码:
源代码:
public class CustomTextReplacingHandle implements IReplacingCallback {
private final String content;
public CustomTextReplacingHandle(String content) {
this.content = content;
}
public int replacing(ReplacingArgs args) throws Exception {
DocumentBuilder builder = new DocumentBuilder((Document)args.getMatchNode().getDocument());
builder.moveTo(args.getMatchNode());
double firstLineIndent = (double)20.0F;
String[] lines = this.content.split("\n");
for(String line : lines) {
if (line.contains("\t")) {
builder.getParagraphFormat().setFirstLineIndent(firstLineIndent);
line = line.replace("\t", "").trim();
} else {
builder.getParagraphFormat().setFirstLineIndent((double)0.0F);
}
builder.write(line);
builder.writeln();
}
args.getMatchNode().remove();
return 1;
}
}