@Override
 public InterpreterResult interpret(String st, InterpreterContext interpreterContext) {
   String html;
   try {
     html = md.process(st);
   } catch (IOException | java.lang.RuntimeException e) {
     LOGGER.error("Exception in Markdown while interpret ", e);
     return new InterpreterResult(Code.ERROR, InterpreterUtils.getMostRelevantMessage(e));
   }
   return new InterpreterResult(Code.SUCCESS, "%html " + html);
 }
  /** Converts the text in editor to HTML text to be displayed in preview page. */
  void markdownToHtml() {
    String editorText = editor.getDocumentProvider().getDocument(editor.getEditorInput()).get();

    String htmlText = "<p>Error processing the input.</p>";
    try {
      htmlText = markdownProcessor.process(editorText);
    } catch (IOException e) {
    }

    browser.setText(htmlText);
  }
Beispiel #3
0
  private static Map<String, String> content_for(
      Set<String> relevant_files, Map<String, Vertabrae> file_names) {

    Map<String, String> result = new HashMap<>();
    for (String file : relevant_files) {
      String index = file.substring(file.length() - 1);

      Vertabrae vertabrae = file_names.get(file);
      ByteSource bs = Files.asByteSource(vertabrae.path().toFile());
      String html;
      try {
        html = md.process(bs.openBufferedStream());
        result.put(index, html);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return result;
  }
Beispiel #4
0
  private static void generate_markup(
      Path abs_path_from, Path abs_path_to, Map<String, Vertabrae> file_names) throws IOException {
    Function<Vertabrae, String> title = Vertabrae::title;

    Map<String, String> toc = Maps.transformValues(file_names, title);

    Set<String> files = file_names.keySet();

    Set<String> filtered_files =
        files.stream().filter(file -> !file.contains("_")).collect(Collectors.toSet());

    for (String key : filtered_files) {
      Vertabrae vertabrae = file_names.get(key);

      ByteSource bs = Files.asByteSource(vertabrae.path().toFile());
      String html = md.process(bs.openBufferedStream());

      Set<String> relevant_files =
          files.stream().filter(file -> file.contains(key + "_")).collect(Collectors.toSet());

      String template = pick_template(abs_path_from, vertabrae.file_name());

      VelocityContext velocity_context = new VelocityContext();
      velocity_context.put("name", vertabrae.title());
      velocity_context.put("content", html);
      velocity_context.put("pages", toc);

      Map<String, String> content_files = content_for(relevant_files, file_names);

      for (String index : content_files.keySet()) {
        velocity_context.put("content_" + index, content_files.get(index));
      }

      System.out.println("[SPINE] Template: " + template);

      String page = merge(template, velocity_context);

      File to_file = new File(abs_path_to + File.separator + vertabrae.file_name() + ".html");

      Files.write(page, to_file, Charsets.UTF_8);
    }
  }