Skip to content

Commit

Permalink
Fix airtable flavored markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
rastislav-chynoransky committed Jul 9, 2024
1 parent ba5f532 commit ebadd2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Models/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function descriptionHtml(): Attribute
return Attribute::get(
fn() => Str::of($this->description)
->replace("\n", "\n\n")
->markdown(),
->airtableMarkdown(),
);
}

Expand Down
14 changes: 14 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use App\Http\Resources\ArtworkMapPointCollection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -30,5 +32,17 @@ public function boot()
}

ArtworkMapPointCollection::withoutWrapping();

Str::macro('airtableMarkdown', function ($value) {
return Str::of($value)
->replaceMatches('/\*\*(\s*)(.*?)(\s*)\*\*/', '$1**$2**$3')
->replaceMatches('/_(\s*)(.*?)(\s*)_/', '$1_$2_$3')
->replaceMatches('/~~(\s*)(.*?)(\s*)~~/', '$1~~$2~~$3')
->markdown();
});

Stringable::macro('airtableMarkdown', function () {
return Str::airtableMarkdown($this->value);
});
}
}

0 comments on commit ebadd2b

Please sign in to comment.