diff options
-rw-r--r-- | Zotlabs/Module/Wiki.php | 15 | ||||
-rw-r--r-- | include/wiki.php | 20 | ||||
-rw-r--r-- | view/tpl/wiki.tpl | 2 |
3 files changed, 32 insertions, 5 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index 1c3add38f..de5863d2e 100644 --- a/Zotlabs/Module/Wiki.php +++ b/Zotlabs/Module/Wiki.php @@ -74,7 +74,9 @@ class Wiki extends \Zotlabs\Web\Controller { // Configure page template $wikiheaderName = t('Wiki'); $wikiheaderPage = t('Sandbox'); - $content = '"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."'; + require_once('library/markdown.php'); + $content = t('"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."'); + $renderedContent = Markdown(json_decode($content)); $hide_editor = false; $showPageControls = false; $showNewWikiButton = $wiki_owner; @@ -122,6 +124,9 @@ class Wiki extends \Zotlabs\Web\Controller { goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName); } $content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"'); + // Render the Markdown-formatted page content in HTML + require_once('library/markdown.php'); + $renderedContent = wiki_convert_links(Markdown(json_decode($content)),argv(0).'/'.argv(1).'/'.$wikiUrlName); $hide_editor = false; $showPageControls = $wiki_editor; $showNewWikiButton = $wiki_owner; @@ -133,8 +138,6 @@ class Wiki extends \Zotlabs\Web\Controller { default: // Strip the extraneous URL components goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName.'/'.$pageUrlName); } - // Render the Markdown-formatted page content in HTML - require_once('library/markdown.php'); $wikiModalID = random_string(3); $wikiModal = replace_macros( @@ -162,7 +165,7 @@ class Wiki extends \Zotlabs\Web\Controller { '$acl' => $x['acl'], '$bang' => $x['bang'], '$content' => $content, - '$renderedContent' => Markdown(json_decode($content)), + '$renderedContent' => $renderedContent, '$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''), '$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''), '$pageRename' => array('pageRename', t('Enter the new name:'), '', ''), @@ -193,8 +196,12 @@ class Wiki extends \Zotlabs\Web\Controller { // Render mardown-formatted text in HTML for preview if((argc() > 2) && (argv(2) === 'preview')) { $content = $_POST['content']; + $resource_id = $_POST['resource_id']; require_once('library/markdown.php'); $html = purify_html(Markdown($content)); + $w = wiki_get_wiki($resource_id); + $wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName']; + $html = wiki_convert_links($html,$wikiURL); json_return_and_die(array('html' => $html, 'success' => true)); } diff --git a/include/wiki.php b/include/wiki.php index fdbc704dc..63cf70f3c 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -473,4 +473,24 @@ function wiki_generate_page_filename($name) { } else { return $file . '.md'; } +} + +function wiki_convert_links($s, $wikiURL) { + + if (strpos($s,'[[') !== false) { + preg_match_all("/\[\[(.*?)\]\]/", $s, $match); + $pages = $pageURLs = array(); + foreach ($match[1] as $m) { + // TODO: Why do we need to double urlencode for this to work? + $pageURLs[] = urlencode(urlencode(escape_tags($m))); + $pages[] = $m; + } + $idx = 0; + while(strpos($s,'[[') !== false) { + $replace = '<a href="'.$wikiURL.'/'.$pageURLs[$idx].'">'.$pages[$idx].'</a>'; + $s = preg_replace("/\[\[(.*?)\]\]/", $replace, $s, 1); + $idx++; + } + } + return $s; }
\ No newline at end of file diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl index d0744009d..1d8570828 100644 --- a/view/tpl/wiki.tpl +++ b/view/tpl/wiki.tpl @@ -200,7 +200,7 @@ editor.getSession().setValue(window.wiki_page_content); $('#wiki-get-preview').click(function (ev) { - $.post("wiki/{{$channel}}/preview", {content: editor.getValue()}, function (data) { + $.post("wiki/{{$channel}}/preview", {content: editor.getValue(), resource_id: window.wiki_resource_id}, function (data) { if (data.success) { $('#wiki-preview').html(data.html); } else { |