Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@Theifmaster is probably a better way forward. But, I managed to remove 2 lines of code, and the unused variable $para;</p> <pre><code>&lt;?php class Markdown { private static $html = ''; private static $list_types = array( array('&gt;&gt;','&lt;ul&gt;','&lt;/ul&gt;'), array('&gt;&gt;&gt;','&lt;ol&gt;','&lt;/ol&gt;') ); private static $list_patterns = array( '/-[ ]+(.+)/' =&gt; ' &gt;&gt;\1', '/[0-9]{1}\. (.+)/' =&gt; ' &gt;&gt;&gt;\1' ); public static function convertText($markdown = array()) { foreach (explode("\n", strip_tags($markdown)) as &amp;$line) { $line = htmlentities($line, ENT_QUOTES, 'UTF-8'); foreach (self::$list_patterns as $pattern =&gt; $replace) { if (!is_array($line) &amp;&amp; preg_match($pattern, $line)) { $line = preg_replace($pattern, $replace, $line); $type = 0; foreach (self::$list_types as $key =&gt; $val) { if (preg_match('/ ' . $val[0] . ' /', $line)) $type = $key; } $line = preg_split('/' . self::$list_types[$type][0] . '/', $line); $line = array('depth' =&gt; strlen($line[0]), 'string' =&gt; $line[1], 'type' =&gt; $type); } } } while (!empty($markdown)) { $snippet = array_shift($markdown); if (is_array($snippet)) self::makeList($snippet, $markdown); else self::$html .= $snippet; } return self::$html; } private static function makeList($snippet, &amp;$markdown, $last_depth = 0, $close_tag = '') { if ($last_depth == $snippet['depth']) self::$html .= sprintf('&lt;/li&gt;&lt;li&gt;%s', $snippet['string']); elseif ($last_depth &lt; $snippet['depth']) self::$html .= sprintf('%s&lt;li&gt;%s', self::$list_types[$snippet['type']][1], $snippet['string']); elseif ($last_depth &gt; $snippet['depth']) self::$html .= sprintf('&lt;/li&gt;%s&lt;li&gt;%s', $close_tag, $snippet['string']); $next_snippet = array_shift($markdown); if (is_array($next_snippet)) self::makeList($next_snippet, $markdown, $snippet['depth'], self::$list_types[$snippet['type']][2]); else array_unshift($markdown, $next_snippet); self::$html .= sprintf('&lt;/li&gt;%s', $close_tag); } } </code></pre> <p>enjoy</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload