fix markdown in descriptions
authorMichael Wallner <mike@php.net>
Tue, 9 Sep 2014 09:35:19 +0000 (11:35 +0200)
committerMichael Wallner <mike@php.net>
Tue, 9 Sep 2014 09:38:04 +0000 (11:38 +0200)
mdref/Markdown.php
mdref/RefEntry.php
mdref/RefListing.php
views/index.phtml
views/mdref.phtml

index 6d761c29ad2f8dc4ac577129820fc8a57e0ef101..e8c5cb67af21cba2ce19c717e3699348e7c0f671 100644 (file)
@@ -12,7 +12,7 @@ class Markdown
        /**
         * @param \mdref\Path $path
         */
-       function __construct(Path $path) {
+       function __construct(Path $path = null) {
                $this->path = $path;
        }
        
@@ -20,6 +20,9 @@ class Markdown
         * @return string
         */
        function __toString() {
+               if (!$this->path) {
+                       return "";
+               }
                try {
                        $r = fopen($this->path->getFullPath(".md"), "r");
                        $md = \MarkdownDocument::createFromStream($r);
@@ -31,4 +34,10 @@ class Markdown
                }
                return $html;
        }
+
+       function quick($string) {
+               $md = \MarkdownDocument::createFromString($string);
+               $md->compile(\MarkdownDocument::AUTOLINK);
+               return $md->getHtml();
+       }
 }
index 2ad3d278b617308af441f95069477df2337d7363..6c54674cedad30a1b8b545ae596c4ea4dd9f63c6 100644 (file)
@@ -114,7 +114,7 @@ class RefEntry
        function readTitle() {
                $this->openFile();
                fseek($this->file, 1, SEEK_SET);
-               return htmlspecialchars(fgets($this->file));
+               return fgets($this->file);
        }
        
        /**
@@ -126,7 +126,7 @@ class RefEntry
                fseek($this->file, 0, SEEK_SET);
                fgets($this->file);
                fgets($this->file);
-               return htmlspecialchars(fgets($this->file));
+               return fgets($this->file);
        }
        
        /**
index 3816be23d60beb0b8a8c6ab33993e7efc39d7831..4c3b629eccb276193ef079d0e5c65fd275dbdebf 100644 (file)
@@ -71,7 +71,7 @@ class RefListing implements \Countable, \Iterator
         * @return \mdref\RefEntry
         */
        function current() {
-               return new RefEntry($this->path, $this->key());//$this->format($this->key());
+               return new RefEntry($this->path, $this->key());
        }
        
        /**
index dbd3017f372b7b4c479a8ab53597d767083cb744..417419d4d3c5ad0d247384445235dd2c6ec78291 100644 (file)
                        <?php $entry->recurse($refs, "/*.md", function($entry, $pattern, callable $recursor) { ?>
                        <ul>
                                <li><p><a href="<?=$entry->formatUrl()?>"><?=$entry->formatLink()?></a></p>
-                                       <?=$entry->readDescription()?>
-                                       <?php $recursor($entry, "/[A-Z]*.md") ?>
+                                       <?php
+                                               if (!isset($html)) {
+                                                       $html = new \mdref\Markdown;
+                                               }
+                                               echo $html->quick($entry->readDescription());
+                                               $recursor($entry, "/[A-Z]*.md");
+                                       ?>
                                </li>
                        </ul>
                        <?php }); ?>
index 5cec21d42ae76c3a438e6c2d86dfaefcf0163720..08df2e11a33e4a0b5abaf2654a541c38d53362b0 100644 (file)
@@ -6,8 +6,8 @@
        <?php foreach($sublisting as $entry) : ?>
                <li>
                        <h3><a href="<?=$entry->formatUrl()?>"><?=$entry->formatLink(true)?></a></h3>
-                       <p><?=$entry->readDescription()?></p>
-                       <p><?=$entry->readTitle()?></p>
+                       <p><?=$html->quick($entry->readDescription())?></p>
+                       <p><?=$view->esc($entry->readTitle())?></p>
                </li>
        <?php endforeach; ?>
        </ul>