Skip to content

Commit

Permalink
screens
Browse files Browse the repository at this point in the history
  • Loading branch information
cbl committed Aug 25, 2020
1 parent cc04acc commit 08c06ba
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Commands/Concerns/ManagesScreens.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Documentor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,6 +124,7 @@ public function get($repo, $version, $page, $subfolder = null)
TocParser::class,
AlertParser::class,
CodeParser::class,
SrcParser::class,
LinkParser::class,
LinkNameParser::class,
];
Expand Down
56 changes: 56 additions & 0 deletions src/Parser/SrcParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Docdress\Parser;

use Illuminate\Support\Str;

class SrcParser implements HtmlParserInterface
{
/**
* Parse html.
*
* @param string $text
* @return string
*/
public function parse($text)
{
$matches = $this->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[^>]*>(.*?)</code\b[^>]*>#s', $text, $matches);

foreach ($matches[0] as $match) {
$text = str_replace($match, '', $text);
}

preg_match_all('/(?<=\bsrc=")[^"]*/', $text, $matches);

return $matches;
}
}

0 comments on commit 08c06ba

Please sign in to comment.