diff --git a/doc/bbcode.html b/doc/bbcode.html
index f0b61b33c..f75b1c90b 100644
--- a/doc/bbcode.html
+++ b/doc/bbcode.html
@@ -49,26 +49,31 @@
Red Matrix specific codes
-- [©] © This works for many HTML entities
- - [zrl]https://redmatrix.me[/zrl] Magic-auth version of [url] tag
- - [zmg]https://redmatrix.me/some/photo.jpg[/zmg] Magic-auth version of [img] tag
-
- - [observer=1]Text to display if observer is authenticated in the matrix[/observer]
-
- [observer=0]Text to display if observer is not authenticated in the matrix[/observer]
- - [observer.baseurl] website of observer
- - [observer.url] channel URL of observer
- - [observer.name] name of observer
- - [observer.address] address (zot-id) of observer
- - [observer.photo] profile photo of observer
-
- - [spoiler] for hiding spoilers
+ - [©] © This works for many HTML entities
+- [zrl]https://redmatrix.me[/zrl] Magic-auth version of [url] tag
+- [zmg]https://redmatrix.me/some/photo.jpg[/zmg] Magic-auth version of [img] tag
-- [rpost=title]Text to post[/rpost] The observer will be returned to their home hub to enter a post with the specified title and body. Both are optional
- - [qr]text to post[/qr] - create a QR code.
- - [toc] - create a table of content in a webpage (level h1,...,h4).
-
+ - [observer=1]Text to display if observer is authenticated in the matrix[/observer]
+- [observer=0]Text to display if observer is not authenticated in the matrix[/observer]
+- [observer.baseurl] website of observer
+- [observer.url] channel URL of observer
+- [observer.name] name of observer
+- [observer.address] address (zot-id) of observer
+- [observer.photo] profile photo of observer
+
+- [spoiler] for hiding spoilers
+
+- [rpost=title]Text to post[/rpost] The observer will be returned to their home hub to enter a post with the specified title and body. Both are optional
+- [qr]text to post[/qr] - create a QR code.
+- [toc] - create a table of content in a webpage. Please refer to the original jquery toc to get more explanations.
+
+ - Optional param: 'data-toc'. If ommited the default is 'body'
+ - Optional param: 'data-toc-headings'. If ommited the default is 'h1,h2,h3'
+ - Full example: [toc data-toc='div.page-body' data-toc-headings='h1,h2']
+
+
-
+
These require a suitable map plugin/addon such as openstreetmap or else the result will be blank
- [map] Generate an inline map using the current browser coordinates of the poster, if browser location is enabled
diff --git a/include/bbcode.php b/include/bbcode.php
index 8f2b5bd38..82d0bd1d1 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -582,9 +582,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
if (strpos($Text,'[h6]') !== false) {
$Text = preg_replace("(\[h6\](.*?)\[\/h6\])ism",'$1
',$Text);
}
- // Check for table of content
+ // Check for table of content without params
if (strpos($Text,'[toc]') !== false) {
- $Text = preg_replace("/\[toc\]/ism",'',$Text);
+ $Text = preg_replace("/\[toc\]/ism",'',$Text);
+ }
+ // Check for table of content with params
+ if (strpos($Text,'[toc') !== false) {
+ $Text = preg_replace("/\[toc([^\]]+?)\]/ism",'',$Text);
+
}
// Check for centered text
if (strpos($Text,'[/center]') !== false) {
diff --git a/library/tableofcontents/jquery.toc.js b/library/tableofcontents/jquery.toc.js
index 6ef36f49c..fe10850a3 100644
--- a/library/tableofcontents/jquery.toc.js
+++ b/library/tableofcontents/jquery.toc.js
@@ -15,8 +15,6 @@
*
* The original script was modified to work within the red#martrix
* - added var pathname
- * - added var textHeading: Accept heading with text only
- * Why? At the moment webpages can contain empty title using h3
*/
(function ($) {
@@ -55,36 +53,31 @@
// What level is the current heading?
var elem = $(this), level = $.map(headingSelectors, function (selector, index) {
return elem.is(selector) ? index : undefined;
- })[0];
-
- // Accept heading with text only
- var textHeading = elem.text();
- if(textHeading != '') {
- if (level > currentLevel) {
- // If the heading is at a deeper level than where we are, start a new nested
- // list, but only if we already have some list items in the parent. If we do
- // not, that means that we're skipping levels, so we can just add new list items
- // at the current level.
- // In the upside-down stack, unshift = push, and stack[0] = the top.
- var parentItem = stack[0].children("li:last")[0];
- if (parentItem) {
- stack.unshift($("<" + listTag + "/>").appendTo(parentItem));
- }
- } else {
- // Truncate the stack to the current level by chopping off the 'top' of the
- // stack. We also need to preserve at least one element in the stack - that is
- // the containing element.
- stack.splice(0, Math.min(currentLevel - level, Math.max(stack.length - 1, 0)));
+ })[0];
+ if (level > currentLevel) {
+ // If the heading is at a deeper level than where we are, start a new nested
+ // list, but only if we already have some list items in the parent. If we do
+ // not, that means that we're skipping levels, so we can just add new list items
+ // at the current level.
+ // In the upside-down stack, unshift = push, and stack[0] = the top.
+ var parentItem = stack[0].children("li:last")[0];
+ if (parentItem) {
+ stack.unshift($("<" + listTag + "/>").appendTo(parentItem));
}
- // the variable pathname was added to the original script.
- var pathname = window.location.pathname;
- // Add the list item
- $(" ").appendTo(stack[0]).append(
- $("").text(elem.text()).attr("href", pathname + "#" + elem.attr("id"))
- );
-
- currentLevel = level;
+ } else {
+ // Truncate the stack to the current level by chopping off the 'top' of the
+ // stack. We also need to preserve at least one element in the stack - that is
+ // the containing element.
+ stack.splice(0, Math.min(currentLevel - level, Math.max(stack.length - 1, 0)));
}
+ // the variable pathname was added to the original script.
+ var pathname = window.location.pathname;
+ // Add the list item
+ $("").appendTo(stack[0]).append(
+ $("").text(elem.text()).attr("href", pathname + "#" + elem.attr("id"))
+ );
+
+ currentLevel = level;
});
});
}, old = $.fn.toc;
diff --git a/view/js/main.js b/view/js/main.js
index 17ea42db7..48505fc04 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -1125,7 +1125,7 @@ $(document).ready(function() {
$(".autotime").timeago();
- $("#toc").toc({content: "body", headings: "h1,h2,h3,h4"});
+ $("#toc").toc();
});