code: public AnnotatedText build() {
      int plainTextPosition = 0;
      int totalPosition = 0;
      Map<Integer,Integer> mapping = new HashMap<>();
      mapping.put(0, 0);
      for (TextPart part : parts) {
        if (part.getType() == TextPart.Type.TEXT) {
          plainTextPosition += part.getPart().length();
          totalPosition += part.getPart().length();
        } else if (part.getType() == TextPart.Type.MARKUP) {
          totalPosition += part.getPart().length();
        } else if (part.getType() == TextPart.Type.FAKE_CONTENT) {
          plainTextPosition += part.getPart().length();
        }
        mapping.put(plainTextPosition, totalPosition);
      }
      return new AnnotatedText(parts, mapping, metaData, customMetaData);
    }
docs: Create the annotated text to be passed into {@link org.languagetool.JLanguageTool#check(AnnotatedText)}.