Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and merge to release 0.8.0 #110

Open
wants to merge 79 commits into
base: master
Choose a base branch
from
Open

Conversation

Daniel-KM
Copy link

Hi,

I merged all previous requests and fixes, so parsedown-extra works now as it should. In particular, it allows to add specific attributes to links. This can be the release 0.8.0.

Fixes #44, #55, #58, #71, #82, #85, #86, #96, #99, #100, #101, #106, #109, probably some other issues, and some issues fixed in forks that were not pr.

Sincerely,

Daniel Berthereau
Infodoc & Knowledge management

rhukster and others added 30 commits January 10, 2015 19:41
Setting footnote prefix: ParsedownExtra::setFootnotePrefix( string $footnotePrefix )
	This should be a string that is valid in an HTML attribute, i.e. escaped properly.
	Default value is blank, if this is kept blank behavior is as before.
	Use case in mind is for something like a blog, where you can set the prefix to something unique like a post ID.

Added test_footnote_prefix() to test cases.
ignores the list of voided elements when rendering markdown
Stabilizes library by revamping class to utilize methods from php 5.4
or greater.
Does an extra check on valid DOMElements to make sure they have child
nodes before calling recursively.
Previously, the 'extra' in 'Markdown Extra' was only supported in links,
lists, and headings. This commits adds support for adding a class or ID
to fenced code blocks.
That'll tech me to debug my own code.
* Move the custom class to the <pre> rather than the <code>
* Add dashes in "truncated-for-brevity"
* Code language is specified through 'class="language-python"' rather than 'lang="python"'
* Remove newline at end of file
…st a `class` and `id`.

- I wanted the ability to be able to add `width` & `height` attributes to images but wasn't able to in the current state so I updated the RegEx rules and the `parseAttributeData` method. Now a user can add something like `{.test .fu #bar style="color:red; font-style:italic" data-is-cool="'tis true" lang=en_us}` and it'll render out these attributes `class="test fu" id="bar" style="color:red; font-style:italic" data-is-cool="'tis true" lang="en_us"`.
- I also added the `inlineImage` method so attributes like `width` & `height` can be added.
This can be used as a template for Parsedown extensions (like Parsedown Extra) to reuse Parsedown's original tests. You can either extend tests (like ParsedownExtraTest) or reuse them unchanged (like CommonMarkTest). Parsedown extensions simply have to implement their own TestParsedown class (test/TestParsedown.php) and all original tests will run with a instance of this class, rather than a instance of the original Parsedown class.

This PR is a follow-up to erusev/parsedown#423, i.e. you must merge erusev/parsedown#423 first, otherwise this doesn't work.
Failing tests don't break builds on purpose, Parsedown Extra doesn't fully comply with the CommonMark specs at the moment. We should switch to test/CommonMarkTest.php of erusev/parsedown later, see erusev/parsedown#423 for details.
Fixes erusev#75, erusev#84

- ext-dom is required due to the use of the DOMDocument class
- ext-mbstring is required due to the use of the mb_convert_encoding() function
@Daniel-KM Daniel-KM force-pushed the fix/merge branch 5 times, most recently from a3a8f2b to 4f427f0 Compare June 21, 2017 14:21
@cooperaj
Copy link

This PR adds many necessary fixes and tweaks. The one especially hitting me is the footnote count being incorrect on subsequent calls.

I'd really really like to see this merged.

@Daniel-KM
Copy link
Author

Daniel-KM commented Jun 21, 2017

Note that because it allows any attributes and potentially any xss attacks, the merge will be released after the upstream of parsedown (see erusev/parsedown#495 or erusev/parsedown#161).

@aidantwoods
Copy link
Collaborator

@Daniel-KM

Note that because it allows any attributes and potentially any xss attacks, the merge will be released after the upstream of parsedown (see erusev/parsedown#495 or erusev/parsedown#161).

If I'm reading this right, some of these changes will allow arbitrary attribute (names) to be set?

A feature in erusev/parsedown#495 will prune the event handlers (their only purpose is scripting, so getting rid of them is an easy win).

But I would strongly encourage the use of the new $this->safeMode bool that'll be available once that PR is merged, so as to decide whether or not to permit arbitrary attribute names. ($this->safeMode should indicate that the user would like Parsedown to operate as necessary to be safe).

I mention this because, even without event handlers, there are still possible XSS vectors if arbitrary attribute names can be set, and if the browser permits these ridiculous things (e.g. here and some after here – thankfully e.g. Chrome does not permit javascript in a stylesheet url as executable, but I bet you could find a browser that does permit it).

Equally, there might be an attribute that just plain permits scripting that I haven't considered – dropping event attributes is ultimately a blacklist, so is unfortunately doomed to play the catchup game as (I miss things to include || new attributes come to exist). Still, dropping event handlers is still better than not dropping them IMO if an extension already permits arbitrary attribute names (hence why the feature exists), but to be safe the extension should ideally change its behaviour to be less permissive when $this->safeMode is set to true.

To sum that huge message up:
Recommended change: utilise $this->safeMode to decide whether to permit arbitrary attribute names to be set.

@Daniel-KM
Copy link
Author

Daniel-KM commented Jul 2, 2017

@aidantwoods
Yes, markdown-extra is a specific markdown to allow to add class, id, and anything else in markdown. For example, I need to use the attributes "rel" and "lang", but this is impossible with markdown. Of course, this is not for public writing, but for controlled edition.

@aidantwoods
Copy link
Collaborator

Of course, this is not for public writing, but for controlled edition.

Looks like (from a cursory look at the code) that there is no setter to turn this on/off though? So Parsedown-extra would automatically allow these attributes, with no option to let Parsedown-extra know whether or not you trust the input contents (i.e. if you use this version of parsedown-extra, it can only be used for trusted input).

If you wanted to retain the xss protection added by erusev/parsedown#495, then I'd suggest toggling such attribute behaviour based on the user-set $this->safeMode setting.

Yes, markdown-extra is a specific markdown to allow to add class, id, and anything else in markdown. For example, I need to use the attributes "rel" and "lang", but this is impossible with markdown.

It seems like Parsedown-extra adds more than that? Abbreviations, footnotes, ...? Those would still be useful in their own right, without being able to set arbitrary html attributes?

@Daniel-KM
Copy link
Author

Daniel-KM commented Jul 2, 2017

I'm going to rebase this commit on your secure parsedown. To allow attributes is the purpose of markdown extra... You can look at https://michelf.ca/projects/php-markdown/extra/ for it. Or a double setter, one for basic attributes (rel, lang, etc.), by default, the other for any attributes (if somebody really want anything).

@Daniel-KM Daniel-KM force-pushed the fix/merge branch 3 times, most recently from 67c3b46 to b0c512e Compare July 6, 2017 11:53
@bung87
Copy link

bung87 commented Nov 5, 2017

code start with self::str needs to remove self::
and self::substr needs to remove self::

@NightScript370
Copy link

So, uh, does this have a possibility of getting merged?

@aidantwoods
Copy link
Collaborator

Yup! Once Parsedown 1.8 is released I hope to be able to take a look at the things in this PR :)

@sbrl
Copy link

sbrl commented May 23, 2020

Any update on this amazing PR getting merged?

By the looks of things Parsedown 2.x is now being worked on - but it doesn't appear to be a single file any more (which, unfortunately, is actually critical to my extremely unusual use-case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTML on one line renders incorrectly