The Wayback Machine - https://web.archive.org/web/20210708155045/https://github.com/laravel/framework/pull/37954
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

[8.x] Add support for both CommonMark 1.x and 2.x #37954

Open
wants to merge 1 commit into
base: 8.x
Choose a base branch
from

Conversation

@colinodell
Copy link
Contributor

@colinodell colinodell commented Jul 8, 2021

This PR complements #37953 by allowing users of 8.x to install either major version of the CommonMark library.

@@ -22,7 +22,7 @@
"doctrine/inflector": "^1.4|^2.0",
"dragonmantank/cron-expression": "^3.0.2",
"egulias/email-validator": "^2.1.10",
"league/commonmark": "^1.3",
"league/commonmark": "^1.3|^2.0",

This comment has been minimized.

@colinodell

colinodell Jul 8, 2021
Author Contributor

Technically you'll want ^2.0beta3, as the type hints in the first two betas do not support $converter->getEnvironment()->addExtension() as used below.

], $environment);
]);

$converter->getEnvironment()->addExtension(new TableExtension());

This comment has been minimized.

@colinodell

colinodell Jul 8, 2021
Author Contributor

To help promote compatibility between the two major versions, 2.0.0-beta3 exposes an Environment here that can be used to add new extensions. This is not the preferred way to add extensions, and it may be deprecated at some point, but it at least allows for easy compatibility by avoiding the Environment namespace changes.


return new HtmlString($converter->convertToHtml($text));
return new HtmlString((string) $converter->convertToHtml($text));

This comment has been minimized.

@colinodell

colinodell Jul 8, 2021
Author Contributor

In 1.x the convertToHtml() method returns a string. In 2.x it returns a Stringable object. Casting the output to a string allows us to support both.

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

Successfully merging this pull request may close these issues.

None yet

1 participant