private void cutAndInsertContent()

in freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/PrintTextWithDocgenSubstitutionsDirective.java [458:487]


        private void cutAndInsertContent(InsertDirectiveArgs args, String content)
                throws TemplateException, IOException {
            if (args.from != null) {
                Matcher matcher = args.from.matcher(content);
                if (matcher.find()) {
                    String remaining = content.substring(matcher.start());
                    content = "[\u2026]"
                            + (remaining.startsWith("\n") || remaining.startsWith("\r") ? "" : "\n")
                            + remaining;
                } else if (!args.fromOptional) {
                    throw newErrorInDocgenTag(
                            "\"from\" regular expression has no match in the file content: " + args.from);
                }
            }

            if (args.to != null) {
                Matcher matcher = args.to.matcher(content);
                if (matcher.find()) {
                    String remaining = content.substring(0, matcher.start());
                    content = remaining
                            + (remaining.endsWith("\n") || remaining.endsWith("\r") ? "" : "\n")
                            + "[\u2026]";
                } else if (!args.toOptional) {
                    throw newErrorInDocgenTag(
                            "\"to\" regular expression has no match in the file content: " + args.to);
                }
            }

            HTMLOutputFormat.INSTANCE.output(content, out);
        }