Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pegdown for markdown conversion #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description :=


libraryDependencies ++= Seq(
"com.tristanhunt" %% "knockoff" % "0.8.0-16",
"org.pegdown" % "pegdown" % "1.1.0",
"net.databinder" %% "unfiltered-netty-server" % "0.6.2",
"net.liftweb" %% "lift-json" % "2.4",
"net.databinder.dispatch" %% "core" % "0.9.0-alpha6",
Expand Down
14 changes: 8 additions & 6 deletions src/main/scala/herald.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package herald
import dispatch._
import java.net.URI
import java.io.{File,FileInputStream}
import com.tristanhunt.knockoff.DefaultDiscounter._
import org.streum.configrity._
import scala.xml.{NodeSeq,Node}
import scala.util.control.Exception.allCatch
import xml.{XML, NodeSeq, Node}
import org.pegdown.PegDownProcessor

object Herald {
def heraldCredentialsPath =
file(new File(System.getProperty("user.home")), ".herald")
Expand Down Expand Up @@ -121,16 +122,17 @@ object Herald {
mdToXml(versionNotes) ++
<div class="about"> { mdToXml(about) } </div>

val pegDown = new PegDownProcessor
/** @return node sequence from str or Nil if str is null or empty. */
private def mdToXml(str: String) = str match {
private def mdToXml(str: String): NodeSeq = str match {
case null | "" => Nil
case _ => toXML(knockoff(str))
case _ => XML.loadString("<wrapper>"+pegDown.markdownToHtml(str)+"</wrapper>").iterator.toSeq
}

/** @return node sequence from file or Nil if file is not found. */
private def mdToXml(md: File) =
private def mdToXml(md: File): NodeSeq =
if (md.exists)
toXML(knockoff(scala.io.Source.fromFile(md).mkString))
mdToXml(scala.io.Source.fromFile(md).mkString)
else
Nil

Expand Down