Code Monkey home page Code Monkey logo

laravel's Introduction

You might also like Caret - our Markdown editor for Mac / Windows / Linux.

Parsedown for Laravel

Build Status

This package is a Laravel wrapper around Parsedown. If you want to know more about Parsedown alone check out our base repository.

Features

  • Blade Directive
  • Configuration File
  • Helper Function

Installation

Parsedown for Laravel is available as a Composer package. You can install it using the command below:

composer require parsedown/laravel

Configuration

If you're using Laravel +5.5 you don't need to follow the steps below. The package auto-discovery feature has been implemented and will take care of loading the service provider for you.

But if that's not your case you will need to add the service provider to your config/app.php file:

return [
    // Other configurations above...

    'providers' => [
        // Other providers above...
        Parsedown\Providers\ParsedownServiceProvider::class,
        // Other providers below...
    ],

    // Other configurations below...
];

This package uses the Parsedown\Providers\ParsedownServiceProvider service provider to create a singleton of Parsedown. That's stored it in a container called parsedown. It uses the following options to set the default behavior for that instance:

Name Description Default
breaks_enabled Converts line breaks such as \n into <br /> tags. false
inline Enables inline parsing for the parsedown() helper and the @parsedown directive by default. false
markup_escaped Escapes HTML in trusted input. Redundant if safe_mode is enabled. false
safe_mode Doesn't process untrusted user-input. true
urls_linked Automatically converts URLs into anchor tags. true

You can overwrite these values by publishing the config/parsedown.php file with the following command:

php artisan vendor:publish --provider="Parsedown\Providers\ParsedownServiceProvider"

Usage

The snippets below show how you can easily use Parsedown in your *.blade.php files:

@parsedown('Hello _Parsedown_!')

...or (using the helper approach)

{{ parsedown('Hello _Parsedown_!') }}

Any of the code above will generate:

<p>Hello <em>Parsedown</em>!</p>

If you want to parse a value using the inline style you just need to set the second argument as true:

@parsedown('Hello _Parsedown_!', true)

...or (using the helper approach)

{{ parsedown('Hello _Parsedown_!', true) }}

Any of the code above will generate:

Hello <em>Parsedown</em>!

The helper is globally available and can also be used with PHP code throughout your project.

Lumen Support

Laravel and Lumen pretty much share the same core code. The instructions below should be enough to set this package for your Lumen project.

Enable Facades in Your Project

Ensure you have the following in your bootstrap/app.php file:

$app->withFacades();

Service Provider Registering

As Lumen does not support package auto-discovery you got to do it manually adding the code below in your bootstrap/app.php file:

$app->register(Parsedown\Providers\ParsedownServiceProvider::class);

laravel's People

Contributors

eagostini avatar osbre avatar por avatar wmather avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel's Issues

Integrating with ParsedownExtra

Hiyo!

I was curious on how one would get this to work with ParsedownExtra? Prior to moving my site over to Laravel I used ParsedownExtra as I could add a CSS class to my images - {.img-fluid} but as this isn't possible with this package I now just have that text rendering as normal on my site and big/non-responsive images 😝

Screen Shot 2022-02-27 at 19 02 46PM

Thanks!

Parse a block of markdown

Would it be possbile to use the blade directive like this?

@parsedown
# How to setup you account
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Numquam obcaecati
atque adipisci ex ipsa eius odit. Amet illo possimus eius officiis quaerat
modi beatae, nemo ea deserunt minus a culpa.

## Checklist
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
- Aliquam nec nulla non lorem hendrerit pulvinar vel non justo.
- Pellentesque in ligula porta nibh auctor tristique.
@endparsedown

For now I've solved it by using a blade component but I guess it would be nice to have this functionality built in.

components/parsedown.blade.php:

@parsedown($slot)

Usage:

<x-parsedown>
(markdown content)
</x-parsedown>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.