aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-03-20 13:37:11 +0000
committerMario <mario@mariovavti.com>2024-03-20 13:37:11 +0000
commit4f8ede35bdbcd1d068c431de685d583ff55f98cc (patch)
tree5ab76159536405162af9cc486717aef253fedbeb
parent9d9c102da82208ae03c0380a08288dd9ff26684a (diff)
parent3de8f5e7de424563cfe521848b2e2d11d100fcc5 (diff)
downloadvolse-hubzilla-4f8ede35bdbcd1d068c431de685d583ff55f98cc.tar.gz
volse-hubzilla-4f8ede35bdbcd1d068c431de685d583ff55f98cc.tar.bz2
volse-hubzilla-4f8ede35bdbcd1d068c431de685d583ff55f98cc.zip
Merge branch 'dev' of https://framagit.org/hubzilla/core into dev
-rw-r--r--include/bbcode.php47
-rw-r--r--include/html2bbcode.php30
-rw-r--r--tests/unit/includes/BBCodeTest.php16
-rw-r--r--vendor/composer/installed.php4
4 files changed, 72 insertions, 25 deletions
diff --git a/include/bbcode.php b/include/bbcode.php
index db4147c1e..86944ba60 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -1054,6 +1054,15 @@ function bb_fixtable_lf($match) {
}
+function bb_fix_lf($match) {
+ // remove extraneous whitespace between element tags since newlines will all
+ // be converted to '<br />' and turn your neatly crafted tables into a whole lot of
+ // empty space.
+
+ $new_content = str_replace(["\n\r", "\n", "\r"], '', $match[1]);
+ return str_replace($match[1], $new_content, $match[0]);
+}
+
function bbtopoll($s) {
$pl = [];
@@ -1207,8 +1216,6 @@ function bbcode($text, $options = []) {
}
}
-
-
$text = bb_format_attachdata($text);
// If we find any event code, turn it into an event.
@@ -1249,7 +1256,7 @@ function bbcode($text, $options = []) {
$text = str_replace("<", "&lt;", $text);
$text = str_replace(">", "&gt;", $text);
- $text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fixtable_lf',$text);
+
$text = str_replace(array("\t", " "), array("&nbsp;&nbsp;&nbsp;&nbsp;", "&nbsp;&nbsp;"), $text);
// Check for [code] text here, before the linefeeds are messed with.
@@ -1487,10 +1494,10 @@ function bbcode($text, $options = []) {
// Check for list text
- $text = preg_replace("/<br \/>\[\*\]/ism",'[*]',$text);
-
+ $text = str_replace(["\r\n[*]", "\r[*]", "\n[*]"], "[*]", $text);
$text = str_replace("[*]", "<li>", $text);
+
// handle nested lists
$endlessloop = 0;
@@ -1499,16 +1506,35 @@ function bbcode($text, $options = []) {
((strpos($text, "[/ul]") !== false) && (strpos($text, "[ul]") !== false)) ||
((strpos($text, "[/dl]") !== false) && (strpos($text, "[dl") !== false)) ||
((strpos($text, "[/li]") !== false) && (strpos($text, "[li]") !== false))) && (++$endlessloop < 20)) {
+
+ $text = preg_replace_callback("/\[list\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet">$1</ul>', $text);
+
+ $text = preg_replace_callback("/\[list=\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $text);
+
+ $text = preg_replace_callback("/\[list=1\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $text);
+
+ $text = preg_replace_callback("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>', $text);
+
+ $text = preg_replace_callback("/\[list=((?-i)I)\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>', $text);
+
+ $text = preg_replace_callback("/\[list=((?-i)a)\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>', $text);
+
+ $text = preg_replace_callback("/\[list=((?-i)A)\](.*?)\[\/list\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>', $text);
- $text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '<ul class="listbullet">$1</ul>', $text);
+
+ $text = preg_replace_callback("/\[ol\](.*?)\[\/ol\]/ism",'bb_fix_lf', $text);
$text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $text);
- $text = preg_replace("/\[\/li\]<br \/>\[li\]/ism",'[/li][li]',$text);
+
+ $text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/ism",'bb_fix_lf', $text);
+ $text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '<ul class="listbullet">$1</ul>', $text);
+
+ $text = preg_replace("/\[\/li\]<br \/>\[li\]/ism",'[/li][li]', $text);
$text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>', $text);
// [dl] tags have an optional [dl terms="bi"] form where bold/italic/underline/mono/large
@@ -1521,24 +1547,29 @@ function bbcode($text, $options = []) {
}
if (strpos($text,'[checklist]') !== false) {
+ $text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism",'bb_fix_lf', $text);
$text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism", 'bb_checklist', $text);
}
if (strpos($text,'[th]') !== false) {
$text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>', $text);
}
+
if (strpos($text,'[td]') !== false) {
$text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '<td>$1</td>', $text);
}
+
if (strpos($text,'[tr]') !== false) {
$text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '<tr>$1</tr>', $text);
}
+
if (strpos($text,'[/table]') !== false) {
+ $text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fix_lf',$text);
$text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '<table>$1</table>', $text);
$text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '<table class="table table-responsive table-bordered" >$1</table>', $text);
$text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '<table class="table table-responsive" >$1</table>', $text);
}
- $text = str_replace('</tr><br /><tr>', "</tr>\n<tr>", $text);
+
$text = str_replace('[hr]', '<hr />', $text);
// This is actually executed in prepare_body()
diff --git a/include/html2bbcode.php b/include/html2bbcode.php
index 009c051e6..03e09cd62 100644
--- a/include/html2bbcode.php
+++ b/include/html2bbcode.php
@@ -187,25 +187,24 @@ function html2bbcode($message)
node2bbcode($doc, 'u', array(), '[u]', '[/u]');
node2bbcode($doc, 's', array(), '[s]', '[/s]');
node2bbcode($doc, 'mark', array(), '[mark]', '[/mark]');
+ node2bbcode($doc, 'span', array(), "", "");
node2bbcode($doc, 'big', array(), "[size=large]", "[/size]");
node2bbcode($doc, 'small', array(), "[size=small]", "[/size]");
- node2bbcode($doc, 'blockquote', array(), '[quote]', '[/quote]');
-
// Use a temporary tag to keep line breaks
node2bbcode($doc, 'br', array(), '[br]', '');
node2bbcode($doc, 'a', array('href'=>'/(.+)/'), '[url=$1]', '[/url]');
- node2bbcode($doc, 'p', array('class'=>'MsoNormal'), "\n", "");
- node2bbcode($doc, 'div', array('class'=>'MsoNormal'), "\r", "");
+ node2bbcode($doc, 'img', array('src'=>'/(.+)/', 'width'=>'/(\d+)/', 'height'=>'/(\d+)/'), '[img=$2x$3]$1', '[/img]');
+ node2bbcode($doc, 'img', array('src'=>'/(.+)/', 'alt'=>'/(.+)/'), '[img=$1]$2', '[/img]');
+ node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '[img]$1', '[/img]');
- node2bbcode($doc, 'span', array(), "", "");
+ node2bbcode($doc, 'video', array('src'=>'/(.+)/'), '[video]$1', '[/video]');
+ node2bbcode($doc, 'audio', array('src'=>'/(.+)/'), '[audio]$1', '[/audio]');
+// node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]');
- node2bbcode($doc, 'pre', array(), "", "");
- node2bbcode($doc, 'div', array(), "\r", "\r");
- node2bbcode($doc, 'p', array(), "\n", "\n");
node2bbcode($doc, 'ul', array(), "[list]", "[/list]");
node2bbcode($doc, 'ol', array(), "[list=1]", "[/list]");
@@ -229,18 +228,19 @@ function html2bbcode($message)
node2bbcode($doc, 'h5', array(), "[h5]", "[/h5]");
node2bbcode($doc, 'h6', array(), "[h6]", "[/h6]");
- node2bbcode($doc, 'img', array('src'=>'/(.+)/', 'width'=>'/(\d+)/', 'height'=>'/(\d+)/'), '[img=$2x$3]$1', '[/img]');
- node2bbcode($doc, 'img', array('src'=>'/(.+)/', 'alt'=>'/(.+)/'), '[img=$1]$2', '[/img]');
- node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '[img]$1', '[/img]');
-
- node2bbcode($doc, 'video', array('src'=>'/(.+)/'), '[video]$1', '[/video]');
- node2bbcode($doc, 'audio', array('src'=>'/(.+)/'), '[audio]$1', '[/audio]');
-// node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]');
+ node2bbcode($doc, 'blockquote', array(), '[quote]', '[/quote]');
+ node2bbcode($doc, 'pre', array(), "", "");
node2bbcode($doc, 'code', array('class'=>'/(.+)/'), '[code=$1]', '[/code]');
node2bbcode($doc, 'code', array(), '[code]', '[/code]');
+ node2bbcode($doc, 'p', array('class'=>'MsoNormal'), "\n", "");
+ node2bbcode($doc, 'p', array(), "\n", "\n");
+
+ node2bbcode($doc, 'div', array('class'=>'MsoNormal'), "\r", "");
+ node2bbcode($doc, 'div', array(), "\r", "\r");
+
$message = $doc->saveHTML();
// I'm removing the UTF-8 encoding of a NO-BREAK SPACE codepoint
diff --git a/tests/unit/includes/BBCodeTest.php b/tests/unit/includes/BBCodeTest.php
index 0da50f77a..100d28fc4 100644
--- a/tests/unit/includes/BBCodeTest.php
+++ b/tests/unit/includes/BBCodeTest.php
@@ -107,6 +107,18 @@ class BBCodeTest extends UnitTestCase {
"[code]\ntestvar = \"this is a test\"\necho \"the message is \$testvar\"\n[/code]",
'<pre><code>testvar = "this is a test"<br />echo "the message is $testvar"</code></pre>',
],
+ 'list with linebreaks \n' => [
+ "some text\n[list]\n[*] item1\n[*] item2\n[/list]\nsome more text",
+ 'some text<br /><ul class="listbullet"><li> item1<li> item2</ul><br />some more text'
+ ],
+ 'list with linebreaks \r' => [
+ "some text\r[list]\r[*] item1\r[*] item2\r[/list]\rsome more text",
+ 'some text<br /><ul class="listbullet"><li> item1<li> item2</ul><br />some more text'
+ ],
+ 'list with linebreaks \r\n' => [
+ "some text\r\n[list]\r\n[*] item1\r\n[*] item2\r\n[/list]\r\nsome more text",
+ 'some text<br /><ul class="listbullet"><li> item1<li> item2</ul><br />some more text'
+ ]
];
}
@@ -198,6 +210,10 @@ class BBCodeTest extends UnitTestCase {
'nested tags with ampersand and new line' => [
"<b>\n<i>foo & bar</i></b>",
'[b] [i]foo &amp; bar[/i][/b]'
+ ],
+ 'html reshares from streams' => [
+ '<div><div><a href="https://example.com"><img src="https://example.com/image.jpg" alt="image/photo"></a> shared something</div>something</div>',
+ '[url=https://example.com][img=https://example.com/image.jpg]image/photo[/img][/url] shared something' . "\n" . 'something'
]
];
}
diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php
index 17113d857..4386e70b5 100644
--- a/vendor/composer/installed.php
+++ b/vendor/composer/installed.php
@@ -3,7 +3,7 @@
'name' => 'zotlabs/hubzilla',
'pretty_version' => 'dev-9.0RC',
'version' => 'dev-9.0RC',
- 'reference' => 'fe018d646a4f25d3512059f6e8d520441e95967c',
+ 'reference' => 'a18e873d08e733225c70b0ace31c3cbb025ff906',
'type' => 'application',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -340,7 +340,7 @@
'zotlabs/hubzilla' => array(
'pretty_version' => 'dev-9.0RC',
'version' => 'dev-9.0RC',
- 'reference' => 'fe018d646a4f25d3512059f6e8d520441e95967c',
+ 'reference' => 'a18e873d08e733225c70b0ace31c3cbb025ff906',
'type' => 'application',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),