diff --git a/app/Models/Artwork.php b/app/Models/Artwork.php index 03d5b62..2872ec3 100644 --- a/app/Models/Artwork.php +++ b/app/Models/Artwork.php @@ -268,7 +268,7 @@ public function descriptionHtml(): Attribute return Attribute::get( fn() => Str::of($this->description) ->replace("\n", "\n\n") - ->markdown(), + ->airtableMarkdown(), ); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3bd8b9e..bf1942d 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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 { @@ -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); + }); } }