Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否加上todolist呢? #11

Open
4 of 7 tasks
hellobbq opened this issue Oct 24, 2015 · 6 comments
Open
4 of 7 tasks

能否加上todolist呢? #11

hellobbq opened this issue Oct 24, 2015 · 6 comments

Comments

@hellobbq
Copy link

hellobbq commented Oct 24, 2015

  • 加或不加
  • 是个问题呢
- [ ] i
  - [ ] missing
  - [ ] you
  - [x] so
- [x] much
  • i
    • missing
    • you
    • so
  • much

btw:上次问题反馈处理真是速度,谢谢

@joyqi
Copy link
Member

joyqi commented Oct 24, 2015

可以考虑支持,但需要一点时间

@hellobbq
Copy link
Author

@joyqi 谢谢,我最近每天都有过来看看,谢谢分享

@tlerbao
Copy link

tlerbao commented Mar 14, 2017

todo list 现在还不支持啊。请问什么时候可以支持呢,特别需要这个功能。

@hsrzq
Copy link

hsrzq commented Jun 2, 2017

自己造轮子吧,比如我就搞了个SuperDown,不兼容markdown语法,但创造了一些自己的语法

@shiny
Copy link

shiny commented Dec 10, 2017

转眼两年过去了

@zhangkx666
Copy link

zhangkx666 commented Mar 20, 2018

@shiny @hellobbq @tlerbao 是不是这样的http://miao.blog/article/21
修改一下parseList方法实现

    /**
     * parseList
     *
     * @param array $lines
     * @return string
     */
    private function parseList(array $lines)
    {
        $html = '';
        $minSpace = 99999;
        $rows = array();

        // count levels
        foreach ($lines as $key => $line) {
            if (preg_match("/^(\s*)((?:[0-9a-z]+\.?)|\-|\+|\*)(\s+)(.*)$/", $line, $matches)) {
                $space = strlen($matches[1]);
                $type = false !== strpos('+-*', $matches[2]) ? 'ul' : 'ol';
                $minSpace = min($space, $minSpace);

                $rows[] = array($space, $type, $line, $matches[4]);
            } else {
                $rows[] = $line;
            }
        }

        $found = false;
        $secondMinSpace = 99999;
        foreach ($rows as $row) {
            if (is_array($row) && $row[0] != $minSpace) {
                $secondMinSpace = min($secondMinSpace, $row[0]);
                $found = true;
            }
        }
        $secondMinSpace = $found ? $secondMinSpace : $minSpace;

        $lastType = '';
        $leftLines = array();
        $row_types = []; //--
        $__count = 0; //--
        foreach ($rows as $row) {
            if (is_array($row)) {
                list ($space, $type, $line, $text) = $row;

                if ($space != $minSpace) {
                    $leftLines[] = preg_replace("/^\s{" . $secondMinSpace . "}/", '', $line);
                } else {

                    // 加上选择列表 //--
                    if (preg_match("/^(\s*)(\-\s+\[\s+\])(.*)$/", $line)) {
                        $check_type = 'unselect';
                    } else if (preg_match("/^(\s*)(\-\s+\[X\])(.*)$/i", $line)) {
                        $check_type = 'select';
                    } else {
                        $check_type = '';
                    }
                    $row_types[] = $check_type;
                    //--

                    if (!empty($leftLines)) {
                        $_html = $this->parse(implode("\n", $leftLines)); //--
                        $html .= "<li class='" . ($row_types[$__count++]) . "'>" . $_html . "</li>"; //--
                    }

                    if ($lastType != $type) {
                        if (!empty($lastType)) {
                            $html .= "</{$lastType}>";
                        }

                        $html .= "<{$type}>";
                    }

                    $leftLines = array($text);
                    $lastType = $type;
                }
            } else {
                $leftLines[] = preg_replace("/^\s{" . $secondMinSpace . "}/", '', $row);
            }
        }

        if (!empty($leftLines)) {
            $_html = $this->parse(implode("\n", $leftLines)); //--
            $html .= "<li class='" . ($row_types[$__count]) . "'>" . $_html . "</li></{$lastType}>"; //--
        }

        $html = preg_replace("/(\[[Xx]\]|\[\s+\])\s?/", '', $html); //--
        return $html;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants