diff --git a/src/Commands/Concerns/ManagesScreens.php b/src/Commands/Concerns/ManagesScreens.php index 0bbde4c..1bf2e66 100644 --- a/src/Commands/Concerns/ManagesScreens.php +++ b/src/Commands/Concerns/ManagesScreens.php @@ -31,7 +31,7 @@ protected function publishScreens($repo, $version, $subfolder) continue; } - $publicDir = public_path(config("docdress.repos.{$repo}.route_prefix").'/'.$version.str_replace($path, '', $file)); + $publicDir = storage_path('app/public/'.config("docdress.repos.{$repo}.route_prefix").'/'.$version.str_replace($path, '', $file)); File::ensureDirectoryExists($publicDir); File::copyDirectory($file, $publicDir); diff --git a/src/Documentor.php b/src/Documentor.php index 6f77f96..818fd68 100644 --- a/src/Documentor.php +++ b/src/Documentor.php @@ -6,6 +6,7 @@ use Docdress\Parser\CodeParser; use Docdress\Parser\LinkNameParser; use Docdress\Parser\LinkParser; +use Docdress\Parser\SrcParser; use Docdress\Parser\TocParser; use Illuminate\Contracts\Cache\Repository as Cache; use Illuminate\Filesystem\Filesystem; @@ -123,6 +124,7 @@ public function get($repo, $version, $page, $subfolder = null) TocParser::class, AlertParser::class, CodeParser::class, + SrcParser::class, LinkParser::class, LinkNameParser::class, ]; diff --git a/src/Parser/SrcParser.php b/src/Parser/SrcParser.php new file mode 100644 index 0000000..7fb2038 --- /dev/null +++ b/src/Parser/SrcParser.php @@ -0,0 +1,56 @@ +getSrcOutsideOfCodeBlocks($text); + + foreach ($matches[0] as $link) { + if (Str::startsWith($link, '#')) { + continue; + } + + if (array_key_exists('host', parse_url($link))) { + $replace = "{$link}"; + } else { + $path = explode('/', request()->getPathInfo()); + array_pop($path); + $replace = '/storage'.implode('/', $path).'/'.str_replace('./', '', $link); + } + + $text = str_replace($link, $replace, $text); + } + + return $text; + } + + /** + * Get links outside of code blocks. + * + * @param string $text + * @return array + */ + protected function getSrcOutsideOfCodeBlocks($text) + { + preg_match_all('#<\s*?code\b[^>]*>(.*?)]*>#s', $text, $matches); + + foreach ($matches[0] as $match) { + $text = str_replace($match, '', $text); + } + + preg_match_all('/(?<=\bsrc=")[^"]*/', $text, $matches); + + return $matches; + } +}