Sfoglia il codice sorgente

修改 ParsedownExtension 库 解决`[TOC]`目录多余重复标题不显示问题

huwhois 3 anni fa
parent
commit
766577e9e2
3 ha cambiato i file con 20 aggiunte e 6 eliminazioni
  1. 1 0
      README.md
  2. 16 3
      application/parsedown/ParsedownExtension.php
  3. 3 3
      public/html/index.html

+ 1 - 0
README.md

@ -7,3 +7,4 @@
7 7
* 编辑器使用的是 [ace.js](https://github.com/ajaxorg/ace), 暂未加入代码风格.
8 8
* ace中文输入有问题, 尝试使用 [codemirror](), 也没调好, 改回用基本的 textarea.
9 9
* 重新找了一个 ace 编辑器版本, 解决了中文输入问题
10
* 修改 ParsedownExtension 库 解决`[TOC]`目录多余重复标题不显示问题

+ 16 - 3
application/parsedown/ParsedownExtension.php

@ -40,7 +40,7 @@ class ParsedownExtension extends Parsedown
40 40
        $topHeadLevel       = min(array_column($this->rawTocList, 'level'));
41 41
42 42
        foreach ($this->rawTocList as $id => $tocItem) {
43
            $tocMarkdownContent .= sprintf('%s- [%s](#%s)' . PHP_EOL, str_repeat('  ', $tocItem['level'] - $topHeadLevel), $this->line($tocItem['text']), $id);
43
            $tocMarkdownContent .= sprintf('%s- [%s](#%s)' . PHP_EOL, str_repeat('  ', $tocItem['level'] - $topHeadLevel), $this->line($tocItem['text']), $tocItem['id']);
44 44
        }
45 45
46 46
        return parent::text($tocMarkdownContent);
@ -50,15 +50,28 @@ class ParsedownExtension extends Parsedown
50 50
    {
51 51
        $block = parent::blockHeader($line);
52 52
        $text  = $block['element']['handler']['argument'];
53
        $no = 0;
54
        foreach ($this->rawTocList as $key => $value) {
55
            if ($text == $value['text']) {
56
                $no = $value['no'] + 1;
57
            }
58
        }
59
        
53 60
        $id    = urlencode($this->line($text));
54
61
        
62
        if ($no != 0) {
63
            $id .= '-' . $no;
64
        }
65
        
55 66
        $block['element']['attributes'] = [
56 67
            'id' => $id,
57 68
        ];
58 69
59
        $this->rawTocList[$id] = [
70
        $this->rawTocList[] = [
71
            'id' => $id,
60 72
            'text'  => $text,
61 73
            'level' => str_replace('h', '', $block['element']['name']),
74
            'no'=> $no,
62 75
        ];
63 76
64 77
        return $block;

+ 3 - 3
public/html/index.html

@ -93,9 +93,9 @@
93 93
94 94
    <script>
95 95
        // 表格加上边框
96
        // $(document).ready(function(){
97
        //     $("table").addClass('table table-bordered');
98
        // });
96
        $(document).ready(function(){
97
            $("table").addClass('table table-bordered');
98
        });
99 99
100 100
        // ace 编辑器
101 101
        var editor = ace.edit('mdeditor');//左侧编辑框