erusev / parsedown-extra Goto Github PK
View Code? Open in Web Editor NEWMarkdown Extra Extension for Parsedown
License: MIT License
Markdown Extra Extension for Parsedown
License: MIT License
Hi nice work.
It seems parsedown-extra does not work in PHP v5.2.
The problematic part seems to be this one.
https://github.com/erusev/parsedown-extra/blob/0.5.1/ParsedownExtra.php#L350-L352
uasort($this->DefinitionData['Footnote'], function($A, $B) {
return $A['number'] - $B['number'];
});
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.
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);
Could you put a list into readme.md
?
Also is this extension includes autolink?
<div markdown="1">A text with any html entity —</div>
Expected output:
<div markdown="1"><p>A text with any html entity —</p></div>
Actual output is same as source:
<div markdown="1">A text with any html entity —</div>
Using an actual symbol instead of its entity (e.g. —
instead of —
) produces paragraphs inside markdown="1"
blocks as expected.
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="mailto:test@test.com">test@test.com</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>
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 😄
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.
HTML entities like »
are not working. Instead, I get the following error: "DOMDocument::loadXML(): Entity 'raquo' not defined in Entity".
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 <a href="#fnref1:0" rev="footnote" class="footnote-backref">↩</a></p>
</li>
</ol>
</div>
Hi, since parsedown version 1.2.0 there is this E_WARNING coming up when using parsedown-extra.
Trace:
...
ParsedownExtra->__construct( )
array_unshift () in ParsedownExtra.php:31
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;
}
}
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"><p>paragraph <b>emphasis</b>
</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!
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.
the following works with MDE, but not PDE:
![kitteh][1]
[1]: http://exmoorpet.com/wp-content/uploads/2012/08/cat.png {.right}
<figure>
<!--<img src="https://www.google.cz/images/srpr/logo11w.png" alt="">-->
</figure>
Try it on http://parsedown.org/extra/
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.
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>
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.
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>
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
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>
(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>
.
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>
.
It would be cooler 😄
Hi, I had originally posted this to the Kirby CMS github repo, but realize it is probably more appropriately placed here:
If a
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:
break
- You should never - See me againbreak
- test - testbreak
- test - testbreak
- test - testbreak
- test - testbreak
- test - testbreak
- test - testbreak
- test - testbreak
- test - testbreak
- test - testbreak
- test - testbreak
- test - testbreak
- test - testHHVM 3.4 and 3.6-dev both display have this issue:
Fatal error: Call to undefined method DOMText::getAttribute() in /home/travis/build/BootstrapCMS/CMS/vendor/erusev/parsedown-extra/ParsedownExtra.php on line 477
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
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.
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>
on parse down, is there any easy way to prevent some tag being parsed like <script>
or <form>
?
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.
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>
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.
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
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>
Hi !
It's possible to add the multimarkdown support http://fletcherpenney.net/multimarkdown/ in parsedown, e.g metadata ?
Regards
As I am using Parsedown-extra many times in a same page, the anchors target not only the concerned item. E.g:
`
Item 1
Item 2
`
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 ?
Could you tag a stable version?
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.
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
patch
foreach ($numbers as $number)
{
$backLinkText = ' <a href="#fnref' ...;
}
to
$backLinkText .= ' <a href="#fnref' ...;
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)
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.
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?
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;`.
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>> And that’s the footnote. <a href="#fnref1:5" rev="footnote" class="footnote-backref">↩</a></p>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.