Code Monkey home page Code Monkey logo

parsedown-extra's Introduction

parsedown-extra's People

Contributors

aidantwoods avatar drjdr avatar erusev avatar grahamcampbell avatar luketowers avatar nwtn avatar phrozenbyte avatar storeman avatar tiogatours 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  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

parsedown-extra's Issues

HTML on one line renders incorrectly

If you have HTML on a single line, only the first will render.

See this screenshot of the behavior from the demo.

Only happens in Parsedown Extra. Regular Parsedown is fine.

Line breaks, multiple paragraphs inside footnotes

This snippet from the documentation:

[^1]:
    And that's the footnote.

    That's the second paragraph.

Doesn't render a footnote.

<p>[^1]:</p>
<pre><code>And that's the footnote.

That's the second paragraph.</code></pre>

processTag failed for javascript

input:

<script>
alert(1);
</script>

expected result:

<script>
alert(1);
</script>

actual result(error):

DOMDocument::saveHTML() expects exactly 0 parameters, 1 given(2)
File: /ParsedownExtra.php:492
DOMDocument::saveHTML() expects exactly 0 parameters, 1 given(2)
File: /ParsedownExtra.php:508

Footnotes incorrectly numbered?

Something seems off with the ParsedownExtra footnotes – code below copied straight from the parsed html on your demo page (http://parsedown.org/demo?extra=1). The sup and enclosed a tag are numbered 1 – the corresposnding footnote li and a tag are numbered 0. They don't link up. Any ideas on correcting this? Thanks

<p>This is an interactive demo of Parsedown Extra <sup id="fnref1:1"><a href="#fn:1" class="footnote-ref">1</a></sup>.</p>  

<div class="footnotes"><hr /><ol><li id="fn:0"><p>Parsedown Extra is an extension of Parsedown. <a href="#fnref1:0" rev="footnote" class="footnote-backref">↩</a></p></li></ol></div>

Broken paragraphs/links within markdown="1" divs

A user just sent me a broken example of a div with a markdown="1" attribute, which is a bit weird. When you try it in the demo you can see the difference.

<div class="someclass" markdown="1">

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 

It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. <a href="https://www.facebook.com/therollingchef.aponte">It was popularised</a> in the 1960s with the release of <a href="http://google.com">Letraset</a> sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

</div>

Support for [TOC]?

I am using DOMDocument to fetch the h1 and h2 tag tree (not a good method I think) to make a tree for my app. Would be awesome if it gets implemented 😄

HTML entities not working

HTML entities like &raquo; are not working. Instead, I get the following error: "DOMDocument::loadXML(): Entity 'raquo' not defined in Entity".

Period at end of abbreviations

(I'll have a PR for this momentarily, but I wanted to document the issue.)

If you have a period at the end of an abbreviation definition, the abbreviation is not replaced in the text. E.g.

Ph.D.

*[Ph.D.]: Doctor of Philosophy

…will produce <p>Ph.D.</p>, not <p><abbr title="Doctor of Philosophy">Ph.D.</abbr></p>.

screen shot 2015-02-24 at 11 31 36 am

Omitting the period from the abbreviation definition works, but then the final period in the text is not wrapped in the abbr element:

Ph.D.

*[Ph.D]: Doctor of Philosophy

…will produce <p><abbr title="Doctor of Philosophy">Ph.D</abbr>.</p>.

screen shot 2015-02-24 at 11 31 51 am

Server crash on long image url

I've got quite an issue with parsedown. It was a lot of digging, because php crashed and on it's way down it took apache with him. Anyway, I don't know what is happening exactly, but when I'm parsing the example below with parsedown, it just crashes the server. If a remove any line, it is working correctly. The length of the url seems to be the problem. I can create a workaround for this, but I think this is worth mentioning here.

require '../../../vendor/autoload.php';

$str = '![alt](64esabbase64eyppbWc6Y3JvcEZpdCg1MDAsMjYwKTpzaXplcygnKG1heC13aWR'
        . '0aDogNzY4cHgpIDI1dncnLCAnKG1pbi13aWR0aDogMTAwMHB4KSAyMjVweCcsICcxNjBw'
        . 'eCcpOnNyY1NldCgnMTIwLDAnLCAnMTg1LDAnLCAnMjI1LDAnKTpsaWdodGJveChyb3V0'
        . 'ZS01MTUpKn0=64esabbase64/img/diversen/klantfotos/2014-klantenfotos/f'
        . 'acebook-overig/brandenburg-sabine-horseshoe-bend.JPG \'Page, Horsesho'
        . 'e Bend foto Sabine Brandenburg\')';

$parser = new \Parsedown();
$content = $parser->text($str);

Fenced Code Blocks with classes and ID's do not work

Hi,

https://michelf.ca/projects/php-markdown/extra/#fenced-code-blocks

I noticed this small issue with fenced code blocks:

The following:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.html #example-1}
<p>paragraph <b>emphasis</b>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Should parse into:

<pre><code id="example-1" class="html">&lt;p&gt;paragraph &lt;b&gt;emphasis&lt;/b&gt;
</code></pre>

but actually gives:

<p><del>~</del><del>~</del><del>~</del><del>~</del><del>~</del>~~~ {.html #example-1}</p>
<p>paragraph <b>emphasis</b>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>

This would be incredibly useful for syntax highlighting amongst other stuff.

Thanks!

Footnote name problem

I've using footnote like example

Here[^a]

[^a]: just for test

like that but seems there's a problem with naming when rendering [^a]: just for test.
footnote name become int 0? why?

<sup id="fnref1:a"><a href="#fn:a" class="footnote-ref">1</a></sup>

<div class="footnotes">
<hr>
<ol>
<li id="fn:0">
<p>here for more detail&nbsp;<a href="#fnref1:0" rev="footnote" class="footnote-backref">↩</a></p>
</li>
</ol>
</div>

Change to the protected method parseAttributes

Sorry my bad english.
Change to the protected method parseAttributes and $attributesPattern, to be able to inherit a class and their use.

class MyParsedown extends ParsedownExtra
{
    function __construct()
    {
        parent::__construct();
    }

    protected function buildParagraph($Line)
    {
        $Block = parent::buildParagraph($Line);

        if (preg_match('/^'.$this->attributesPattern.'[ ]?/', $Block['element']['text'], $matches, PREG_OFFSET_CAPTURE))
        {
            $attributeString = $matches[1][0];

            $Block['element']['attributes'] = $this->parseAttributes($attributeString);

            $Block['element']['text'] = substr($Block['element']['text'], strlen($matches[0][0]));
        }

        return $Block;
    }
} 

{.red} Text text text

<p class="red">Text text text</p>

fix footnote backlink

patch

            foreach ($numbers as $number)
            {
                $backLinkText = ' <a href="#fnref' ...;
            }

to

                $backLinkText .= ' <a href="#fnref' ...;

Placeholder causes unexpected behaviour

If you have form elements with placeholder attributes, ParsedownExtra destroys these because it uses the 'placeholder' string itself.

I suggest using a more random string so this won't confict valid html.

UL/OL loop in parsedownextra

Hi, I had originally posted this to the Kirby CMS github repo, but realize it is probably more appropriately placed here:

If a

contains more than 10 UL or OL elements, the 2nd element ("1" in an array) is duplicated from UL/OL11-20, the 3rd is duplicated for UL/OL 21-30, etc.

I believe I've narrowed it down to this passage from parsedownextra:

    foreach ($DOMDocument->documentElement->childNodes as $Node)
    {
        if ($Node instanceof DOMText)
        {
            $texts [] = $this->text($Node->nodeValue);

            # replaces the text of the node with a placeholder
            $Node->nodeValue = '\x1A'.$index ++;
        }
    }

    $markup = $DOMDocument->saveXML($DOMDocument->documentElement);

    foreach ($texts as $index => $text)
    {
        $markup = str_replace('\x1A'.$index, $text, $markup);
    }

    $Block['element'] = $markup;

And when I dump $index I'm seeing \x1A0 through \x1A9, but then just the numbers 0, 1, 2, etc. afterward. Those numbers also show up on the page following the UL/OL element. I really wanted to figure it out, and it must be staring me in the face, but I didn't quite get there, sorry.

Anyway, I don't have a live page at the moment, but you can reproduce with this block:

- You should never - See me again

break

- You should never - See me again

break

- test - test

break

- test - test

break

- test - test

break

- test - test

break

- test - test

break

- test - test

break

- test - test

break

- test - test

break

- test - test

break

- test - test

break

- test - test

break

- test - test

Placeholder attribute is being removed

When you have some inline html in your Markdown like:

<div><input placeholder="test"></div>

…the word "placeholder" gets removed and leaves a broken attribute.

Recent changes to parsedown have broken parsedown-extra

You're probably aware of this, but I was trying to use parsedown/parsedown extra in a project today and the recent changes to the method names in parsedown (e.g. identify to block, Span to Inline) haven't been reflected in parsedown-extra so it doesn't work with the current version of parsedown.

Suggestion: Text alignment

Hello,
I would like know if there's been any consideration given to including syntax for text alignment. Such as making text centre (or justify, or right align)? My own interest is in centring. It can be down with some inline CSS, but in my opinion it would be great to see it implemented in parsedown. In the "Discount" variant of Markdown (found here), this is implemented with the following syntax:

-> Centred text <-

Thank you for your consideration.

classes on images no longer working with 0.3.0+

I can't get the markdown extra syntax for extra classes to work any longer:

![](https://octodex.github.com/images/gracehoppertocat.jpg) {.github}

Results in:

<img src="https://octodex.github.com/images/gracehoppertocat.jpg" alt="">

Class is missing. This was working prior to the refactor of parsedown from 1.1.4 to 1.2.0 and the associated changes in parsedown-extra. I just is no longer available in the $excerpt.

Prevent some tag html

on parse down, is there any easy way to prevent some tag being parsed like <script> or <form>?

Add Markdown Inside HTML Blocks like Markdown Extra

Would be really helpful for Parsedown Extra to add Markdown Inside HTML Blocks

Previously in Markdown, you couldn’t wrap Markdown-formatted content inside a <div> element. This is because <div> is a block element and plain Markdown does not format the content of such.

Markdown Extra gives you a way to put Markdown-formatted text inside any block-level tag. You do this by adding a markdown attribute to the tag with the value 1 — which gives markdown="1" — like this:

<div markdown="1">
This is *true* markdown text.
</div>

The markdown="1" attribute will be stripped and <div>’s content will be converted from Markdown to HTML. The end result will look like this:

<div>
<p>This is <em>true</em> markdown text.</p>
</div>

https://michelf.ca/projects/php-markdown/extra/#markdown-attr

Escape chars abbreviations

Including certain chars, such as a /, in abbreviations will trigger an error in preg_replace(). E.g.:

FBI

OB/GYN

*[FBI]: Federal Bureau of Investigation
*[OB/GYN]: Obstetrics and gynaecology

…will break, with PHP Warning: preg_replace(): Unknown modifier 'G' in ….

screen shot 2015-02-23 at 12 18 57 pm

The Mark tag

I was reading an article on a site that used the mark tag a lot. Then I happened to see some markdown parser that supported it via ==marked up text==.

This is an ==interactive== demo of Parsedown.

This would parse out to this:

<p>This is an <mark>interactive</mark> demo of Parsedown.</p>

From the HTMLDoctor site:

Previously, you may have used em and strong for adding emphasis or importance, respectively, to portions of text. mark differs from these two as it is used purely for highlighting the relevance of a piece of text to the user and/or page’s content. In the past you may have used em and strong for this purpose, which was arguably valid at the time due to the lack of a better element, but the introduction of mark simply means their use will be more strict.

Use strong when you need to indicate the importance of a piece of text, such as an error or warning message, and em should be for adding emphasis to text, stressing words to adapt the meaning of a sentence.

I know that Markdown extra doesnt support this. But I can see it being quite useful for some sites that are writing proper articles as opposed to posts about their cat and the sandwhich they had that morning.

Any thoughts?

suggestion: figure with caption

Hi Emanuil,

I was recently inserting a CC image to one of my posts using Parsedown Extra to be displayed and I realized I cannot use it for HTML5 figure to add caption properly.

I came across Markdown Extra Extended and it's figure solution and I was wondering how to add this to Parsedown.

To be honest the code structure of Parsedown is extremely unfamiliar for me, and I will try to add this myself, but I have a feeling it would take much less time for you.

paragraph inside html not working

When embedding markdown inside a <div markdown="1"> paragraphed text doesn't work.

Instead of <p></p>, we'll have a <br /> when a new-line is entered.

Unique Footnote anchors

As I am using Parsedown-extra many times in a same page, the anchors target not only the concerned item. E.g:

`
Item 1

fn:1

fnref1:1

Item 2

fn:1

fnref1:1

`

As you can the see, this always refer to a same item footnote (the first one). So is it possible to generate an unique id for footnotes ?

Special chars ignored in abbreviations

Some characters get ignored in abbreviations.

Input:

*[µg]: micrograms
*[g]: grams

* µg
* g

Expected output (and output from PHP Markdown Extra):

<ul>
<li><abbr title="micrograms">µg</abbr></li>
<li><abbr title="grams">g</abbr></li>
</ul>

Actual output:

<ul>
<li>µ<abbr title="grams">g</abbr></li>
<li><abbr title="grams">g</abbr></li>
</ul>

screen shot 2015-03-26 at 1 04 01 pm

iframes within divs

I've found a bug!

When trying to display an iframe within a div like so:

<div markdown="1">

<iframe src="http://example.com"></iframe>

**Some sort of markdown formatting**

</div>

Parsedown-extra seems to convert this into:

<div><iframe src="http://example.com"/>

**Some sort of markdown formatting**</div>

eliminating the ending </iframe> and causing both the iframe and the markdown below it to not display.

attribute

Nice to see id and class attribue for header.
But Markdown Extra also provide the ability to add any attribue as ## The Site ## {lang=en}or any other we wish and also combinaison ## The Site ## {.principal .eclat #le-site lang=en}.
It would be nice to have the same feature set in Parsedown extra than in Markdown Extra.

HTML entities confuse the parser

<div markdown="1">A text with any html entity &mdash;</div>

Expected output:

<div markdown="1"><p>A text with any html entity &mdash;</p></div>

Actual output is same as source:

<div markdown="1">A text with any html entity &mdash;</div>

Using an actual symbol instead of its entity (e.g. instead of &mdash;) produces paragraphs inside markdown="1" blocks as expected.

array_unshift() expects parameter 1 to be array, null given

Hey,

Just made today composer update and we get the following error:

PHP Warning:  array_unshift() expects parameter 1 to be array, null given in /.../vendor/erusev/parsedown-extra/ParsedownExtra.php on line 31
PHP Fatal error:  Call to undefined method ParsedownExtra::blockDefinitionList() in /.../vendor/erusev/parsedown/Parsedown.php on line 219

Does this update break compatibility?

- Removing erusev/parsedown (1.1.4)
- Installing erusev/parsedown (1.4.2)

Adding support for markdown within HTML tags

We've recently included Parsedown (Extra) into Statamic (and, by the way, I love it, it's so quick and does a much, much better job of handling the weird edge cases).

Anyway, someone has submitted a ticket to our support system asking about support in Parsedown (Extra) for markdown="1" for parsing within HTML elements. (It's part of Markdown Extra).

So, I'm here doing my due diligence. Is this feature something on the Parsedown Extra roadmap for implementation? Is it perhaps already implemented but slightly different syntax from Markdown Extra?

Thanks for your time (and for such an awesome markdown parser).
Fred

Backslash escapes don't work

Escaping doesn't seem to work properly.

For exemple :

\:exclamation: Ne jamais rien coder d'inutile. Ainsi, il est déconseillé de déclarer : `@color_bg: white;`.

Blockquotes inside footnotes

This footnote output:

[^5]: > And that's the footnote.

Will result in a footnote with the ">" sign as text in a paragraph instead of converting to a blockquote.

<p>&gt; And that’s the footnote.&nbsp;<a href="#fnref1:5" rev="footnote" class="footnote-backref">↩</a></p>

Over-aggressive abbreviations

Input:

AMW

*[AMW]: auxiliary midwife
*[MW]: midwife

Expected output (which is produced by PHP Markdown Extra):

<p><abbr title="auxiliary midwife">AMW</abbr></p>

Actual, incorrect output from Parsedown Extra:

<p><abbr title="auxiliary midwife">A<abbr title="midwife">MW</abbr></abbr></p>

Issues with multiple block-level elements in definition lists

As tested on the parsedown demo: http://parsedown.org/demo?extra=1

this code does not render as it should within the definition list:

Term 1

:   This is a definition with two paragraphs. Lorem ipsum
    dolor sit amet, consectetuer adipiscing elit. Aliquam
    hendrerit mi posuere lectus.

    Vestibulum enim wisi, viverra nec, fringilla in, laoreet
    vitae, risus.

:   Second definition for term 1, also wrapped in a paragraph
    because of the blank line preceding it.

Term 2

:   This definition has a code block, a blockquote and a list.

        code block.

    > block quote
    > on two lines.

    1.  first list item
    2.  second list item

For reference: https://michelf.ca/projects/php-markdown/extra/#def-list

Automatic links don't parse correctly inside markdown="1" blocks

Originally from here: erusev/parsedown#296

All of the following is from the demo (http://parsedown.org/extra/).

Input:

<div markdown="1">
Testing *this*.

<[email protected]>

<http://www.google.com/>
</div>

Expected output (also what PHP Markdown Extra shows):

<div>

<p>Testing <em>this</em>.</p>

<p><a href="&#109;&#x61;&#105;&#x6c;&#116;&#x6f;&#58;&#x74;&#101;&#x73;&#116;&#x40;&#116;&#x65;&#115;&#x74;&#46;&#x63;&#111;&#x6d;">&#x74;&#101;&#x73;&#116;&#x40;&#116;&#x65;&#115;&#x74;&#46;&#x63;&#111;&#x6d;</a></p>

<p><a href="http://www.google.com/">http://www.google.com/</a></p>

</div>

What actually gets output by Parsedown Extra:

<div>
<p>Testing <em>this</em>.</p>
<test><http:></http:></test>
</div>

Rendering breaks at the end of a paragraph with opening tag, but no closing tag

I have a blog article that I was given in HTML format and didn't feel like converting everything.

All paragraphs have an opening tag, but not a closing tag. While this bugs the heck out of me, it's valid in html5, and I didn't have the urge to change it.

In a previous version of parsedown, it rendered fine. (see here https://www.joyent.com/blog/predicteria-2015)

With the version of parsedown included in Kirby 2.0.6, this page breaks. (see this screenshot of the same article on localhost http://d.pr/i/1dkSl)

If I remove all the opening paragraph tags and replace them with line breaks, the unclosed list item tags later in the article still render fine as list items, so it appears that it's just unclosed paragraphs that's broken.

Idea for extension: wrap

I just made an extension that makes an invisible wrapper around any block. Contents are parsed as usual. It wraps any other text in a div so you have more possibilities with CSS and JS.

For example, in our CMS I want our writers to be able to add a setlist when writing a concert review:

     ...setlist
     Intro
     Song 1
     Song 2
     ...

I know this could have been done using

     ```setlist
     Intro
     Song 1
     Song 2
     ```

but the following could not. I wanted our writers to be able to add an image gallery.

     ...gallery
     * ![](some-url)
     * ![](some-url)
     * ![](some-url)
     ...

I could not have a list of images inside en fenced code block since the images would not be parsed. And having images in a list is not enough, since a list could be used someplace else as well.
So I needed an invisible wrapper with a class. Now I can have CSS and JS targeting the .gallery ul.

Using a wrapper with a class I can save some time finding extra codes and extensions. That way I keep ParsedownExtra smaller and put more control into CSS and JS.

Maybe this is interesting in some way for ParsedownExtra. Most code was copied from the blockQuote and blockQuoteContinues methods.

    public function __construct()
    {
        // add a new block type: tripe period plus class name
        $this->BlockTypes['.'] = array('Wrap');
    }

    protected function blockWrap($Line)
    {
        // check for the triple period (or more) plus class name
        if (preg_match('/^\.{3,}[ ]?(.*)/', $Line['text'], $matches)) {
            $Block = array(
                'element' => array(
                    'name' => 'div',
                    'handler' => 'lines',
                    'attributes' => ['class' => $matches[1]],
                ),
            );

            return $Block;
        }
    }

    protected function blockWrapContinue($Line, array $Block)
    {
        if ($Line['text'][0] === '.' and preg_match('/^\.{3,}[ ]?(.*)/', $Line['text'], $matches)) {
            if (isset($Block['interrupted'])) {
                $Block['element']['text'] []= '';
                unset($Block['interrupted']);
            }

            $Block['element']['text'] []= $matches[1];

            return $Block;
        }

        if ( ! isset($Block['interrupted'])) {
            $Block['element']['text'] []= $Line['text'];

            return $Block;
        }
    }

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.