Giter Club home page Giter Club logo

laravel-markdown's Issues

No method to escape user-inputted markdown

There's no satisfactory way to escape user-submitted Markdown as it uses the the angle bracket > for a block quote, which is escaped by Laravel into > by default.

Example:

# Title 1

<script src="example.com"></script>

> Blockquote

Escaped:

# Title 1

&lt;script src=&quot;example.com&quot;&gt;&lt;/script&gt;

&gt; Blockquote

The issue here is that the blockquote is no longer recognized as valid Markdown. One solution could be adding an escape function that ignores all right-angle brackets, which would instead convert it to:

# Title 1

&lt;script src=&quot;example.com&quot;>&lt;/script>

> Blockquote

... which then would result in the expected Markdown, with the blockquote intact.

Markdown can't render this {{

I don't why markdown can't render the blade syntax like.

<meta name="description" content="{{ $article->teaser }}">

The result of it be

<meta name="description" content="">

Anyone can answer what's really need to show that ?

markdown doesn't render in a blade section

not sure if this is supported or not, or if it can be supported, but i am trying to render markdown in a blade section such as

file - welcome.md.blade.php

@extends('layouts.default')

@section('content')
    # home
@stop

when the view is rendered, it is plain text. is this by design, or a bug?

line breaks not working

For some reason this happens:
1x -enter-: nothing
2x -enter-: new paragraph

Why isn't 1x enter a line break? Checked CommonMark spec and there it is a linebreak...
Am I overlooking something?
Thanks in advance

BadMethodCallException in ServiceProvider.php

Looks awesome but I am getting the following error after installing the package.

BadMethodCallException in ServiceProvider.php line 140
at ServiceProvider->__call('package', array('graham-campbell/markdown', 'graham-campbell/markdown', 'E:\work\development\backend\vendor\graham-campbell\markdown\src')) in MarkdownServiceProvider.php line 40
at MarkdownServiceProvider->package('graham-campbell/markdown', 'graham-campbell/markdown', 'E:\work\development\backend\vendor\graham-campbell\markdown\src') in MarkdownServiceProvider.php line 40
at MarkdownServiceProvider->boot()
at call_user_func_array(array(object(MarkdownServiceProvider), 'boot'), array()) in Container.php line 523
at Container->call(array(object(MarkdownServiceProvider), 'boot')) in Application.php line 597
at Application->bootProvider(object(MarkdownServiceProvider)) in Application.php line 579
at Application->Illuminate\Foundation\{closure}(object(MarkdownServiceProvider), '19')
at array_walk(array(object(EventServiceProvider), object(RoutingServiceProvider), object(AuthServiceProvider), object(ControllerServiceProvider), object(CookieServiceProvider), object(DatabaseServiceProvider), object(EncryptionServiceProvider), object(FilesystemServiceProvider), object(FormRequestServiceProvider), object(FoundationServiceProvider), object(PaginationServiceProvider), object(SessionServiceProvider), object(ValidationServiceProvider), object(ViewServiceProvider), object(AppServiceProvider), object(BusServiceProvider), object(ConfigServiceProvider), object(EventServiceProvider), object(RouteServiceProvider), object(MarkdownServiceProvider), object(BusServiceProvider)), object(Closure)) in Application.php line 580
at Application->boot() in BootProviders.php line 15
at BootProviders->bootstrap(object(Application)) in Application.php line 151
at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 140
at Kernel->bootstrap() in Kernel.php line 103
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 83
at Kernel->handle(object(Request)) in index.php line 53

Image markdown is not getting compiled

Hi, Thanks for this wonderful package,

I have a problem with images, this is working fine:

! [Image] (imageLink)

but this one isn't working:

! [Image] (imageLink "Image title")

quick question

Hi mate,
Is it possible to call the Markdown fascade directly in a controller to convert or does this package only convert files?
Thanks,
Sam

Quick Question: Trying to extend Laravel-Markdown for Block Rendering

Hi,

I'm quite new on Laravel.

