// skip over any spaces interleaved among the cite markers
while (($pos < $length) && ($body{$pos} == ' ')) {
+
$pos++;
+
}
if ($pos >= $length) {
break;
// special case: if this is a blank line then maintain it
// (i.e. try to preserve original paragraph breaks)
// unless they occur at the very beginning of the text
- if (($body{$pos} == "\n") && (strlen($outString) != 0)) {
+ if (($body{$pos} == "\n" ) && (strlen($outString) != 0)) {
$outStringLast = $outString{strlen($outString) - 1};
if ($outStringLast != "\n") {
$outString .= "\n";
$pos = $nextNewline + 1;
continue;
}
-
+ /**
+ * Set this to false to stop appending short strings to previous lines
+ */
+ $smartwrap = true;
// inner loop, (obviously) handles wrapping up to
// the next newline
while ($pos < $nextNewline) {
while (($pos < $nextNewline) && (ctype_space ($body{$pos}))) {
$pos++;
}
-
// if this is a short line then just append it and continue outer loop
- if (($outStringCol + $nextNewline - $pos) <= ($wrap - $citeLevel - 1)) {
+ if (($outStringCol + $nextNewline - $pos) <= ($wrap - $citeLevel - 1) ) {
// if this is the final line in the input string then include
// any trailing newlines
+ // echo substr($body,$pos,$wrap). "<br />";
if (($nextNewline + 1 == $length) && ($body{$nextNewline} == "\n")) {
$nextNewline++;
}
// trim trailing spaces
$lastRealChar = $nextNewline;
- while (($lastRealChar > $pos) && (ctype_space ($body{$lastRealChar}))) {
+ while (($lastRealChar > $pos && $lastRealChar < $length) && (ctype_space ($body{$lastRealChar}))) {
$lastRealChar--;
}
+ // decide if appending the short string is what we want
+ if (($nextNewline < $length && $body{$nextNewline} == "\n") &&
+ isset($lastRealChar)) {
+ $mypos = $pos;
+ //check the first word:
+ while (($mypos < $length) && ($body{$mypos} == '>')) {
+ $mypos++;
+ // skip over any spaces interleaved among the cite markers
+ $oldpos = $mypos;
+ while (($mypos < $length) && ($body{$mypos} == ' ')) {
+ $mypos++;
+ }
+ }
+/*
+ $ldnspacecnt = 0;
+ if ($mypos == $nextNewline+1) {
+ while (($mypos < $length) && ($body{$mypos} == ' ')) {
+ $ldnspacecnt++;
+ }
+ }
+*/
+
+ $firstword = substr($body,$mypos,strpos($body,' ',$mypos) - $mypos);
+ //if ($dowrap || $ldnspacecnt > 1 || ($firstword && (
+ if (!$smartwrap || $firstword && (
+ $firstword{0} == '-' ||
+ $firstword{0} == '+' ||
+ $firstword{0} == '*' ||
+ $firstword{0} == strtoupper($firstword{0}) ||
+ strpos($firstword,':'))) {
+ $outString .= substr($body,$pos,($lastRealChar - $pos+1));
+ $outStringCol += ($lastRealChar - $pos);
+ sqMakeNewLine($outString,$citeLevel,$outStringCol);
+ $nextNewline++;
+ $pos = $nextNewline;
+ $outStringCol--;
+ continue;
+ }
+
+ }
$outString .= substr ($body, $pos, ($lastRealChar - $pos + 1));
$outStringCol += ($lastRealChar - $pos);
// our current line is already too long, break immediately
// and restart outer loop
if ($eol <= $pos) {
- sqMakeNewLine ($outString, $citeLeve, $outStringCol);
+ sqMakeNewLine ($outString, $citeLevel, $outStringCol);
continue;
}