diff --git a/inc/databap.php b/inc/databap.php index ef46525..a77299a 100644 --- a/inc/databap.php +++ b/inc/databap.php @@ -1146,7 +1146,7 @@ class Databap extends PhpObject $asTable['title'] = self::getTableFormat($asTable['title']); $asTable['description'] = self::getDescriptionFormat($asTable['description']); $asTable['led'] = self::getDateFormat($asTable['led']); - $asTable['formatted_keywords'] = ToolBox::findReplaceLinks($asTable['keywords']); + $asTable['formatted_keywords'] = str_replace("\n", '
', ToolBox::findReplaceLinks($asTable['keywords'])); } return $asTable; } diff --git a/inc/reader.php b/inc/reader.php index 34851bc..c9facbb 100644 --- a/inc/reader.php +++ b/inc/reader.php @@ -139,7 +139,7 @@ class Reader extends PhpObject $sCode = $this->convText2Html($this->sCode); //$sServName = $_GET['serv_name']; - $asLines = explode("\n", str_replace("\r\n", "\n", $sCode)); + $asLines = explode("\n", ToolBox::fixEOL($sCode)); $asLineClasses = array(); $iOffSet = 0; diff --git a/inc/toolbox.php b/inc/toolbox.php index d15afa4..fb8f2cd 100644 --- a/inc/toolbox.php +++ b/inc/toolbox.php @@ -243,6 +243,9 @@ class ToolBox //TODO implement link pattern public static function findReplaceLinks($sText, $sLinkPattern='') { + //Fix Carriage Return / Line Feed OS issue + $sText = self::fixEOL($sText); + $sServerPath = substr(str_replace(array('http://', 'https://'), '', $_GET['serv_name']), 0, -1); //building all replacements possibilities @@ -254,32 +257,38 @@ class ToolBox $asReplacements[preg_quote(Databap::$PAGE_TITLES[$sPage])] = $sPage; } - //Phase 1 : Identify internal links : merge cases /#code-1 and code 1, destroy link. + //Phase 1: Identify internal links : merge cases /#code-1 and code 1, destroy link. $asPatterns = array(); foreach($asReplacements as $sHash=>$sPage) { - $asPatterns['`(^|\ )(https?://|)'.$sServerPath.'/?\#'.$sHash.'\-([\d]+)`sui'] = '$1$4'.$sPage.' $3'; + //Type + id + $asPatterns['`(^|\ )(https?://|)'.$sServerPath.'/?\#'.$sHash.'\-([\d]+)`mui'] = '$1$4'.$sPage.' $3'; + + //Type + phrase + if($sPage=='table') $asPatterns['`(^|\ )(https?://|)'.$sServerPath.'/?\#(?i)'.$sHash.'(?-i)\-([_A-Z0-9]+)`mu'] = '$1$4'.$sPage.' $3'; } $sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText); - //Phase 2 : Identify remaining links (external) - $asPatterns = array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`sui', '`((?$1 ', '$1'); $sText = preg_replace($asPatterns, $asLinks, $sText); - //Phase 3: rebuild link + //Phase 3: Rebuild link $asPatterns = array(); + $sPreChar = '(^|\ |\*|\')'; + $sPostChar = '(\ |\.|\:|$)'; foreach($asReplacements as $sHash=>$sPage) { if(mb_strlen($sHash)>1) { $sTitle = Databap::$PAGE_TITLES[$sPage]; - //Type + phrase - if($sPage=='table') $asPatterns['`(^|\ |\*)(?i)'.$sHash.'(?-i)\ ([_A-Z0-9]+)(\ |$)`su'] = '$1'.$sTitle.' $2$3'; - //Type + id - $asPatterns['`(^|\ |\*)'.$sHash.'\ ([\d]+)(\ |$)`sui'] = '$1'.$sTitle.'$2$3'; + $asPatterns['`'.$sPreChar.$sHash.'\ ([\d]+)'.$sPostChar.'`mui'] = '$1'.$sTitle.'$2$3'; + + //Type + phrase + if($sPage=='table') $asPatterns['`'.$sPreChar.'(?i)'.$sHash.'(?-i)\ ([_A-Z0-9]+)'.$sPostChar.'`mu'] = '$1'.$sTitle.' $2$3'; } } $sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText); @@ -287,6 +296,18 @@ class ToolBox return $sText; } + public static function fixEOL($sText) + { + //Normalize line endings + //Convert all line-endings to UNIX format + $sText = str_replace("\r\n", "\n", $sText); //Windows + $sText = str_replace("\r", "\n", $sText); //Mac + + // Don't allow out-of-control blank lines + $sText = preg_replace("/\n{2,}/", "\n\n", $sText); + return $sText; + } + public static function getDateTimeDesc($oTime) { $iTimeStamp = is_numeric($oTime)?$oTime:strtotime($oTime); diff --git a/masks/table.html b/masks/table.html index 56774a1..34095bb 100644 --- a/masks/table.html +++ b/masks/table.html @@ -101,7 +101,7 @@ Table.prototype.applyTableInfo = function() { if(sKey=='warning' && sValue!='') databap.addWarningBefore(sValue, tableself.sFeedBackBoxId); //debug('key='+sKey+', value='+sValue); - $('#read_'+sKey).html(sValue.replace(/(?:\r\n|\r|\n)/g, '
')); + $('#read_'+sKey).html(sValue); //sValue.replace(/(?:\r\n|\r|\n)/g, '
') $('#'+sKey).val(sValue); }); tableself.setDisplay(tableself.DISPLAY_READ); diff --git a/style/screen.css b/style/screen.css index 8a5a4de..b856f15 100644 --- a/style/screen.css +++ b/style/screen.css @@ -2400,6 +2400,10 @@ vertical-align 0% -5% -10% -15% -20% -25% -30% font-size: 0.9em; } +#table #read_formatted_keywords a.internal_link { + padding:0 0 0 2px; +} + #table input:disabled { color:#D9E5F2; background-color:#04357B;