Skip to content

Instantly share code, notes, and snippets.

@olih
Created April 18, 2013 14:23
Show Gist options
  • Save olih/5413104 to your computer and use it in GitHub Desktop.
Save olih/5413104 to your computer and use it in GitHub Desktop.
Process a html document and reformat it nicely. Beautifier
import scala.xml._
import scala.xml.transform._
import java.io._
import xml._
/**
Creator: 2013, Olivier Huin (https://github.com/olih)
License: Eclipse Public License - v 1.0
Contributors:
*/
object HtmlBeautifier {
object Meta {
val description = "Process a html document and reformat it nicely"
val signature = "HtmlBeautifier.process(ifile: File ,ofile: File)"
val parameters = Array(
"ifile: a html file to process",
"ofile: a html file to create")
val creator = "Olivier Huin (https://github.com/olih)"
val license = "Eclipse Public License - v 1.0"
val copyrightYear = 2013
val keywords="file"
val version="1.16"
val usage = s"""
Usage: $signature
$description
* ${parameters(0)}
* ${parameters(1)}
Creator: $copyrightYear, $creator
License: $license
Keywords: $keywords
Version: $version
"""
}
def process(ifile: File ,ofile: File): Unit = {
require(ifile!=null, {println("You must provide a html input file! ")})
require(ofile!=null, {println("You must provide a html output file! ")})
val ixml = xml.XML.loadFile(ifile.getAbsolutePath)
val pp = new PrettyPrinter(80, 5);
val oxml= pp.formatNodes(ixml)
val fw = new FileWriter(ofile)
fw.write(oxml)
fw.close()
}
def process(ifile: String ,ofile: String): Unit = process(new File(ifile),new File(ofile))
def process(ixml: Seq[scala.xml.Node] ,ofile: File): Unit = {
require(ixml!=null, {println("You must provide a html input ! ")})
require(ofile!=null, {println("You must provide a html output file! ")})
val pp = new PrettyPrinter(80, 5);
val oxml= pp.formatNodes(ixml)
val fw = new FileWriter(ofile)
fw.write(oxml)
fw.close()
}
def process(ixml: Seq[scala.xml.Node] ,ofile: String): Unit = process(ixml,new File(ofile))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment