summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFranck Magnan <fmagnan@gmail.com>2013-03-05 16:41:01 +0100
committerFranck Magnan <fmagnan@gmail.com>2013-03-05 16:41:01 +0100
commitb27101b27e1f5434fd985d38a5ade8cbc06cffbc (patch)
tree0a0a04f30ecbe5bfd6fb7ba1476cdf513eb5df1e
parent2efc4bb4f6f154d67125d313b1412926fe9d70ee (diff)
downloadsql-formatter-b27101b27e1f5434fd985d38a5ade8cbc06cffbc.zip
sql-formatter-b27101b27e1f5434fd985d38a5ade8cbc06cffbc.tar.gz
sql-formatter-b27101b27e1f5434fd985d38a5ade8cbc06cffbc.tar.bz2
adding option to deactivate preformatted text
-rw-r--r--lib/SqlFormatter.php27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php
index ae65211..9b15a99 100644
--- a/lib/SqlFormatter.php
+++ b/lib/SqlFormatter.php
@@ -313,10 +313,11 @@ class SqlFormatter
*
* @param String $string The SQL string
* @param boolean $highlight If true, syntax highlighting will also be performed
+ * @param boolean $preformatted If true, enclose string in <pre> tags
*
* @return String The SQL string with HTML styles and formatting wrapped in a <pre> tag
*/
- public static function format($string, $highlight=true) {
+ public static function format($string, $highlight=true, $preformatted=true) {
// This variable will be populated with formatted html
$return = '';
@@ -531,7 +532,7 @@ class SqlFormatter
$return = trim(str_replace("\t",self::$tab,$return));
if ($highlight) {
- $return = "<pre ".self::$pre_attributes.">" . $return . "</pre>";
+ $return = self::output($return,$preformatted);
}
return $return;
@@ -541,10 +542,11 @@ class SqlFormatter
* Add syntax highlighting to a SQL string
*
* @param String $string The SQL string
+ * @param boolean $preformatted If true, enclose string in <pre> tags
*
* @return String The SQL string with HTML styles applied
*/
- public static function highlight($string)
+ public static function highlight($string,$preformatted=true)
{
$tokens = self::tokenize($string);
@@ -554,7 +556,7 @@ class SqlFormatter
$return .= self::highlightToken($token);
}
- return "<pre ".self::$pre_attributes.">" . trim($return) . "</pre>";
+ return self::output($return,$preformatted);
}
/**
@@ -784,4 +786,21 @@ class SqlFormatter
private static function quote_regex($a) {
return preg_quote($a,'/');
}
+
+ /**
+ * Helper function for building string output
+ *
+ * @param String $a The string to be quoted
+ * @param boolean $preformatted If true, enclose string in <pre> tags
+ *
+ * @return String The quoted string
+ */
+ private static function output($string,$preformatted=true){
+ $string=trim($string);
+ if(!$preformatted){
+ return $string;
+
+ }
+ return '<pre '.self::$pre_attributes.'>' . $string . '</pre>';
+ }
}