]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #701 from ArthurHoaro/plugins/md-html-doc
authorArthur <arthur@hoa.ro>
Sat, 3 Dec 2016 07:52:12 +0000 (08:52 +0100)
committerGitHub <noreply@github.com>
Sat, 3 Dec 2016 07:52:12 +0000 (08:52 +0100)
Describe markdown HTML rendering and display a warning

index.php
plugins/markdown/README.md
plugins/markdown/markdown.php
tests/plugins/PluginMarkdownTest.php
tpl/editlink.html
tpl/tools.html

index 84282b8dc6c6ecc41dd67cae0eae0e9c3fdf883a..5366cb0e22fbdafe221e0b0a2c1910b67f5122f0 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1078,6 +1078,7 @@ function renderPage($conf, $pluginManager)
     {
         $data = array(
             'pageabsaddr' => index_url($_SERVER),
+            'sslenabled' => !empty($_SERVER['HTTPS'])
         );
         $pluginManager->executeHooks('render_tools', $data);
 
index c64a831a1cb2a76f1a724889fe8fe900c0c34a94..aafcf0662ecf778da3051a44f891f5add70d3479 100644 (file)
@@ -20,26 +20,35 @@ The directory structure should look like:
      |--- markdown.css
      |--- markdown.meta
      |--- markdown.php
-     |--- Parsedown.php
      |--- README.md
 ```
 
 To enable the plugin, just check it in the plugin administration page.
 
-You can also add `markdown` to your list of enabled plugins in `data/config.php`
-(`ENABLED_PLUGINS` array).
+You can also add `markdown` to your list of enabled plugins in `data/config.json.php`
+(`general.enabled_plugins` list).
 
 This should look like:
 
 ```
-$GLOBALS['config']['ENABLED_PLUGINS'] = array('qrcode', 'any_other_plugin', 'markdown')
+"general": {
+  "enabled_plugins": [
+    "markdown",
+    [...]
+  ],
+}
 ```
 
+Parsedown parsing library is imported using Composer. If you installed Shaarli using `git`,
+or the `master` branch, run
+
+    composer update --no-dev --prefer-dist
+
 ### No Markdown tag
 
-If the tag `.nomarkdown` is set for a shaare, it won't be converted to Markdown syntax.
+If the tag `nomarkdown` is set for a shaare, it won't be converted to Markdown syntax.
  
-> Note: it's a private tag (leading dot), so it won't be displayed to visitors.
+> Note: this is a special tag, so it won't be displayed in link list.
 
 ### HTML rendering
 
index a764b6fa88520711ec6b46183894040055e6fe3a..0cf6e6e2d283e32de9ec978389cad40ad5c309c0 100644 (file)
@@ -22,7 +22,7 @@ function hook_markdown_render_linklist($data)
 {
     foreach ($data['links'] as &$value) {
         if (!empty($value['tags']) && noMarkdownTag($value['tags'])) {
-            $value['taglist'] = stripNoMarkdownTag($value['taglist']);
+            $value = stripNoMarkdownTag($value);
             continue;
         }
         $value['description'] = process_markdown($value['description']);
@@ -41,7 +41,7 @@ function hook_markdown_render_feed($data)
 {
     foreach ($data['links'] as &$value) {
         if (!empty($value['tags']) && noMarkdownTag($value['tags'])) {
-            $value['tags'] = stripNoMarkdownTag($value['tags']);
+            $value = stripNoMarkdownTag($value);
             continue;
         }
         $value['description'] = process_markdown($value['description']);
@@ -63,6 +63,7 @@ function hook_markdown_render_daily($data)
     foreach ($data['cols'] as &$value) {
         foreach ($value as &$value2) {
             if (!empty($value2['tags']) && noMarkdownTag($value2['tags'])) {
+                $value2 = stripNoMarkdownTag($value2);
                 continue;
             }
             $value2['formatedDescription'] = process_markdown($value2['formatedDescription']);
@@ -81,20 +82,30 @@ function hook_markdown_render_daily($data)
  */
 function noMarkdownTag($tags)
 {
-    return strpos($tags, NO_MD_TAG) !== false;
+    return preg_match('/(^|\s)'. NO_MD_TAG .'(\s|$)/', $tags);
 }
 
 /**
  * Remove the no-markdown meta tag so it won't be displayed.
  *
- * @param string $tags Tag list.
+ * @param array $link Link data.
  *
- * @return string tag list without no markdown tag.
+ * @return array Updated link without no markdown tag.
  */
-function stripNoMarkdownTag($tags)
+function stripNoMarkdownTag($link)
 {
-    unset($tags[array_search(NO_MD_TAG, $tags)]);
-    return array_values($tags);
+    if (! empty($link['taglist'])) {
+        $offset = array_search(NO_MD_TAG, $link['taglist']);
+        if ($offset !== false) {
+            unset($link['taglist'][$offset]);
+        }
+    }
+
+    if (!empty($link['tags'])) {
+        str_replace(NO_MD_TAG, '', $link['tags']);
+    }
+
+    return $link;
 }
 
 /**
index 12bdda24231b47a9cad0454694d030d7b4884362..17ef228031331fba63fbb5ef567a3fc1fa06c04c 100644 (file)
@@ -8,8 +8,8 @@ require_once 'application/Utils.php';
 require_once 'plugins/markdown/markdown.php';
 
 /**
- * Class PlugQrcodeTest
- * Unit test for the QR-Code plugin
+ * Class PluginMarkdownTest
+ * Unit test for the Markdown plugin
  */
 class PluginMarkdownTest extends PHPUnit_Framework_TestCase
 {
@@ -130,8 +130,11 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
             ))
         );
 
-        $data = hook_markdown_render_linklist($data);
-        $this->assertEquals($str, $data['links'][0]['description']);
+        $processed = hook_markdown_render_linklist($data);
+        $this->assertEquals($str, $processed['links'][0]['description']);
+
+        $processed = hook_markdown_render_feed($data);
+        $this->assertEquals($str, $processed['links'][0]['description']);
 
         $data = array(
             // Columns data
@@ -152,6 +155,24 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']);
     }
 
+    /**
+     * Test that a close value to nomarkdown is not understand as nomarkdown (previous value `.nomarkdown`).
+     */
+    function testNoMarkdownNotExcactlyMatching()
+    {
+        $str = 'All _work_ and `no play` makes Jack a *dull* boy.';
+        $data = array(
+            'links' => array(array(
+                'description' => $str,
+                'tags' => '.' . NO_MD_TAG,
+                'taglist' => array('.'. NO_MD_TAG),
+            ))
+        );
+
+        $data = hook_markdown_render_feed($data);
+        $this->assertContains('<em>', $data['links'][0]['description']);
+    }
+
     /**
      * Test hashtag links processed with markdown.
      */
index 441b530271fb0e5e6dcceaa5b674a6ea47de5125..9e7621dbea26b7452a167974b25fc1ca16d48a52 100644 (file)
@@ -8,13 +8,15 @@
 {elseif="$link.description==''"}onload="document.linkform.lf_description.focus();"
 {else}onload="document.linkform.lf_tags.focus();"{/if} >
 <div id="pageheader">
-       {if="$source !== 'firefoxsocialapi'"}
-       {include="page.header"}
-       {/if}
-       <div id="editlinkform">
-           <form method="post" name="linkform">
-               <input type="hidden" name="lf_linkdate" value="{$link.linkdate}">
-               <label for="lf_url"><i>URL</i></label><br><input type="text" name="lf_url" id="lf_url" value="{$link.url}" class="lf_input"><br>
+    {if="$source !== 'firefoxsocialapi'"}
+    {include="page.header"}
+    {else}
+    <div id="shaarli_title"><a href="{$titleLink}">{$shaarlititle}</a></div>
+    {/if}
+    <div id="editlinkform">
+        <form method="post" name="linkform">
+            <input type="hidden" name="lf_linkdate" value="{$link.linkdate}">
+            <label for="lf_url"><i>URL</i></label><br><input type="text" name="lf_url" id="lf_url" value="{$link.url}" class="lf_input"><br>
             <label for="lf_title"><i>Title</i></label><br><input type="text" name="lf_title" id="lf_title" value="{$link.title}" class="lf_input"><br>
             <label for="lf_description"><i>Description</i></label><br><textarea name="lf_description" id="lf_description" rows="4" cols="25">{$link.description}</textarea><br>
             <label for="lf_tags"><i>Tags</i></label><br>
                 {$value}
             {/loop}
 
-               {if="($link_is_new && $default_private_links) || $link.private == true"}
+            {if="($link_is_new && $default_private_links) || $link.private == true"}
             <input type="checkbox" checked="checked" name="lf_private" id="lf_private">
             &nbsp;<label for="lf_private"><i>Private</i></label><br>
             {else}
             <input type="checkbox"  name="lf_private" id="lf_private">
             &nbsp;<label for="lf_private"><i>Private</i></label><br>
             {/if}
-               <input type="submit" value="Save" name="save_edit" class="bigbutton">
-               <input type="submit" value="Cancel" name="cancel_edit" class="bigbutton">
-               {if="!$link_is_new"}<input type="submit" value="Delete" name="delete_link" class="bigbutton delete" onClick="return confirmDeleteLink();">{/if}
-               <input type="hidden" name="token" value="{$token}">
-               {if="$http_referer"}<input type="hidden" name="returnurl" value="{$http_referer}">{/if}
-           </form>
-       </div>
+            <input type="submit" value="Save" name="save_edit" class="bigbutton">
+            <input type="submit" value="Cancel" name="cancel_edit" class="bigbutton">
+            {if="!$link_is_new"}<input type="submit" value="Delete" name="delete_link" class="bigbutton delete" onClick="return confirmDeleteLink();">{/if}
+            <input type="hidden" name="token" value="{$token}">
+            {if="$http_referer"}<input type="hidden" name="returnurl" value="{$http_referer}">{/if}
+        </form>
+    </div>
 </div>
 {if="$source !== 'firefoxsocialapi'"}
 {include="page.footer"}
index 8e285f445733cf5c28ded6387e1bc541521243e4..e06d239d4fe07f8beb6d2e140dde7031abee2cfc 100644 (file)
                                &nbsp;&nbsp;&nbsp;&nbsp;Then click "✚Add Note" button anytime to start composing a private Note (text post) to your Shaarli.
                        </span>
                </a><br><br>
+
+               {if="$sslenabled"}
                <a class="smallbutton" onclick="activateFirefoxSocial(this)">
                        <b>✚Add to Firefox social</b>
                </a>
                <a href="#">
                        <span>&#x21D0; Click on this button to add Shaarli to the "Share this page" button in Firefox.</span>
                </a><br><br>
+               {/if}
 
                {loop="$tools_plugin"}
             {$value}
@@ -64,6 +67,7 @@
                <div class="clear"></div>
 
                <script>
+                       {if="$sslenabled"}
                        function activateFirefoxSocial(node) {
                                var loc = location.href;
                                var baseURL = loc.substring(0, loc.lastIndexOf("/"));
@@ -87,7 +91,7 @@
                                var activate = new CustomEvent("ActivateSocialFeature");
                                node.dispatchEvent(activate);
                        }
-
+                       {/if}
                        function alertBookmarklet() {
                                alert('Drag this link to your bookmarks toolbar, or right-click it and choose Bookmark This Link...');
                                return false;