Replace homemade table of content generator with existing jQuery plugin. Now toc is linked to document headings.
This commit is contained in:
		| @@ -126,8 +126,7 @@ class Wiki extends \Zotlabs\Web\Controller { | |||||||
| 				$content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"'); | 				$content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"'); | ||||||
| 				// Render the Markdown-formatted page content in HTML | 				// Render the Markdown-formatted page content in HTML | ||||||
| 				require_once('library/markdown.php');	 | 				require_once('library/markdown.php');	 | ||||||
| 				$toc_content = wiki_generate_toc(json_decode($content)); | 				$html = wiki_generate_toc(purify_html(Markdown(json_decode($content)))); | ||||||
| 				$html = purify_html(Markdown($toc_content)); |  | ||||||
| 				$renderedContent = wiki_convert_links($html,argv(0).'/'.argv(1).'/'.$wikiUrlName); | 				$renderedContent = wiki_convert_links($html,argv(0).'/'.argv(1).'/'.$wikiUrlName); | ||||||
| 				$hide_editor = false; | 				$hide_editor = false; | ||||||
| 				$showPageControls = $wiki_editor; | 				$showPageControls = $wiki_editor; | ||||||
| @@ -200,8 +199,7 @@ class Wiki extends \Zotlabs\Web\Controller { | |||||||
| 			$content = $_POST['content']; | 			$content = $_POST['content']; | ||||||
| 			$resource_id = $_POST['resource_id'];  | 			$resource_id = $_POST['resource_id'];  | ||||||
| 			require_once('library/markdown.php'); | 			require_once('library/markdown.php'); | ||||||
| 			$content = wiki_generate_toc($content); | 			$html = wiki_generate_toc(purify_html(Markdown($content))); | ||||||
| 			$html = purify_html(Markdown($content)); |  | ||||||
| 			$w = wiki_get_wiki($resource_id); | 			$w = wiki_get_wiki($resource_id); | ||||||
| 			$wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName']; | 			$wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName']; | ||||||
| 			$html = wiki_convert_links($html,$wikiURL); | 			$html = wiki_convert_links($html,$wikiURL); | ||||||
|   | |||||||
| @@ -498,7 +498,8 @@ function wiki_convert_links($s, $wikiURL) { | |||||||
| function wiki_generate_toc($s) { | function wiki_generate_toc($s) { | ||||||
| 	 | 	 | ||||||
| 	if (strpos($s,'[toc]') !== false) { | 	if (strpos($s,'[toc]') !== false) { | ||||||
| 		$toc_md = wiki_toc($s); | 		//$toc_md = wiki_toc($s);	// Generate Markdown-formatted list prior to HTML render | ||||||
|  | 		$toc_md = '<ul id="wiki-toc"></ul>'; // use the available jQuery plugin http://ndabas.github.io/toc/ | ||||||
| 		$s = preg_replace("/\[toc\]/", $toc_md, $s, -1); | 		$s = preg_replace("/\[toc\]/", $toc_md, $s, -1); | ||||||
| 	} | 	} | ||||||
| 	return $s; | 	return $s; | ||||||
|   | |||||||
| @@ -190,6 +190,7 @@ | |||||||
|    |    | ||||||
|   $(document).ready(function () { |   $(document).ready(function () { | ||||||
|     wiki_refresh_page_list(); |     wiki_refresh_page_list(); | ||||||
|  |     $("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"}); | ||||||
|     // Show Edit tab first. Otherwise the Ace editor does not load. |     // Show Edit tab first. Otherwise the Ace editor does not load. | ||||||
|     $("#wiki-nav-tabs li:eq(1) a").tab('show'); |     $("#wiki-nav-tabs li:eq(1) a").tab('show'); | ||||||
|   }); |   }); | ||||||
| @@ -203,6 +204,7 @@ | |||||||
|     $.post("wiki/{{$channel}}/preview", {content: editor.getValue(), resource_id: window.wiki_resource_id}, function (data) { |     $.post("wiki/{{$channel}}/preview", {content: editor.getValue(), resource_id: window.wiki_resource_id}, function (data) { | ||||||
|       if (data.success) { |       if (data.success) { | ||||||
|         $('#wiki-preview').html(data.html); |         $('#wiki-preview').html(data.html); | ||||||
|  |         $("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"}); | ||||||
|       } else { |       } else { | ||||||
|         window.console.log('Error previewing page.'); |         window.console.log('Error previewing page.'); | ||||||
|       } |       } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user