I would like to add another rendering/parsing(not sure which one is the best) for Headers.
So simply, I would like to render # {Testing This Title} this to <h1 id="testing-this-title">Testing This Title</h1> (Using Laravels, str_slug helper)

There are other solutions in order to get id properties for headers. But since I'm trying to learn how to extend a package. If you could show me a starting point with a small code block, i would appreciate.

What I have read before;
https://commonmark.thephpleague.com/customization/block-parsing/
https://commonmark.thephpleague.com/customization/block-rendering/

Since I'm not sure where to add these code blockes, I'm stuck.

PS: I have also seen another Issue post here where you recommended an Emoji package but I could not extract the code I need.

Thanks in advance!

Tev.

Inline UserHandleParser

So I extended this for a UserHandleParser below but it doesn't make the changes.

<?php

namespace App\Extensions\Markdown;

use League\CommonMark\ContextInterface;
use League\CommonMark\Inline\Element\Link;
use League\CommonMark\Inline\Parser\AbstractInlineParser;
use League\CommonMark\InlineParserContext;

class UserHandleParser extends AbstractInlineParser
{
    public function getCharacters() {
        return array('@');
    }

    public function parse(ContextInterface $context, InlineParserContext $inlineContext) {
        $cursor = $inlineContext->getCursor();

        // The @ symbol must not have any other characters immediately prior
        $previousChar = $cursor->peek(-1);
        if ($previousChar !== null && $previousChar !== ' ') {
            // peek() doesn't modify the cursor, so no need to restore state first
            return false;
        }

        // Save the cursor state in case we need to rewind and bail
        $previousState = $cursor->saveState();

        // Advance past the @ symbol to keep parsing simpler
        $cursor->advance();

        // Parse the handle
        $handle = $cursor->match('/^\w+\W\w+/');
        if (empty($handle)) {
            // Regex failed to match; this isn't a valid Twitter handle
            $cursor->restoreState($previousState);

            return false;
        }

        $profileUrl = url('members/' . $handle);

        $inlineContext->getInlines()->add(new Link($profileUrl, '@'.$handle));

        return true;
    }
}

I've bootstrapped the parser into Markdown with a ServiceProvider as seen below.

    $environment = Environment::createCommonMarkEnvironment();
    $environment->addInlineParser( new UserHandleParser() );

But it doesn't parse my text case on render.

Any ideas?

preg_match() expects parameter 2 to be string, array given

Hi,

I recently updated (composer update) to latest 2.0 branch on my Laravel 4.1 project and I have an issue with parsedown-extra.

Error :

ErrorException
preg_match() expects parameter 2 to be string, array given (ParsedownExtra.php line 252)

Markdown syntax with error :

