Merge pull request #1837 from fabrixxm/feature-1796

add support for oneline,in-text code tag
This commit is contained in:
Tobias Diekershoff 2015-08-23 17:27:45 +02:00
commit fc18123082
4 changed files with 31 additions and 10 deletions

View file

@ -152,22 +152,22 @@ function format_event_diaspora($ev) {
$o .= '**' . (($ev['summary']) ? bb2diaspora($ev['summary']) : bb2diaspora($ev['desc'])) . '**' . "\n"; $o .= '**' . (($ev['summary']) ? bb2diaspora($ev['summary']) : bb2diaspora($ev['desc'])) . '**' . "\n";
$o .= t('Starts:') . ' ' . '[' $o .= t('Starts:') . ' ' . '['
. (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC',
$ev['start'] , $bd_format )) $ev['start'] , $bd_format ))
: day_translate(datetime_convert('UTC', 'UTC', : day_translate(datetime_convert('UTC', 'UTC',
$ev['start'] , $bd_format))) $ev['start'] , $bd_format)))
. '](' . $a->get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n"; . '](' . $a->get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n";
if(! $ev['nofinish']) if(! $ev['nofinish'])
$o .= t('Finishes:') . ' ' . '[' $o .= t('Finishes:') . ' ' . '['
. (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC',
$ev['finish'] , $bd_format )) $ev['finish'] , $bd_format ))
: day_translate(datetime_convert('UTC', 'UTC', : day_translate(datetime_convert('UTC', 'UTC',
$ev['finish'] , $bd_format ))) $ev['finish'] , $bd_format )))
. '](' . $a->get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n"; . '](' . $a->get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n";
if(strlen($ev['location'])) if(strlen($ev['location']))
$o .= t('Location:') . bb2diaspora($ev['location']) $o .= t('Location:') . bb2diaspora($ev['location'])
. "\n"; . "\n";
$o .= "\n"; $o .= "\n";

View file

@ -268,6 +268,13 @@ function stripcode_br_cb($s) {
return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]'; return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]';
} }
function bb_onelinecode_cb($match) {
if (strpos($match[1],"<br>")===false){
return "<key>".$match[1]."</key>";
}
return "<code>".$match[1]."</code>";
}
function tryoembed($match){ function tryoembed($match){
//$url = ((count($match)==2)?$match[1]:$match[2]); //$url = ((count($match)==2)?$match[1]:$match[2]);
$url = $match[1]; $url = $match[1];
@ -1179,7 +1186,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// If we found an event earlier, strip out all the event code and replace with a reformatted version. // If we found an event earlier, strip out all the event code and replace with a reformatted version.
// Replace the event-start section with the entire formatted event. The other bbcode is stripped. // Replace the event-start section with the entire formatted event. The other bbcode is stripped.
// Summary (e.g. title) is required, earlier revisions only required description (in addition to // Summary (e.g. title) is required, earlier revisions only required description (in addition to
// start which is always required). Allow desc with a missing summary for compatibility. // start which is always required). Allow desc with a missing summary for compatibility.
if((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) { if((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) {
@ -1193,6 +1200,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text); $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text);
} }
//replace oneliner <code> with <key>
$Text = preg_replace_callback("|(?!<br[^>]*>)<code>([^<]*)</code>(?!<br[^>]*>)|ism", 'bb_onelinecode_cb', $Text);
// Unhide all [noparse] contained bbtags unspacefying them // Unhide all [noparse] contained bbtags unspacefying them
// and triming the [noparse] tag. // and triming the [noparse] tag.

View file

@ -90,12 +90,18 @@ function html2bbcode($message)
$message = str_replace("\r", "", $message); $message = str_replace("\r", "", $message);
$message = preg_replace_callback("|<pre><code>([^<]*)</code></pre>|ism", function($m) {
return "<code>".str_replace("\n","<br>\n",$m[1]). "</code>";
}, $message);
$message = str_replace(array( $message = str_replace(array(
"<li><p>", "<li><p>",
"</p></li>"), "</p></li>",
),
array( array(
"<li>", "<li>",
"</li>"), "</li>",
),
$message); $message);
// remove namespaces // remove namespaces
@ -187,6 +193,7 @@ function html2bbcode($message)
node2bbcode($doc, 'span', array(), "", ""); node2bbcode($doc, 'span', array(), "", "");
node2bbcode($doc, 'pre', array(), "", ""); node2bbcode($doc, 'pre', array(), "", "");
node2bbcode($doc, 'div', array(), "\r", "\r"); node2bbcode($doc, 'div', array(), "\r", "\r");
node2bbcode($doc, 'p', array(), "\n", "\n"); node2bbcode($doc, 'p', array(), "\n", "\n");
@ -230,6 +237,7 @@ function html2bbcode($message)
node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]'); node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]');
node2bbcode($doc, 'code', array(), '[code]', '[/code]'); node2bbcode($doc, 'code', array(), '[code]', '[/code]');
node2bbcode($doc, 'key', array(), '[code]', '[/code]');
$message = $doc->saveHTML(); $message = $doc->saveHTML();

View file

@ -170,6 +170,9 @@ span.oembed, h4 {
margin: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;
} }
code { display: block; background-color: #eee; color: #666; padding:1em; font-size: 0.8em; font-family: monospace; }
key { display: inline; background-color: #eee; color: #666; padding:0.2em; font-size: 0.8em; font-family: monospace; }
/* fields help text */ /* fields help text */
.field .field_help { .field .field_help {
clear: left; clear: left;
@ -178,7 +181,6 @@ span.oembed, h4 {
/* notifications unseen */ /* notifications unseen */
.notify-unseen { background-color: #cceeFF; } .notify-unseen { background-color: #cceeFF; }
/* plain text editor upload/select popup */ /* plain text editor upload/select popup */
.fbrowser .path a { padding: 5px; } .fbrowser .path a { padding: 5px; }