Merge pull request #13288 from snipe/fixes/line_based_markdown

Added Inline markdown method
This commit is contained in:
snipe 2023-07-13 13:16:50 +01:00 committed by GitHub
commit 5aa99a15d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 29 additions and 18 deletions

View file

@ -33,6 +33,16 @@ class Helper
} }
} }
public static function parseEscapedMarkedownInline($str = null)
{
$Parsedown = new \Parsedown();
$Parsedown->setSafeMode(true);
if ($str) {
return $Parsedown->line($str);
}
}
/** /**
* The importer has formatted number strings since v3, * The importer has formatted number strings since v3,
* so the value might be a string, or an integer. * so the value might be a string, or an integer.

View file

@ -32,7 +32,7 @@ class AccessoriesTransformer
'model_number' => ($accessory->model_number) ? e($accessory->model_number) : null, 'model_number' => ($accessory->model_number) ? e($accessory->model_number) : null,
'category' => ($accessory->category) ? ['id' => $accessory->category->id, 'name'=> e($accessory->category->name)] : null, 'category' => ($accessory->category) ? ['id' => $accessory->category->id, 'name'=> e($accessory->category->name)] : null,
'location' => ($accessory->location) ? ['id' => $accessory->location->id, 'name'=> e($accessory->location->name)] : null, 'location' => ($accessory->location) ? ['id' => $accessory->location->id, 'name'=> e($accessory->location->name)] : null,
'notes' => ($accessory->notes) ? Helper::parseEscapedMarkedown($accessory->notes) : null, 'notes' => ($accessory->notes) ? Helper::parseEscapedMarkedownInline($accessory->notes) : null,
'qty' => ($accessory->qty) ? (int) $accessory->qty : null, 'qty' => ($accessory->qty) ? (int) $accessory->qty : null,
'purchase_date' => ($accessory->purchase_date) ? Helper::getFormattedDateObject($accessory->purchase_date, 'date') : null, 'purchase_date' => ($accessory->purchase_date) ? Helper::getFormattedDateObject($accessory->purchase_date, 'date') : null,
'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost), 'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost),

View file

@ -110,7 +110,7 @@ class ActionlogsTransformer
'type' => e($actionlog->targetType()), 'type' => e($actionlog->targetType()),
] : null, ] : null,
'note' => ($actionlog->note) ? Helper::parseEscapedMarkedown($actionlog->note): null, 'note' => ($actionlog->note) ? Helper::parseEscapedMarkedownInline($actionlog->note): null,
'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null, 'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null,
'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null, 'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null,
'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'), 'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),

View file

@ -49,7 +49,7 @@ class AssetMaintenancesTransformer
'id' => (int) $assetmaintenance->asset->defaultLoc->id, 'id' => (int) $assetmaintenance->asset->defaultLoc->id,
'name'=> e($assetmaintenance->asset->defaultLoc->name), 'name'=> e($assetmaintenance->asset->defaultLoc->name),
] : null, ] : null,
'notes' => ($assetmaintenance->notes) ? Helper::parseEscapedMarkedown($assetmaintenance->notes) : null, 'notes' => ($assetmaintenance->notes) ? Helper::parseEscapedMarkedownInline($assetmaintenance->notes) : null,
'supplier' => ($assetmaintenance->supplier) ? ['id' => $assetmaintenance->supplier->id, 'name'=> e($assetmaintenance->supplier->name)] : null, 'supplier' => ($assetmaintenance->supplier) ? ['id' => $assetmaintenance->supplier->id, 'name'=> e($assetmaintenance->supplier->name)] : null,
'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost), 'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost),
'asset_maintenance_type' => e($assetmaintenance->asset_maintenance_type), 'asset_maintenance_type' => e($assetmaintenance->asset_maintenance_type),

View file

@ -63,7 +63,7 @@ class AssetModelsTransformer
'default_fieldset_values' => $default_field_values, 'default_fieldset_values' => $default_field_values,
'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol.' months' : 'None', 'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol.' months' : 'None',
'requestable' => ($assetmodel->requestable == '1') ? true : false, 'requestable' => ($assetmodel->requestable == '1') ? true : false,
'notes' => Helper::parseEscapedMarkedown($assetmodel->notes), 'notes' => Helper::parseEscapedMarkedownInline($assetmodel->notes),
'created_at' => Helper::getFormattedDateObject($assetmodel->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($assetmodel->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($assetmodel->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($assetmodel->updated_at, 'datetime'),
'deleted_at' => Helper::getFormattedDateObject($assetmodel->deleted_at, 'datetime'), 'deleted_at' => Helper::getFormattedDateObject($assetmodel->deleted_at, 'datetime'),

View file

@ -58,7 +58,7 @@ class AssetsTransformer
'id' => (int) $asset->supplier->id, 'id' => (int) $asset->supplier->id,
'name'=> e($asset->supplier->name), 'name'=> e($asset->supplier->name),
] : null, ] : null,
'notes' => ($asset->notes) ? Helper::parseEscapedMarkedown($asset->notes) : null, 'notes' => ($asset->notes) ? Helper::parseEscapedMarkedownInline($asset->notes) : null,
'order_number' => ($asset->order_number) ? e($asset->order_number) : null, 'order_number' => ($asset->order_number) ? e($asset->order_number) : null,
'company' => ($asset->company) ? [ 'company' => ($asset->company) ? [
'id' => (int) $asset->company->id, 'id' => (int) $asset->company->id,

View file

@ -46,7 +46,7 @@ class ComponentsTransformer
'id' => (int) $component->company->id, 'id' => (int) $component->company->id,
'name' => e($component->company->name), 'name' => e($component->company->name),
] : null, ] : null,
'notes' => ($component->notes) ? Helper::parseEscapedMarkedown($component->notes) : null, 'notes' => ($component->notes) ? Helper::parseEscapedMarkedownInline($component->notes) : null,
'created_at' => Helper::getFormattedDateObject($component->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($component->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($component->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($component->updated_at, 'datetime'),
'user_can_checkout' => ($component->numRemaining() > 0) ? 1 : 0, 'user_can_checkout' => ($component->numRemaining() > 0) ? 1 : 0,

View file

@ -39,7 +39,7 @@ class ConsumablesTransformer
'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost), 'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost),
'purchase_date' => Helper::getFormattedDateObject($consumable->purchase_date, 'date'), 'purchase_date' => Helper::getFormattedDateObject($consumable->purchase_date, 'date'),
'qty' => (int) $consumable->qty, 'qty' => (int) $consumable->qty,
'notes' => ($consumable->notes) ? Helper::parseEscapedMarkedown($consumable->notes) : null, 'notes' => ($consumable->notes) ? Helper::parseEscapedMarkedownInline($consumable->notes) : null,
'created_at' => Helper::getFormattedDateObject($consumable->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($consumable->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($consumable->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($consumable->updated_at, 'datetime'),
]; ];

View file

@ -34,7 +34,7 @@ class LicensesTransformer
'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null, 'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost), 'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost),
'purchase_cost_numeric' => $license->purchase_cost, 'purchase_cost_numeric' => $license->purchase_cost,
'notes' => Helper::parseEscapedMarkedown($license->notes), 'notes' => Helper::parseEscapedMarkedownInline($license->notes),
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'), 'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
'seats' => (int) $license->seats, 'seats' => (int) $license->seats,
'free_seats_count' => (int) $license->free_seats_count, 'free_seats_count' => (int) $license->free_seats_count,

View file

@ -43,7 +43,7 @@ class SuppliersTransformer
'licenses_count' => (int) $supplier->licenses_count, 'licenses_count' => (int) $supplier->licenses_count,
'consumables_count' => (int) $supplier->consumables_count, 'consumables_count' => (int) $supplier->consumables_count,
'components_count' => (int) $supplier->components_count, 'components_count' => (int) $supplier->components_count,
'notes' => ($supplier->notes) ? Helper::parseEscapedMarkedown($supplier->notes) : null, 'notes' => ($supplier->notes) ? Helper::parseEscapedMarkedownInline($supplier->notes) : null,
'created_at' => Helper::getFormattedDateObject($supplier->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($supplier->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($supplier->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($supplier->updated_at, 'datetime'),

View file

@ -53,7 +53,7 @@ class UsersTransformer
'id' => (int) $user->userloc->id, 'id' => (int) $user->userloc->id,
'name'=> e($user->userloc->name), 'name'=> e($user->userloc->name),
] : null, ] : null,
'notes'=> Helper::parseEscapedMarkedown($user->notes), 'notes'=> Helper::parseEscapedMarkedownInline($user->notes),
'permissions' => $user->decodePermissions(), 'permissions' => $user->decodePermissions(),
'activated' => ($user->activated == '1') ? true : false, 'activated' => ($user->activated == '1') ? true : false,
'autoassign_licenses' => ($user->autoassign_licenses == '1') ? true : false, 'autoassign_licenses' => ($user->autoassign_licenses == '1') ? true : false,

View file

@ -123,6 +123,7 @@ class AssetModelPresenter extends Presenter
'switchable' => true, 'switchable' => true,
'title' => trans('general.notes'), 'title' => trans('general.notes'),
'visible' => false, 'visible' => false,
'formatter' => 'notesFormatter',
], ],
[ [
'field' => 'created_at', 'field' => 'created_at',

View file

@ -287,7 +287,7 @@
</strong> </strong>
</div> </div>
<div class="col-md-9"> <div class="col-md-9">
{!! nl2br(e($accessory->notes)) !!} {!! nl2br(Helper::parseEscapedMarkedownInline($accessory->notes)) !!}
</div> </div>
</div> </div>

View file

@ -93,7 +93,7 @@ use Carbon\Carbon;
<div class="row"> <div class="row">
<div class="col-md-12 col-sm-12" style="padding-bottom: 10px; margin-left: 15px; word-wrap: break-word;"> <div class="col-md-12 col-sm-12" style="padding-bottom: 10px; margin-left: 15px; word-wrap: break-word;">
<strong>{{ trans('admin/asset_maintenances/form.notes') }}: </strong> <strong>{{ trans('admin/asset_maintenances/form.notes') }}: </strong>
{{ $assetMaintenance->notes }} {!! nl2br(Helper::parseEscapedMarkedownInline($assetMaintenance->notes)) !!}
</div> </div>
</div> </div>
<!-- 5th Row End --> <!-- 5th Row End -->

View file

@ -155,7 +155,7 @@
<td> <td>
@if ($file->note) @if ($file->note)
{{ $file->note }} {!! nl2br(Helper::parseEscapedMarkedownInline($file->note)) !!}
@endif @endif
</td> </td>
<td> <td>
@ -275,7 +275,7 @@
</strong> </strong>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
{!! nl2br(e($consumable->notes)) !!} {!! nl2br(Helper::parseEscapedMarkedownInline($consumable->notes)) !!}
</div> </div>
</div> </div>
@endif @endif

View file

@ -730,7 +730,7 @@
</strong> </strong>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
{!! nl2br(e($asset->notes)) !!} {!! nl2br(Helper::parseEscapedMarkedownInline($asset->notes)) !!}
</div> </div>
</div> </div>

View file

@ -357,7 +357,7 @@
</strong> </strong>
</div> </div>
<div class="col-md-9"> <div class="col-md-9">
{!! nl2br(e($license->notes)) !!} {!! nl2br(Helper::parseEscapedMarkedownInline($license->notes)) !!}
</div> </div>
</div> </div>
@endif @endif

View file

@ -338,7 +338,7 @@
@endif @endif
@if ($supplier->notes!='') @if ($supplier->notes!='')
<li><i class="fa fa-comment"></i> {{ $supplier->notes }}</li> <li><i class="fa fa-comment"></i> {!! nl2br(Helper::parseEscapedMarkedownInline($supplier->notes)) !!}</li>
@endif @endif
</ul> </ul>

View file

@ -633,7 +633,7 @@
{{ trans('admin/users/table.notes') }} {{ trans('admin/users/table.notes') }}
</div> </div>
<div class="col-md-9"> <div class="col-md-9">
{{ $user->notes }} {!! nl2br(Helper::parseEscapedMarkedownInline($user->notes)) !!}
</div> </div>
</div> </div>