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

Github-Flavored Markdown #409

Merged
merged 261 commits into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
261 commits
Select commit Hold shift + click to select a range
55a87bf
Include phpunit
dakota Jul 30, 2015
7b005ec
Remove silly comma
dakota Jul 30, 2015
8fa79ab
Adds code which seems to work
johanmeiring Jul 30, 2015
e21a932
Updated to the new commonmark 0.11 API
hason Sep 21, 2015
569bdc4
Added missing tests
hason Sep 22, 2015
edbd119
phpunit should be a dev dependency
dakota Oct 29, 2015
174a272
Enabled a new release of commonmark library
hason Nov 5, 2015
c4e70a3
Enabled commonmark 0.13
hason Jan 14, 2016
422113a
Add support for twig renderer
hason Nov 5, 2015
2158dba
Enable commonmark 0.14 and improve project setting
hason Jul 14, 2016
e1e2753
Fix CS
hason Jul 14, 2016
ebe4b39
Add support for table caption (MultiMarkdown)
hason Jul 14, 2016
2807fe2
Fix tests namespace
hason Sep 24, 2016
6a83cf9
Move support for twig renderer to another repository
hason Sep 24, 2016
96df6e4
Add support for commonmark 0.15
onigoetz Sep 22, 2016
b110757
Improve test matrix
onigoetz Sep 22, 2016
256f250
Support only two latest versions of commonmark
hason Sep 24, 2016
cd4e375
Update Readme and Changelog
hason Sep 26, 2016
95fb184
Allow any phpunit
dakota Sep 30, 2016
23c598b
Fix single-column tables not rendering.
smoogipoo Jan 5, 2017
55a26ed
Correct implementation for single column tables
hason Jan 11, 2017
df490a8
Add webuni as author to composer.json
hason Jan 11, 2017
ebbd69b
Update changelog
hason Jan 11, 2017
70259aa
Better parsing of escapes in cell
nanaya Feb 27, 2017
dc86cb1
Added support for league/commonmark 0.16
michalbundyra Nov 1, 2017
a610130
Added commonmark v0.16 to Travis CI config
michalbundyra Nov 1, 2017
8ef65ce
Added PHP 7.1 and PHP 7.2 in Travis CI config
michalbundyra Nov 1, 2017
ca3e56c
In league/commonmark:0.15, Cursor::getFirstNonSpacePosition() is depr…
rejinka Nov 14, 2017
493663c
Merge pull request #13 from webimpress/feature/leaguage-commonmark-up…
hason Jan 2, 2018
dc27001
Merge pull request #9 from nanaya/fix-escapes
hason Jan 2, 2018
65f918a
Merge pull request #14 from rejinka/feature/remove_deprecation_in_com…
hason Jan 2, 2018
f3b4e18
Fix parsing whitespaces at the end of line
hason Jan 9, 2018
0273ce0
Tag 0.7.0 version
hason Jan 9, 2018
6326245
Fix travis configuration
hason Jan 9, 2018
24845f0
Update escape to use the new helper method
nanaya Jan 15, 2018
490ca9f
Merge pull request #16 from nanaya/xml_escape_update
hason Jan 23, 2018
de50839
Add Psalm static analysis tool
hason Jan 23, 2018
d66b3e5
Feature/html5 head align (#11)
rcole5 Jan 24, 2018
4304b1f
Replace align attribute with text-align style
hason Jan 24, 2018
8c75eb0
Update to league/commonmark 0.17
pjeby May 12, 2018
3db4e01
Add a StrikethroughExtension for ease of use
pjeby May 12, 2018
9046e7e
Document use of StrikethroughExtension
pjeby May 12, 2018
6d10f45
Adding .stickler.yml
stickler-ci May 14, 2018
8206d6b
Merge pull request #3 from uafrica/add-stickler-config
dakota May 14, 2018
d347b1d
Requested change
pjeby May 14, 2018
cfa6dbd
Remove use of removed escape() method on renderers
pjeby May 14, 2018
80f29b8
Merge pull request #2 from pjeby/update-17
dakota May 14, 2018
607c9a8
Indicate correct namespace
johanmeiring Jun 3, 2018
ff065cf
De-lint README
johanmeiring Jun 3, 2018
79ced50
Allow to use the library with CommonMark v0.18.
shulard Oct 8, 2018
94bc98d
Bump version
hason Nov 28, 2018
b64f0f0
Update to league/commonmark 0.18
laurentbardin Jan 3, 2019
a1e27d1
Merge pull request #5 from laurentbardin/update-commonmark-version
dakota Jan 7, 2019
0f927fd
Update dependencies
hason Feb 14, 2019
2540c85
Fix cs
hason Feb 14, 2019
18b2727
Fix errors from static analyse
hason Feb 14, 2019
44ffaba
Fix implementation of Table
hason Feb 14, 2019
2d90236
Update changelog
hason Feb 14, 2019
25838c2
Fix travis build
hason Feb 14, 2019
cdb21c2
Add run script
hason Feb 14, 2019
83af203
Initial commit
colinodell Mar 11, 2019
2d04acd
Update description and keywords
colinodell Mar 11, 2019
aece893
Fix StyleCI violations
colinodell Mar 11, 2019
2fa7239
Add link to league/commonmark project
colinodell Mar 11, 2019
c1dc244
Fix project name and namespace
colinodell Mar 11, 2019
f910a11
Initial commit
colinodell Mar 11, 2019
0fe08a2
Fix package reference
colinodell Mar 11, 2019
12af0f1
composer: fix autoload-dev for tests
glensc Mar 11, 2019
51cd6fa
composer: fix autoload-dev for tests
glensc Mar 11, 2019
d516b52
changelog: reformat and fix changelog links
glensc Mar 11, 2019
71e9eae
Merge pull request #2 from glensc/patch-2
colinodell Mar 12, 2019
050452e
Merge pull request #1 from glensc/patch-1
colinodell Mar 12, 2019
813e4f9
Merge pull request #1 from glensc/patch-1
colinodell Mar 12, 2019
721a1ec
Initial release
colinodell Mar 15, 2019
76b29bc
Fix broken example
colinodell Mar 15, 2019
520e256
Expand Twitter test suite
colinodell Mar 15, 2019
1e446cd
Use the new "commonmark-extension" package type
colinodell Mar 15, 2019
9cd798e
Fix typos in README
svenluijten Mar 15, 2019
2fd1689
Merge pull request #1 from svenluijten/patch-1
colinodell Mar 15, 2019
054450b
exclude editorconfig and styleci from git export
glensc Mar 16, 2019
11c934c
tests: fix namespace capitalization
glensc Mar 16, 2019
a0cb79d
composer: use semver construct for php version
glensc Mar 16, 2019
4f4d3a8
changelog: add 0.1.0 section, fix linking
glensc Mar 16, 2019
a39216b
Merge pull request #3 from glensc/patch-1
colinodell Mar 16, 2019
5623c32
Update CHANGELOG.md
colinodell Mar 16, 2019
9490978
Merge pull request #5 from glensc/test-namespace-naming-fix
colinodell Mar 16, 2019
84a5e10
Refactor tests to use a data provider
colinodell Mar 16, 2019
3dc749f
Fix issues with start/end matching; add more tests
colinodell Mar 16, 2019
a0e0874
Add support for autolinking 'www' URLs per GFM
colinodell Mar 16, 2019
cd21b11
Implement trailing paren handling per the GFM spec
colinodell Mar 16, 2019
90b65ff
Add more GFM spec tests
colinodell Mar 16, 2019
15c97b6
Add ftp as a default protocol per GFM
colinodell Mar 16, 2019
925a532
Fix GFM entity reference handling
colinodell Mar 17, 2019
804b584
Make StyleCI happy
colinodell Mar 17, 2019
93fac92
Fix bad minimum version of PHPUnit
colinodell Mar 17, 2019
438a903
Fix GFM spec compatibility for email autolinks
colinodell Mar 17, 2019
69ec16f
Break processor into smaller chunks
colinodell Mar 17, 2019
f78d4c5
Skip nodes with no autolinks
colinodell Mar 17, 2019
5d950be
Optimize calls to internal PHP functions
colinodell Mar 17, 2019
8b943e8
Document the GFM changes and spec adherence
colinodell Mar 17, 2019
aa5d329
Merge pull request #6 from thephpleague/feature/gfm
colinodell Mar 17, 2019
5687805
Reformat and move the LICENSE file so Github can detect it
colinodell Mar 17, 2019
326c57f
Prepare to release v0.2.0
colinodell Mar 17, 2019
585875f
Fix link to GFM spec section
colinodell Mar 17, 2019
030700d
readme: remove empty pattern (#8)
glensc Mar 19, 2019
2f83c58
Use the new "commonmark-extension" package type
colinodell Mar 15, 2019
66ba8a9
Fix URL autolinking (fixes #10)
colinodell Mar 28, 2019
c35dd4a
Prepare to release 0.3.0
colinodell Apr 11, 2019
12c1ec6
Prepare to release 0.2.0
colinodell Apr 11, 2019
a49a2d1
Don't test on unsupported PHP versions
colinodell Apr 11, 2019
aca3fa7
Don't test on supported PHP versions
colinodell Apr 11, 2019
0488f69
Fix changelog links
colinodell Apr 11, 2019
92806c3
Prepare to release 0.2.0
colinodell Apr 11, 2019
ed8e604
Make StyleCI ignore indentation
colinodell Apr 11, 2019
fadf668
Make StyleCI ignore semi-colon placement
colinodell Apr 11, 2019
724a1f1
Update namespace, copyright, composer.json, and code style
colinodell Mar 15, 2019
20be7eb
Bump dependencies; make compatible with league/commonmark 0.19
colinodell Apr 14, 2019
e69547e
Update the README
colinodell Apr 19, 2019
624b86b
Bump the master branch alias
colinodell Apr 19, 2019
76191d4
Add CONDUCT.md
colinodell Apr 19, 2019
fb9a338
Add a changelog
colinodell Apr 19, 2019
e5e6a3a
Configure third-party services
colinodell Apr 19, 2019
1ba496f
Fix link in README
colinodell Apr 19, 2019
096c1a3
Apply fixes from StyleCI
colinodell Apr 19, 2019
fe5500d
Merge pull request #1 from thephpleague/analysis-z4PDRN
colinodell Apr 19, 2019
b4bb867
Add missing extension to composer.json
colinodell Apr 19, 2019
1aadc22
Add additional unit test
colinodell Apr 19, 2019
ee4a91e
Update CHANGELOG
colinodell Apr 19, 2019
7e59d85
Mark this package as a replacement for uafrica/commonmark-ext
colinodell Apr 19, 2019
5ae0bc2
Release v0.4.0
colinodell Apr 19, 2019
7acd8b6
Refactor to use delimiter processors
colinodell Apr 20, 2019
6894d9f
Initial commit
colinodell May 12, 2019
a74f918
Expand test coverage
colinodell May 12, 2019
5ef3802
Release 0.1.0
colinodell May 12, 2019
bac1b9e
Configure Stale bot
colinodell May 13, 2019
e6d88bd
Configure Stale bot
colinodell May 13, 2019
654aabb
Configure Stale bot
colinodell May 13, 2019
3a0b6b1
Configure Stale bot
colinodell May 13, 2019
8e4987d
Initial commit
colinodell May 19, 2019
6b36fa6
Apply fixes from StyleCI
colinodell May 19, 2019
dc18a61
Merge pull request #1 from thephpleague/analysis-qvxeGl
colinodell May 19, 2019
92209d5
Fix code example
colinodell May 19, 2019
3e9fd6f
Release 0.1.0
colinodell May 19, 2019
fca95e5
Fix branch alias
colinodell May 19, 2019
0bfc2f6
Add FUNDING.yml
colinodell May 23, 2019
bf2958e
Add FUNDING.yml
colinodell May 23, 2019
7440862
Add FUNDING.yml
colinodell May 23, 2019
d0c235c
Add FUNDING.yml
colinodell May 23, 2019
7289cdc
Add FUNDING.yml
colinodell May 23, 2019
a88c946
Add FUNDING.yml
colinodell May 23, 2019
45070bc
Mark as compatible with league/commonmark 1.0.0-beta1
colinodell May 27, 2019
d24e66e
Make compatible with league/commonmark 1.0.0-beta1
colinodell May 27, 2019
d6c904a
Fix changelog header
colinodell May 27, 2019
11b4147
Make compatible with league/commonmark 1.0.0-beta2
colinodell May 27, 2019
674a355
Fix code style
colinodell May 27, 2019
d2408ca
Merge pull request #4 from thephpleague/beta-release
colinodell May 27, 2019
fc20398
Make compatible with league/commonmark 1.0.0-beta2
colinodell May 27, 2019
72b6cd8
Merge pull request #2 from thephpleague/commonmark-next
colinodell May 27, 2019
62d7315
Release 1.0.0-beta1
colinodell May 27, 2019
d2d2b37
Make compatible with league/commonmark 1.0.0-beta1
colinodell May 27, 2019
30386b8
Make compatible with league/commonmark 1.0.0-beta3
colinodell May 28, 2019
53bd6ba
Make compatible with league/commonmark 1.0.0-beta3
colinodell May 28, 2019
de2ce9f
Make compatible with league/commonmark 1.0.0-beta4
colinodell Jun 5, 2019
45f2879
Make compatible with league/commonmark 1.0.0-beta4
colinodell Jun 5, 2019
84b15dc
Fix CHANGELOG reference
colinodell Jun 5, 2019
aa88bb5
Fix incorrect double-linking of standard CommonMark autolinks (fixes …
colinodell Jun 17, 2019
69c181c
Merge v0.3.1
colinodell Jun 17, 2019
5c992e9
Release 1.0.0-beta3
colinodell Jun 17, 2019
9f6da88
Prepare to release v1.0.0
colinodell Jun 29, 2019
46a5c80
Prepare to release v1.0.0
colinodell Jun 29, 2019
99892ad
Prepare to release v1.0.0
colinodell Jun 29, 2019
1a9ed08
Prepare to release v1.0.0
colinodell Jun 29, 2019
45927a7
Prepare to release v1.0.0
colinodell Jun 29, 2019
b2e68fd
Prepare to release v1.0.0
colinodell Jun 29, 2019
3094256
Add support of league commonmark 0.19
yenyasinn Jun 18, 2019
f35d895
composer: allow 1.0; fix 0.x semver
glensc Jul 5, 2019
dfbf10b
chore: Update run and travis script
hason Jul 9, 2019
01d0694
fix: Fix cs and remove obsolete code
hason Jul 9, 2019
d317299
chore: Use composer cache from host in docker
hason Jul 9, 2019
93a3fd9
feat: Prepare 1.0.0 vesion
hason Jul 9, 2019
4101574
chore: Fix travis
hason Jul 9, 2019
7831472
chore: Fix condition in travis
hason Jul 9, 2019
9b976a5
chore: Disable analyse for php 7.1
hason Jul 9, 2019
ccc83f8
Add additional test cases
colinodell Jul 11, 2019
e4b06f7
Fix code not reusing an existing variable
colinodell Jul 11, 2019
7e9e899
Optimize a regular expression
colinodell Jul 11, 2019
9fe28f3
Release v1.0.1
colinodell Jul 11, 2019
201c566
Change the namespace
colinodell Jul 11, 2019
3d7d3d0
Add Colin O'Dell as a maintainer
colinodell Jul 11, 2019
d5e0b0c
Update package name
colinodell Jul 11, 2019
f699489
Allow scripts to be run via Composer
colinodell Jul 11, 2019
cce7710
Refactor changelog to follow Keep A Changelog
colinodell Jul 11, 2019
1baf3bb
Add .editorconfig file
colinodell Jul 11, 2019
c083b00
Bump branch alias to 2.0
colinodell Jul 11, 2019
d2abd0e
Update .scrutinizer.yml
colinodell Jul 11, 2019
b7afc0f
Fix badge URLs
colinodell Jul 11, 2019
96012cb
Change Webuni to League
baijunyao Jul 13, 2019
fad947a
Merge pull request #29 from baijunyao/master
colinodell Jul 13, 2019
6345558
Update the README
colinodell Jul 13, 2019
4daefec
Add information on CONTRIBUTING
colinodell Jul 13, 2019
601d5fb
Add CODE_OF_CONDUCT.md
colinodell Jul 13, 2019
d6e6fc2
Configure stalebot
colinodell Jul 13, 2019
2e0fff2
Add issue templates
colinodell Jul 13, 2019
e5585df
Fix code coverage uploads
colinodell Jul 13, 2019
67bac65
Include function tests in code coverage calculation
colinodell Jul 13, 2019
c7aa3b9
Mark all renderers as final
colinodell Jul 13, 2019
1146c2a
Mark the parser as final
colinodell Jul 13, 2019
fafac0a
Remove unused function
colinodell Jul 13, 2019
e4d066c
Rename TableRows to TableSection
colinodell Jul 13, 2019
4bb680b
Prepare to release 2.0.0
colinodell Jul 13, 2019
8b36bf3
Fix link in changelog
colinodell Jul 15, 2019
75d9a41
Update the README
baijunyao Aug 5, 2019
b4bf5d8
Merge pull request #30 from baijunyao/master
colinodell Aug 5, 2019
bf86599
Remove manual escaping of attributes
nanaya Sep 25, 2019
de04873
Merge pull request #31 from nanaya/attrs-escape
colinodell Sep 26, 2019
3228888
Prepare to release v2.1.0
colinodell Sep 26, 2019
3d03105
Make the quote characters customizable.
adawolfa Oct 3, 2019
822d019
Merge pull request #5 from adawolfa/feature-configurable-quotes
colinodell Oct 3, 2019
3746a86
Prepare to release v1.1.0
colinodell Oct 3, 2019
163529a
Update FUNDING.yml
colinodell Oct 11, 2019
ce7ee5c
Update FUNDING.yml
colinodell Oct 11, 2019
1462751
Update FUNDING.yml
colinodell Oct 11, 2019
b3c0c50
Update FUNDING.yml
colinodell Oct 11, 2019
f831603
Update FUNDING.yml
colinodell Oct 11, 2019
c13eefe
Test on PHP 7.4 stable
colinodell Dec 3, 2019
062dc66
Test on PHP 7.4 stable
colinodell Dec 3, 2019
91f8074
Test on PHP 7.4 stable
colinodell Dec 3, 2019
c79c667
Test on PHP 7.4 stable
colinodell Dec 3, 2019
5113a6b
Test on PHP 7.4 stable
colinodell Dec 3, 2019
128893c
Fix incorrect parenthesis order (#13)
colinodell Jan 14, 2020
9b10753
Prepare to release v1.0.1
colinodell Jan 14, 2020
14823f6
Import the autolink extension
colinodell Jan 21, 2020
97a36c7
Import the External Link extension
colinodell Jan 21, 2020
d0c0413
Import the Inlines Only extension
colinodell Jan 21, 2020
5dfb2b6
Import the Smart Punctuation extension
colinodell Jan 21, 2020
75d76f7
Fix phpstan issues in imported extensions
colinodell Jan 21, 2020
39feb16
Fix extension namespaces and paths
colinodell Jan 21, 2020
88504d9
Import the Strikethrough extension
colinodell Jan 21, 2020
e0fe28b
Import the Table extension
colinodell Jan 21, 2020
c9716b8
Import the TaskList extension
colinodell Jan 21, 2020
7947460
Use the 'align' attribute instead of hard-coded CSS
colinodell Jan 23, 2020
d347978
Add new DisallowedRawHtml extension
colinodell Jan 23, 2020
f48f356
Create a new GFM extension to replace the suggest commonmark-extra li…
colinodell Feb 1, 2020
a14ac19
Test the GFM extension against the GFM spec
colinodell Feb 1, 2020
08a8e14
Modify Task List functionality to match the GFM spec
colinodell Feb 1, 2020
3961685
Modify table functionality to match GFM spec
colinodell Feb 4, 2020
7d034ff
Fix code style
colinodell Feb 4, 2020
5db7c92
Remove table caption functionality
colinodell Feb 4, 2020
90b144f
Avoid using buggy version of scrutinizer/ocular (fixes #410)
colinodell Feb 4, 2020
c93840d
Update the documentation
colinodell Feb 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ finder:
- ".phpstorm.meta.php"
- "CommonMarkCoreExtension.php"
- "FakeEmptyHtmlRenderer.php"
- "InlinesOnlyExtension.php"
- "SmartPunctExtension.php"
- "TableExtension.php"
not-path:
- ".ripstech"
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ Full documentation on advanced usage, configuration, and customization can be fo

Information on how to upgrade to newer versions of this library can be found at <https://commonmark.thephpleague.com/releases>.

## 💻 Github-Flavored Markdown

Github-Flavored Markdown can be parsed by using the `GithubFlavoredMarkdownConverter`:

```php
use League\CommonMark\GithubFlavoredMarkdownConverter;

$converter = new GithubFlavoredMarkdownConverter([
'html_input' => 'strip',
'allow_unsafe_links' => false,
]);

echo $converter->convertToHtml('# Hello World!');

// <h1>Hello World!</h1>
```

This is a drop-in replacement for the `CommonMarkConverter` which adds additional features found in the GFM spec:

- Autolinks
- Disallowed raw HTML
- Strikethrough
- Tables
- Task Lists

See the [Extensions documentation](https://commonmark.thephpleague.com/1.0/customization/extensions/) for more details on how to include only certain GFM features if you don't want them all.

## 🗃️ Related Packages

### Integrations
Expand All @@ -62,19 +89,7 @@ Information on how to upgrade to newer versions of this library can be found at
- [Twig Markdown extension](https://github.com/twigphp/markdown-extension)
- [Twig filter and tag](https://github.com/aptoma/twig-markdown)

### GFM Extensions

You can easily add support for Github-Flavored Markdown by installing the [`league/commonmark-extras`](https://github.com/thephpleague/commonmark-extras) package, which includes bundles all of the extensions listed below:

| Feature | Package Name | Description |
| ------- | ------------ | ----------- |
| Autolinks | [`league/commonmark-ext-autolink`](https://github.com/thephpleague/commonmark-ext-autolink) | Automatically links URLs, emails, and (optionally) @-mentions without needing to use `<...>` |
| Smart Punctuation | [`league/commonmark-ext-smartpunct`](https://github.com/thephpleague/commonmark-ext-smartpunct) | Intelligently converts ASCII quotes, dashes, and ellipses to their Unicode equivalents |
| Strikethrough | [`league/commonmark-ext-strikethrough`](https://github.com/thephpleague/commonmark-ext-strikethrough) | Adds support for `~~strikethrough~~` syntax |
| Task Lists | [`league/commonmark-ext-task-list`](https://github.com/thephpleague/commonmark-ext-task-list) | Support for Github-style task lists |
| Tables | [`league/commonmark-ext-table`](https://github.com/thephpleague/commonmark-ext-table) | GFM-style tables |

### Other PHP League Extensions
### Extensions

- [`league/commonmark-ext-inlines-only`](https://github.com/thephpleague/commonmark-ext-inlines-only) - Renders inline text without paragraph tags or other block-level elements
- [`league/commonmark-ext-external-link`](https://github.com/thephpleague/commonmark-ext-external-link) - Mark external links, make them open in new windows, etc.
Expand Down
16 changes: 14 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
"cebe/markdown": "~1.0",
"commonmark/commonmark.js": "0.29.1",
"erusev/parsedown": "~1.0",
"github/gfm": "0.29.0",
"michelf/php-markdown": "~1.4",
"mikehaertl/php-shellcommand": "^1.4",
"phpstan/phpstan-shim": "^0.11.5",
"phpunit/phpunit": "^7.5",
"scrutinizer/ocular": "^1.5",
"symfony/finder": "^4.2"
},
"suggest": {
"league/commonmark-extras": "Library of useful extensions including smart punctuation"
"conflict": {
"scrutinizer/ocular": "1.7.*"
},
"repositories": [
{
Expand All @@ -49,6 +50,17 @@
"type": "zip"
}
}
},
{
"type": "package",
"package": {
"name": "github/gfm",
"version": "0.29.0",
"dist": {
"url": "https://github.com/github/cmark-gfm/archive/0.29.0.gfm.0.zip",
"type": "zip"
}
}
}
],
"autoload": {
Expand Down
6 changes: 4 additions & 2 deletions docs/1.0/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ redirect_from: /0.20/configuration/
Configuration
=============

You can provide an array of configuration options to the `CommonMarkConverter` when creating it::
You can provide an array of configuration options to the `CommonMarkConverter` when creating it:

~~~php
<?php
Expand All @@ -34,7 +34,7 @@ Here's a list of currently-supported options:

* `renderer` - Array of options for rendering HTML
* `block_separator` - String to use for separating renderer block elements
* `inner_separator` - String to use for separating inner block contents
* `inner_separator` - String to use for separating inner block contents
* `soft_break` - String to use for rendering soft breaks
* `enable_em` - Disable `<em>` parsing by setting to `false`; enable with `true` (default: `true`)
* `enable_strong` - Disable `<strong>` parsing by setting to `false`; enable with `true` (default: `true`)
Expand All @@ -47,6 +47,8 @@ Here's a list of currently-supported options:
* `allow_unsafe_links` - Remove risky link and image URLs by setting this to `false` (default: `true`)
* `max_nesting_level` - The maximum nesting level for blocks (default: infinite). Setting this to a positive integer can help protect against long parse times and/or segfaults if blocks are too deeply-nested. Added in 0.17.

Additional configuration options are available for some of the [available extensions](/1.0/customization/extensions/) - refer to their individual documentation for more details.

The following options have been deprecated. They will no longer work once 1.0.0 is released:

* `safe` - Prevents rendering of raw HTML if set to `true` (default: `false`)
Expand Down
48 changes: 48 additions & 0 deletions docs/1.0/customization/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class EmojiExtension implements ExtensionInterface
public function register(ConfigurableEnvironmentInterface $environment)
{
$environment
// TODO: Create the EmojiParser, Emoji, and EmojiRenderer classes
->addInlineParser(new EmojiParser(), 20)
->addInlineRenderer(Emoji::class, new EmojiRenderer(), 0)
;
Expand All @@ -34,3 +35,50 @@ $environment->addExtension(new EmojiExtension();
$converter = new CommonMarkConverter([], $environment);
echo $converter->convertToHtml('Hello! :wave:');
```

## Included Extensions

Starting in v1.3, this library includes several extensions to support Github-Flavored Markdown. You can manually add the GFM extension to your environment like this:

```php
$environment = Environment::createCommonMarkExtension();
colinodell marked this conversation as resolved.
Show resolved Hide resolved
$environment->addExtension(new GithubFlavoredMarkdownExtension();
colinodell marked this conversation as resolved.
Show resolved Hide resolved

$converter = new CommonMarkConverter([], $environment);
echo $converter->convertToHtml('Hello GFM!');

```

Or, if you only want a subset of GFM extensions, you can add them individually like this instead:

```php
colinodell marked this conversation as resolved.
Show resolved Hide resolved
$environment = Environment::createCommonMarkExtension();
colinodell marked this conversation as resolved.
Show resolved Hide resolved
// Remove any of the lines below if you don't want a particular feature
$environment->addExtension(new AutolinkExtension());
$environment->addExtension(new DisallowedRawHtmlExtension());
$environment->addExtension(new StrikethroughExtension());
$environment->addExtension(new TableExtension());
$environment->addExtension(new TaskListExtension());

$converter = new CommonMarkConverter([], $environment);
echo $converter->convertToHtml('Hello GFM!');
```

### GFM Extensions

| Extension | Purpose | Documentation |
| --------- | ------- | ------------- |
| **`GithubFlavoredMarkdownExtension`** | Enables full support for GFM. Includes the following sub-extensions by default: | |
| `AutolinkExtension` | Enables automatic linking of URLs within text without needing to wrap them with Markdown syntax | [Documentation](https://github.com/thephpleague/commonmark/blob/master/src/Extension/Autolink/README.md) |
| `DisallowedRawHtmlExtension` | Disables certain kinds of HTML tags that could affect page rendering | |
| `StrikethroughExtension` | Allows using tilde characters (`~~`) for ~strikethrough~ formatting | [Documentation](https://github.com/thephpleague/commonmark/blob/master/src/Extension/Strikethrough/README.md) |
| `TableExtension` | Enables you to create HTML tables | [Documentation](https://github.com/thephpleague/commonmark/blob/master/src/Extension/Table/README.md) |
| `TaskListExtension` | Allows the creation of task lists | [Documentation](https://github.com/thephpleague/commonmark/blob/master/src/Extension/TaskList/README.md) |

### Other Useful Extensions

| Extension | Purpose | Documentation |
| --------- | ------- | ------------- |
| `ExternalLinkExtension` | Tags external links with additional markup | [Documentation](https://github.com/thephpleague/commonmark/blob/master/src/Extension/ExternalLink/README.md) |
| `InlinesOnlyExtension` | Only includes standard CommonMark inline elements - perfect for handling comments and other short bits of text where you only want bold, italic, links, etc. | [Documentation](https://github.com/thephpleague/commonmark/blob/master/src/Extension/InlinesOnly/README.md) |
| `SmartPunctExtension` | Intelligently converts ASCII quotes, dashes, and ellipses to their fancy Unicode equivalents | [Documentation](https://github.com/thephpleague/commonmark/blob/master/src/Extension/SmartPunct/README.md) |
11 changes: 10 additions & 1 deletion src/Block/Renderer/ListItemRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\ListItem;
use League\CommonMark\Block\Element\Paragraph;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\Extension\TaskList\TaskListItemMarker;
colinodell marked this conversation as resolved.
Show resolved Hide resolved
use League\CommonMark\HtmlElement;

final class ListItemRenderer implements BlockRendererInterface
Expand All @@ -35,7 +37,7 @@ public function render(AbstractBlock $block, ElementRendererInterface $htmlRende
}

$contents = $htmlRenderer->renderBlocks($block->children(), $inTightList);
if (\substr($contents, 0, 1) === '<') {
if (\substr($contents, 0, 1) === '<' && !$this->startsTaskListItem($block)) {
$contents = "\n" . $contents;
}
if (\substr($contents, -1, 1) === '>') {
Expand All @@ -48,4 +50,11 @@ public function render(AbstractBlock $block, ElementRendererInterface $htmlRende

return $li;
}

private function startsTaskListItem(ListItem $block): bool
{
$firstChild = $block->firstChild();

return $firstChild instanceof Paragraph && $firstChild->firstChild() instanceof TaskListItemMarker;
}
}
9 changes: 9 additions & 0 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use League\CommonMark\Event\AbstractEvent;
use League\CommonMark\Extension\CommonMarkCoreExtension;
use League\CommonMark\Extension\ExtensionInterface;
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
use League\CommonMark\Inline\Parser\InlineParserInterface;
use League\CommonMark\Inline\Renderer\InlineRendererInterface;
use League\CommonMark\Util\Configuration;
Expand Down Expand Up @@ -354,6 +355,14 @@ public static function createCommonMarkEnvironment(): Environment
return $environment;
}

public static function createGFMEnvironment(): EnvironmentInterface
{
$environment = self::createCommonMarkEnvironment();
$environment->addExtension(new GithubFlavoredMarkdownExtension());

return $environment;
}

/**
* {@inheritdoc}
*/
Expand Down
25 changes: 25 additions & 0 deletions src/Extension/Autolink/AutolinkExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace League\CommonMark\Extension\Autolink;

use League\CommonMark\ConfigurableEnvironmentInterface;
use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Extension\ExtensionInterface;

final class AutolinkExtension implements ExtensionInterface
{
public function register(ConfigurableEnvironmentInterface $environment)
{
$environment->addEventListener(DocumentParsedEvent::class, new EmailAutolinkProcessor());
$environment->addEventListener(DocumentParsedEvent::class, new UrlAutolinkProcessor());
}
}
78 changes: 78 additions & 0 deletions src/Extension/Autolink/EmailAutolinkProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace League\CommonMark\Extension\Autolink;

use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Inline\Element\Link;
use League\CommonMark\Inline\Element\Text;

final class EmailAutolinkProcessor
{
const REGEX = '/([A-Za-z0-9.\-_+]+@[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_.]+)/';

/**
* @param DocumentParsedEvent $e
*
* @return void
*/
public function __invoke(DocumentParsedEvent $e)
{
$walker = $e->getDocument()->walker();

while ($event = $walker->next()) {
$node = $event->getNode();
if ($node instanceof Text && !($node->parent() instanceof Link)) {
self::processAutolinks($node);
}
}
}

private static function processAutolinks(Text $node)
{
$contents = \preg_split(self::REGEX, $node->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE);

if ($contents === false || \count($contents) === 1) {
return;
}

$leftovers = '';
foreach ($contents as $i => $content) {
if ($i % 2 === 0) {
$text = $leftovers . $content;
if ($text !== '') {
$node->insertBefore(new Text($leftovers . $content));
}

$leftovers = '';
continue;
}

// Does the URL end with punctuation that should be stripped?
if (\substr($content, -1) === '.') {
// Add the punctuation later
$content = \substr($content, 0, -1);
$leftovers = '.';
}

// The last character cannot be - or _
if (\in_array(\substr($content, -1), ['-', '_'])) {
$node->insertBefore(new Text($content . $leftovers));
$leftovers = '';
continue;
}

$node->insertBefore(new Link('mailto:' . $content, $content));
}

$node->detach();
}
}
Loading