###Hello world
[Link](http://google.com)

Markdown without error (no link) :

###Hello world

My composer :

"graham-campbell/markdown": "~2.0"

In my composer.lock the only difference between my production (working) and my local version (not working) is parsedown version.

Production : 1.4.5
Local : 1.5.0

Temporary fix : set parsedown to version 1.4 in composer.json

Suggestion for improved documentation/readme

I would suggest that the convertToHtml function is mentioned in the readme.md file. I wasn't sure if the function for converting variables was available as only the views method was described.

To make it easier for new users to decide if this is the right package - and ease development I suggest to just mention this - somewhere:

Markdown::convertToHtml($my_markdown)

Thank You

Anchor Tags are ignored

First:
Thanks for this library!

I found a small issue, maybe you can help me out on this.
It seems like anchor-tags are ignored, or am i missing something?

Example:

[Help](#Help)
## <a name="Help"></a>Help

The anchor is missing in the output.

Thanks again
Alex

Table Extension integration

Thanks for this package.

Running into an issue integrating an extension.

I'm looking to use the Webuni table extension with Laravel-Markdown.

I'm adding the following to the extensions array:

Webuni\CommonMark\TableExtension\TableExtension

Which does not cause a hard crash; however, it does not render the tables within the Markdown.

Thoughts??

Strip function?

Any chance we could get a function to strip all markdown too? Useful for excerpts of posts, etc where you don't want the formatting showing.

can't parse markdown table

demo

test.md contents:

# users table

id | name
---|--------
1  | Jim
2  | Lily

routes.php contents:

Route::get('/', function () {
    return view('index');
});

result

GrahamCampbell/Laravel-Markdown can parse "h1", but can't parse "table".

screenshot

2015-11-02 14-11-15

Russian text in markdown

Used in Laravel 4 and worked fine.

Now in Laravel 5 I have some problems. Russian text with <code> renders like:
<li>Из: твоя <code>оя featu</code> ветка</li>

But must render like:

<li>Из: твоя <code>feature</code> ветка </li>

It repeats some symbols.

When in line are only english sybmols - is OK

Disable safe mode temporarily

Setting safe mode to true is good idea for most cases, but sometimes it shouldn't strip HTML tags. I think convertToHTML function could have a second argument which let me disable safe mode temporarily.

Is there a possibility to do so right now?

Request: Ability to add classes to images.

Not sure if it's already implemented, but I can't seem to find it.

Basically, I would want to do something similar to the following

![Image](http://www.example.com/image.png class="img-responsive content-img")

It's not something that needs to be overused, but a few images require 1 attribute (img-responsive) while a few others require that one as well as another.

I know this isn't a true CommonMark implementation, but wondering if I can extend Laravel-Markdown to accomplish this, or perhaps I'm overlooking some easier way to accomplish this.

Thank you for your time.

check UTF-8 with BOM

If md file is encode UTF-8 with BOM, the first line will not be convert. I try fix as

public function get($path, array $data = [])
{
    $bom_content = parent::get($path, $data);
    $contents = str_replace("\xef\xbb\xbf", '', $bom_content);
    return $this->markdown->convertToHtml($contents);
}

But It not working :(

Error when using dependency injection

Getting the following error:

BindingResolutionException in Container.php line 745:
Target [League\CommonMark\ElementRendererInterface] is not instantiable.

Latex support

Does your package support the latex markup? If not, do you plan on adding it in the near future or do you know of any Laravel 5 plugins that offer this in a way that is just as simple to use as yours?

example of use?

Hi, having never used a facade it is not clear how to use your library

an example would be great!

thanks

Nested list hides content

Helle Graham

I'm using version 2.1.0 for Laravel 4.2, and it looks that when I'm using a nested list in my markdown file, all the content below is lost. Do you have any idea?

The weird thing is that I didn't had this problem before, I tried to reverse back to older versions, but that didn't helped either.

E.g.

* test
 * test 2
* test
 * test 2

hello

The result is that the list is shown correctly, but the text hello is missing.

Call to undefined method [package]

The same issue as this one

I'm not sure if Laravel 5 is going to preserve some backward compatibility for this. I've tried to lock my Laravel version at dev-master#846c935194a036901ba6b4397c8897fa51e19111. However, it gives me new errors like "Call to undefined function env()"...

Is it possible for you to remove the following line in @dev for now?

$this->package('graham-campbell/markdown', 'graham-campbell/markdown', __DIR__);

Thanks a lot.

html is visible in browser

Markdown::convertToHtml('Markdown')
is rendered as

Markdown

in the browser

And if i look in the page source in Chrome it is
<p><em>Markdown</em></p>

Custom block parser does not advance to next line

Hello,

I made it to build a few simple extensions that a platform I am building is going to use: a couple of inline extensions for link insertion based on model ids (pages and categories of my small cms, that is); one block extension that builds a fully fledged html/js carousel.

Nothing fancy but it all seems to work pretty well except from the fact that the block extension "eats" up the text after the markers once found.

The current code looks something like this from the Parser perspective:

public function parse(ContextInterface $context, Cursor $cursor)
{
    // Save the cursor state in case we need to rewind and bail
    $previousState = $cursor->saveState();

    // Parse the handle
    $handle = $cursor->match('/(?<=\{carousel:)(.*?)(?=\})/i');

    if (empty($handle)) {
        // Regex failed to match; this isn't a valid carousel marker
        $cursor->restoreState($previousState);
        return false;
    }

    // DO SOME MAGIC TO BUILD THE CAROUSEL DATA FOR THE ELEMENT

    // Advance to the end of the string, consuming the entire line
    $cursor->advance();

    $context->addBlock($carousel_element);
    $context->setBlocksParsed(true);

    return true;
}

Anyone knows what's wrong with this? Is there a different way to properly "advance the cursor to the end of syntax indicating the block start" (as the docs state)?

I really appreciate this package but I feel like it is still missing a few better explained examples or a richer guide on the customizations. I wonder if some might have found/wrote something in this regards.

Thanks a lot!

Table and Raw content

On v7.0.

Using: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#tables

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |
Markdown | Less | Pretty
--- | --- | ---
*Still* | `renders` | **nicely**
1 | 2 | 3

Neither parse down, I just get them wrapped in a <p>

Example:
<p>Markdown | Less | Pretty --- | --- | --- <em>Still</em> | <code>renders</code> | <strong>nicely</strong> 1 | 2 | 3</p>

https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#html
Doesn't appear to work either, and is stripped out.

Also ~~for strikeout~~ doesn't seem to work.

6.1 appears to work for Raw.

Missing first line?

Markdown from my database TEXT field is being parsed successfully but I am getting some weirdness. Here's the markdown and the result. For some reason it's missing out the first headline. Any ideas?

#Hello

So here we go. How about this?

* Some bullets
* Go here

Result

<p>#Hello
So here we go. How about this?</p>
<ul>
<li>Some bullets</li>
<li>Go here</li>
</ul>

GitHub Markdown API

A driver based system so you can use CommonMark or GitHub's Markdown API.

Escape for <canvas> tag

I'm not able to embed a <canvas></canvas> tag within the markdown as it seems to recognize it as text albeit not in quotes like it would normally for other text. I've noticed that when I inspect the elements using Chrome that is not highlighted the same color (purple) as other tags but rather the same coloring as text (black).

<p><canvas id="myChart" width="400" height="200"></canvas></p>

Is it possible to escape from the markdown to input the canvas tag as HTML and to return back to the markdown? I am displaying the markdown in my view.blade.php file as follows:
{!! Markdown::convertToHtml(e($post->body)) !!}

(in this example, body represents the text used for a blog entry)

_UPDATE_
"The issue is that Markdown was created long before the tag (during the HTML 4 and XHTML 1 days) and most Markdown implementations do not include that tag in their list of "block-level HTML elements." - Waylan from Stackoverflow

Not sure where to begin... would this be worth the effort to update the markdown code to have included?

Extending Markdown syntax to add @[somelink](http://somelink.com)?

How can I extend Markdown syntax so that the following code: @[Go to Microsoft](http://www.microsoft.com) converts to a link like this: Go to Microsoft.

This is the exact same as any ordinary Markdown link works, except it has an additional '@' character immediately preceding the first opening bracket.

The reason I want to do this is for an @mention system I'm working on.

I found the issue 24 but it's still not really explained how to do it there.

Disabling/enabling features

Hi,

Is it possible to disable the rendering of certain elements at the moment? My project allows my users to write markdown and I would like to disable the rendering of headings (#) and potentially others.

Cheers

Links break render

If content you want to render contains a link e.g [Example](http://example.com), the following error is thrown:

ERROR: exception 'ErrorException' with message 'preg_match() expects parameter 2 to be string, array given' in /home/ubuntu/laravel-app/vendor/erusev/parsedown-extra/ParsedownExtra.php:228

System:
graham-campbell/markdown - v2.0.7
laravel/framework - v4.2.16

Testing

We need some unit tests...

PHP Requirement?

Why does this package require PHP 5.4.7? From what I can see, PHP 5.4.4 is the current stable version on Debian... and I can't imagine that 5.4.7 has some magic feature required by this package??

Is it possible to have two sets of options?

Currently I have my html_input within the config/markdown.php set to true for my own writing ease, however, is there anyway to override these settings for a specific use case. i.e. So writing blog posts means I can use whatever I want, whereas a user writing a comment would only get certain abilities?

Anything like the following available?

$markdown->options([
    'html_input' => false,
    'allow_unsafe_links' => false
]);

$markdown->convertToHtml($foo);

Composer update/install results in "The requested package graham-campbell/laravel-markdown could not be found"

The error message:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package graham-campbell/markdown could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

I've replicated this on a fresh Laravel project, here are the steps to recreate:

  1. Clone laravel from Github

    git clone https://github.com/laravel/laravel markdown-test
    cd markdown-test/
  2. Ensure that app/storage is writable (often causes issues on my system)

    sudo chmod 777 -R app/storage/
  3. Update require in composer.json to match the following

        "require": {
            "laravel/framework": "4.1.*",
            "graham-campbell/laravel": "*"
        },
  4. Run composer install

Markdown not rendered in include...

So I have the following

index.md.blade.php

@extends('layouts.base')

## This text

@section('body')

@include('bodytext')

@stop

bodytext.md.blade.php

<DIV class="container">
  <div class="row hidden-xs" id="photobox">
    <DIV class="col-xs-3 ">Photo</DIV>
    <DIV class="col-xs-3 ">Photo</DIV>
    <DIV class="col-xs-3 ">Photo</DIV>
    <DIV class="col-xs-3 ">Photo</DIV>
    </DIV>
  <div class="row">

<DIV class="col-sm-9 col-xs-12 smbotmargin" id="announcements" style="margin-bottom:10px">
<DIV id="mainstories" class="" style="border:1px solid rgba(0,0,0,.15);min-height:50px;">
  @foreach ($stories as $story)
    <DIV>
      <h3>{{$story->news_title}}</H3>
        <p>{{$story->news_body}}</p>
      </DIV>
        @endforeach;
      </DIV>
    </DIV>
    <DIV class="col-sm-3 col-xs-12">
      <DIV class="col-xs-6 col-sm-12 smbotmargin">
        <DIV CLASS="mainheadersm topround">CALENDAR</DIV>
      </DIV>
      <DIV class="col-xs-6  col-sm-12 smbotmargin">
        <DIV class="mainheadersm topround">SPONSORS</DIV>
      </DIV>
      <DIV class="col-xs-12 smbotmargin" style="">
          <DIV class="mainheadersm topround">DONATIONS</DIV>
      </DIV>
    </DIV>
  </DIV>
</DIV>

the route which it called is

Route::get('/', ['as'=>'home','uses'=>'IndexController@justShow'] );

calls

  public function justShow(){
        $stories = \AAC\NEWS_OWNERS::orderBy('start_date','desc')->get();
        return View::make('index',array('stories'=>$stories));
    }

The markdown on the index.md.blade.php is rendered correctly...

<h2>This text</h2>

but the markdown returned in the bodytext.md.blade.php is not translated.

***test body*** 
 this one kasdlkasdflkjl 
 this this again 
 and another line another line lskdfj and more and more

the above is an example of the markdown returned from the database and not translated.

Parse Markdown before parsing blade syntax?

In BladeMarkdownEngine::get() the code is as follow:

public function get($path, array $data = [])
{
    $contents = parent::get($path, $data);

    return $this->markdown->convertToHtml($contents);
}

My .md.blade.php contains @extends('layouts.default'). This means that parent::get() has already parsed my blade template and puts loads of HTML into $contents.

When convertToHtml(), which supposed to get only Markdown syntax, gets the fully parsed HTML above, it goes crazy and hence lots of <pre><code> produced.

Is it possible to specify that markdown content in .md.blade.php should be parsed before parsing the rest of blade syntax in that file? If it's not already supported would you welcome a PR that allows that?

Make Parsedown options available

For safety reasons, it should be possible to disallow scripts and other HTML elements. See the discussion at erusev/parsedown#224.

$parsedown->setMarkupEscaped(true);

This is currently not available though this Laravel wrapper around Parsedown.

Extensions

Hey,

is there an easy way to add extensions to this using the addInlineParser method? Maybe this could somehow be done using the published config?

Update title

image

Hi, i want to use Parsedown wrapper for Laravel 5

Is this a Parsedown wrapper or League\Commonmark as its stated in the Readme?

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.