// Return the selected template and format given the YAML front matter
  public RmdSelectedTemplate getTemplateFormat(String yaml) {
    // This is in the editor load path, so guard against exceptions and log
    // any we find without bringing down the editor. Failing to find a
    // template here just turns off the template-specific UI format editor.
    try {
      YamlTree tree = new YamlTree(yaml);
      boolean isShiny = false;

      if (tree.getKeyValue(RmdFrontMatter.KNIT_KEY).length() > 0) return null;

      // Find the template appropriate to the first output format listed.
      // If no output format is present, assume HTML document (as the
      // renderer does).
      List<String> outFormats = getOutputFormats(tree);
      String outFormat =
          outFormats == null ? RmdOutputFormat.OUTPUT_HTML_DOCUMENT : outFormats.get(0);

      RmdTemplate template = getTemplateForFormat(outFormat);
      if (template == null) return null;

      // If this format produces HTML and is marked as Shiny, treat it as
      // a Shiny format
      if (template.getFormat(outFormat).getExtension().equals("html")
          && tree.getKeyValue(RmdFrontMatter.RUNTIME_KEY).equals(RmdFrontMatter.SHINY_RUNTIME)) {
        isShiny = true;
      }

      return new RmdSelectedTemplate(template, outFormat, isShiny);
    } catch (Exception e) {
      Debug.log("Warning: Exception thrown while parsing YAML:\n" + yaml);
    }
    return null;
  }
 private List<String> getOutputFormats(YamlTree tree) {
   List<String> outputs = tree.getChildKeys(RmdFrontMatter.OUTPUT_KEY);
   if (outputs == null) return null;
   if (outputs.isEmpty()) outputs.add(tree.getKeyValue(RmdFrontMatter.OUTPUT_KEY));
   return outputs;
 }
  public String convertYamlToShinyDoc(String yaml) {
    YamlTree yamlTree = new YamlTree(yaml);
    yamlTree.addYamlValue(null, "runtime", "shiny");

    return yamlTree.toString();
  }