Better implementation of markdown.

Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
James Cole 2016-10-22 11:50:33 +02:00
parent 8c675615df
commit 0d87f7c4ca
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 15 additions and 8 deletions

View File

@ -17,13 +17,11 @@ use Carbon\Carbon;
use ExpandedForm; use ExpandedForm;
use FireflyIII\Http\Requests\PiggyBankFormRequest; use FireflyIII\Http\Requests\PiggyBankFormRequest;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Note;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Input; use Input;
use League\CommonMark\CommonMarkConverter;
use Log; use Log;
use Preferences; use Preferences;
use Session; use Session;
@ -349,11 +347,7 @@ class PiggyBankController extends Controller
*/ */
public function show(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank) public function show(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
{ {
/** @var Note $note */
$note = $piggyBank->notes()->first(); $note = $piggyBank->notes()->first();
$converter = new CommonMarkConverter;
$note->text = $converter->convertToHtml($note->text);
$events = $repository->getEvents($piggyBank); $events = $repository->getEvents($piggyBank);
$subTitle = e($piggyBank->name); $subTitle = e($piggyBank->name);

View File

@ -14,6 +14,7 @@ declare(strict_types = 1);
namespace FireflyIII\Models; namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use League\CommonMark\CommonMarkConverter;
/** /**
@ -43,6 +44,18 @@ class Note extends Model
protected $dates = ['created_at', 'updated_at', 'deleted_at']; protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable = ['title', 'text']; protected $fillable = ['title', 'text'];
/**
* @param $value
*
* @return string
*/
public function getMarkdownAttribute(): string
{
$converter = new CommonMarkConverter;
return $converter->convertToHtml($this->text);
}
/** /**
* Get all of the owning noteable models. Currently only piggy bank * Get all of the owning noteable models. Currently only piggy bank
*/ */

View File

@ -92,7 +92,7 @@
<h3 class="box-title">{{ trans('form.notes') }}</h3> <h3 class="box-title">{{ trans('form.notes') }}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
{{ note.text|raw }} {{ note.markdown|raw }}
</div> </div>
</div> </div>