Sfoglia il codice sorgente

修复Widgets\Code构造器传递代码无效问题

jqh 4 anni fa
parent
commit
694cf58a48
2 ha cambiato i file con 8 aggiunte e 6 eliminazioni
  1. 4 4
      src/Widgets/Code.php
  2. 4 2
      src/Widgets/Markdown.php

+ 4 - 4
src/Widgets/Code.php

@@ -19,8 +19,8 @@ class Code extends Markdown
         if (is_array($content) || is_object($content)) {
             $content = json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
         } elseif (is_file($content)) {
-            $this->fromFile($content, $start, $end);
-            $content = '';
+            $this->readFileContent($content, $start, $end);
+            $content = null;
         }
 
         parent::__construct($content);
@@ -71,7 +71,7 @@ class Code extends Markdown
      */
     public function section($file, $lineNumber = 1, $context = 5)
     {
-        return $this->fromFile($file, $lineNumber - $context, $lineNumber + $context);
+        return $this->readFileContent($file, $lineNumber - $context, $lineNumber + $context);
     }
 
     /**
@@ -83,7 +83,7 @@ class Code extends Markdown
      *
      * @return $this
      */
-    public function fromFile($file, $start = 1, $end = 10)
+    public function readFileContent($file, $start = 1, $end = 10)
     {
         if (! $file or ! is_readable($file) || $end < $start) {
             return $this;

+ 4 - 2
src/Widgets/Markdown.php

@@ -29,9 +29,11 @@ class Markdown extends Widget
         'sequenceDiagram' => true,
     ];
 
-    public function __construct($markdown = '')
+    public function __construct($markdown = null)
     {
-        $this->content($markdown);
+        if ($markdown !== null) {
+            $this->content($markdown);
+        }
 
         $this->id('mkd-'.Str::random(8));
     }