예제 #1
0
 public static String md(Object obj) {
   String retVal = obj.toString();
   try {
     StringBuffer buff = new StringBuffer();
     Markdown md = new Markdown();
     Reader in = new StringReader(obj.toString());
     Writer out = new StringBufferWriter(buff);
     md.transform(in, out);
     out.flush();
     retVal = buff.toString();
     retVal = HtmlSanitizer.clean(retVal);
   } catch (Exception e) {
     String msg = "Could not parse for markdown '" + obj.toString() + "'";
     cLogger.error(msg, e);
   }
   return retVal;
 }
  public static String renderMarkdown2(String text) {
    // 协议替换
    text = replayProctoct(text);
    // 转换
    StringWriter out = new StringWriter();
    try {
      md.transform(new StringReader(text), out);
      text = out.toString();

      // 生成完整html
      return text;
    } catch (ParseException e) {
      return text;
    }
  }
  public static String renderMarkdown(String text) {
    text = replayProctoct(text);
    // 转换
    StringWriter out = new StringWriter();
    try {
      md.transform(new StringReader(text), out);
      text = out.toString();

      // 生成完整html
      return HTML_0
          + "\n<link type=\"text/css\" rel=\"stylesheet\" href=\""
          + THEME_CSS
          + "\">"
          + HTML_1
          + text
          + HTML_2;
    } catch (ParseException e) {
      return text;
    }
  }