Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
edgrosvenor authored and github-actions[bot] committed May 25, 2024
1 parent f442aff commit 253ab4c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/Actions/HandleWikiStyleImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ public function convertWikiImagesToHtml($markdown): string
$pattern = '/!\[\[([^\]]+)\]\]/';
preg_match($pattern, $markdown, $matches);



if (isset($matches[1])) {
$image = app(EmbeddedMedia::class)->make($matches[1]);
$markdown = str_replace($matches[0], '<img src="{{ asset(\'' . $image->uri . '\') }}" alt="">', $markdown);
$markdown = str_replace($matches[0], '<img src="{{ asset(\''.$image->uri.'\') }}" alt="">', $markdown);
}

return $markdown;
Expand Down
1 change: 0 additions & 1 deletion src/Actions/HighlightCodeWithTempest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ protected function enableCodeHighlighting(DocumentationLine $line): Documentatio
$this->language = str_replace('language-', '', $matches[1]);
}


if ($this->language === 'live' || $this->language === 'mermaid') {
$this->language = null;
}
Expand Down
10 changes: 6 additions & 4 deletions src/EmbeddedMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
class EmbeddedMedia
{
public string $uri = '';

public string $path = '';

public string $source_path = '';

public bool $exists = false;

public ObsidianConfiguration $obsidian;

public function __construct(public array $config)
Expand All @@ -26,16 +30,15 @@ public function make(string $path)

$this->source_path = implode('/', [
$this->obsidian->attachment_path,
$path
$path,
]);

$this->uri = implode('/', [
str_replace(public_path(), '', rtrim($this->config['media_path'], '/')),
$path,
]);

throw_if(!file_exists($this->source_path), "{$this->source_path} does not exist");

throw_if(! file_exists($this->source_path), "{$this->source_path} does not exist");

$this->exists = file_exists($this->path);

Expand All @@ -45,5 +48,4 @@ public function make(string $path)

return $this;
}

}
12 changes: 6 additions & 6 deletions src/LineTransformers/EmbedRawImageUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EmbedRawImageUrls
{
public function __invoke(string $line, Closure $next): string
{
if (!filter_var(trim(current($chunks = explode(' ', trim(strip_tags($line))))), FILTER_VALIDATE_URL)) {
if (! filter_var(trim(current($chunks = explode(' ', trim(strip_tags($line))))), FILTER_VALIDATE_URL)) {
return $next($line);
}

Expand All @@ -20,12 +20,12 @@ public function __invoke(string $line, Closure $next): string
}

$line = count(array_filter($chunks)) === 1
? '<p><img class="object-contain md:object-scale-down" src="' . current($chunks) . '" alt=""></p>'
? '<p><img class="object-contain md:object-scale-down" src="'.current($chunks).'" alt=""></p>'
: '<p><figure><img class="object-contain md:object-scale-down" src="'
. array_shift($chunks)
. '" alt=""><figcaption>'
. implode(" ", $chunks)
. '</figcaption></figure></p>';
.array_shift($chunks)
.'" alt=""><figcaption>'
.implode(' ', $chunks)
.'</figcaption></figure></p>';

return $next($line);
}
Expand Down
1 change: 0 additions & 1 deletion src/ObsidianConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function __construct(array $configuration)
// Calculate the full path to the Obsidian configuration folder
$configuration_path = data_get($configuration, 'obsidian_config');


$config = [
'app' => json_decode(file_get_contents(implode('/', [$configuration_path, 'app.json'])), true),
'appearance' => json_decode(file_get_contents(implode('/', [$configuration_path, 'appearance.json'])), true),
Expand Down
13 changes: 6 additions & 7 deletions tests/EmbeddedMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use ArtisanBuild\Docsidian\EmbeddedMedia;


it('can get the configuration out of the container', function () {

$embedded_media = app(EmbeddedMedia::class);
Expand All @@ -18,19 +17,19 @@
str_replace(public_path(), '', $this->config['media_path']),
'lighthouse.png',
]))->and($embedded_media->path)->toBe(implode('/', [
$this->config['media_path'],
'lighthouse.png',
]))->and($embedded_media->source_path)->toBe(implode('/', [
$this->config['media_path'],
'lighthouse.png',
]))->and($embedded_media->source_path)->toBe(implode('/', [
$this->config['md_path'],
'lighthouse.png',
]));
});

