private SoyFileSetNode parseAndInjectIntoScriptTags(String input, String toInject) {
    String namespace = "{namespace ns autoescape=\"deprecated-contextual\"}\n\n";
    ErrorReporter boom = ExplodingErrorReporter.get();
    SoyFileSetNode soyTree =
        SoyFileSetParserBuilder.forFileContents(namespace + input).errorReporter(boom).parse();

    ContextualAutoescaper contextualAutoescaper =
        new ContextualAutoescaper(SOY_PRINT_DIRECTIVES, boom);
    List<TemplateNode> extras = contextualAutoescaper.rewrite(soyTree);

    SoyFileNode file = soyTree.getChild(soyTree.numChildren() - 1);
    file.addChildren(file.numChildren(), extras);

    insertTextAtEndOfScriptOpenTag(contextualAutoescaper.getSlicedRawTextNodes(), toInject);
    return soyTree;
  }