Nothing Special   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
new function trim_leading_urls
Browse files Browse the repository at this point in the history
new function from Falcon, trim_leading_urls, useful for generating post
name/title from plain text that is usually auto-linked/embedded, e.g.
photo posts
  • Loading branch information
tantek committed Apr 4, 2016
1 parent f72c6e7 commit 357e30a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cassis.js
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,24 @@ function ellipsize_to_word($s, $max, $e, $min) { /// ?> <!-- ///
return strcat(substr($s, 0, $slen), $e);
}

function trim_leading_urls($s) {
// deliberately trim URLs with explicit http: / https: from start
// keep schemeless URLs, @-names as expected user-visible text
// if empty or just space after trimming, just return original
$r = trim($s);
while (substr($r, 0, 5) == 'http:' || substr($r, 0, 6) == 'https:')
{
$ws = offset(' ', $r);
$rs = offset("\r", $r);
if ($rs == 0) { $rs = offset("\n", $r); }
if ($rs != 0 && $rs < $ws) { $ws = $rs; }
if ($ws == 0) { return $s; }
$r = substr($r, $ws, strlen($r)-$ws);
}
$r = trim($r);
return ((strlen($r) > 0) ? $r : $s);
}

function auto_space($s) {
// replace linebreaks with <br class="auto-break"/>
// and one leading space with &nbsp;
Expand Down

0 comments on commit 357e30a

Please sign in to comment.