it('throws if a referenced file does not exist in the md directory', function() {
expect(fn() => app(EmbeddedMedia::class)->make('not-here.png'))->toThrow(RuntimeException::class);
it('throws if a referenced file does not exist in the md directory', function () {
expect(fn () => app(EmbeddedMedia::class)->make('not-here.png'))->toThrow(RuntimeException::class);
});

it('copies from the source to the destination', function() {
it('copies from the source to the destination', function () {
expect(file_exists(implode('/', [$this->config['media_path'], 'lighthouse.png'])))->toBeFalse();
$embedded_media = app(EmbeddedMedia::class)->make('lighthouse.png');
expect(file_exists($embedded_media->path))->toBeTrue();
Expand Down
10 changes: 5 additions & 5 deletions tests/LineTransformers/EmbedRawImageUrlsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use ArtisanBuild\Docsidian\LineTransformers\EmbedRawImageUrls;
use Illuminate\Support\Facades\Pipeline;

it('transforms raw image urls without a caption', function() {
it('transforms raw image urls without a caption', function () {
$line = '<p>https://images.unsplash.com/photo-1715073145727-393bbded41d9?q=80&w=3987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D</p>';
$image = Pipeline::send($line)
->through([
Expand All @@ -13,7 +13,7 @@
expect($image)->toBe('<p><img class="object-contain md:object-scale-down" src="https://images.unsplash.com/photo-1715073145727-393bbded41d9?q=80&w=3987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt=""></p>');
});

it('handles unexpected space before the image', function() {
it('handles unexpected space before the image', function () {
$line = '<p> https://images.unsplash.com/photo-1715073145727-393bbded41d9?q=80&w=3987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D</p>';
$image = Pipeline::send($line)
->through([
Expand All @@ -23,7 +23,7 @@
expect($image)->toBe('<p><img class="object-contain md:object-scale-down" src="https://images.unsplash.com/photo-1715073145727-393bbded41d9?q=80&w=3987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt=""></p>');
});

it('transforms raw image urls with a caption', function() {
it('transforms raw image urls with a caption', function () {
$line = '<p>https://images.unsplash.com/photo-1715073145727-393bbded41d9?q=80&w=3987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D This has a caption</p>';
$image = Pipeline::send($line)
->through([
Expand All @@ -33,7 +33,7 @@
expect($image)->toBe('<p><figure><img class="object-contain md:object-scale-down" src="https://images.unsplash.com/photo-1715073145727-393bbded41d9?q=80&w=3987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt=""><figcaption>This has a caption</figcaption></figure></p>');
});

it('ignores images that are already in HTML tags', function() {
it('ignores images that are already in HTML tags', function () {
$line = '<p><img class="object-contain md:object-scale-down" src="https://images.unsplash.com/photo-1715073145727-393bbded41d9?q=80&w=3987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt=""></p>';

$image = Pipeline::send($line)
Expand All @@ -44,7 +44,7 @@
expect($image)->toBe($line);
});

it('ignores images that are in markdown', function() {
it('ignores images that are in markdown', function () {
$line = '![image](https://images.unsplash.com/photo-1715073145727-393bbded41d9?q=80&w=3987&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D)';

$image = Pipeline::send($line)
Expand Down
8 changes: 4 additions & 4 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
use ArtisanBuild\Docsidian\Tests\TestCase;
use Illuminate\Support\Facades\File;

uses(TestCase::class)->beforeEach(function() {
uses(TestCase::class)->beforeEach(function () {
$this->config = [
'default_visibility' => 'protected',
'folio_middleware' => ['web'],
'folio_path' => resource_path('views/docs/test'),
'folio_uri' => 'docs/test',
'layout' => 'docsidian',
'md_path' => __DIR__ . '/md',
'md_path' => __DIR__.'/md',
'md_repo' => 'artisan-build/docsidian-docs', // Only applies to hosted docs
'media_path' => public_path('vendor/docsidian/test'),
'obsidian_config' => __DIR__ . '/md/.obsidian',
'obsidian_config' => __DIR__.'/md/.obsidian',
];
app()->when(EmbeddedMedia::class)->needs('$config')->give($this->config);
})->afterEach(function() {
})->afterEach(function () {
if (File::isDirectory($this->config['folio_path'])) {
File::deleteDirectory($this->config['folio_path']);
}
Expand Down

0 comments on commit 253ab4c

Please sign in to comment.