{"id":13514825,"url":"https://github.com/michelf/php-markdown","last_synced_at":"2025-05-13T00:05:54.100Z","repository":{"id":41094908,"uuid":"706295","full_name":"michelf/php-markdown","owner":"michelf","description":"Parser for Markdown and Markdown Extra derived from the original Markdown.pl by John Gruber.","archived":false,"fork":false,"pushed_at":"2024-06-06T15:37:10.000Z","size":828,"stargazers_count":3441,"open_issues_count":103,"forks_count":529,"subscribers_count":139,"default_branch":"lib","last_synced_at":"2025-05-13T00:05:47.279Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://michelf.ca/projects/php-markdown/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michelf.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-06-06T17:48:42.000Z","updated_at":"2025-05-08T02:05:50.000Z","dependencies_parsed_at":"2022-07-30T21:38:09.912Z","dependency_job_id":"393a3b52-1601-4477-8cad-00f704276ebd","html_url":"https://github.com/michelf/php-markdown","commit_stats":{"total_commits":389,"total_committers":56,"mean_commits":6.946428571428571,"dds":"0.35732647814910024","last_synced_commit":"eb176f173fbac58a045aff78e55f833264b34e71"},"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michelf%2Fphp-markdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michelf%2Fphp-markdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michelf%2Fphp-markdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michelf%2Fphp-markdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michelf","download_url":"https://codeload.github.com/michelf/php-markdown/tar.gz/refs/heads/lib","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843215,"owners_count":21972873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T05:01:02.336Z","updated_at":"2025-05-13T00:05:54.075Z","avatar_url":"https://github.com/michelf.png","language":"PHP","readme":"PHP Markdown\n============\n\n![ci.yml](https://github.com/michelf/php-markdown/actions/workflows/ci.yml/badge.svg)\n\nby Michel Fortin  \n\u003chttps://michelf.ca/\u003e\n\nbased on Markdown by John Gruber  \n\u003chttps://daringfireball.net/\u003e\n\n\nIntroduction\n------------\n\nThis is a library package that includes the PHP Markdown parser and its\nsibling PHP Markdown Extra with additional features.\n\nMarkdown is a text-to-HTML conversion tool for web writers. Markdown\nallows you to write using an easy-to-read, easy-to-write plain text\nformat, then convert it to structurally valid XHTML (or HTML).\n\n\"Markdown\" is actually two things: a plain text markup syntax, and a\nsoftware tool, originally written in Perl, that converts the plain text\nmarkup to HTML. PHP Markdown is a port to PHP of the original Markdown\nprogram by John Gruber.\n\n*\t[Full documentation of the Markdown syntax](\u003chttps://daringfireball.net/projects/markdown/\u003e)  \n\t— Daring Fireball (John Gruber)\n*\t[Markdown Extra syntax additions](\u003chttps://michelf.ca/projects/php-markdown/extra/\u003e)  \n\t— Michel Fortin\n\n\nRequirement\n-----------\n\nThis library package requires PHP 7.4 or later.\n\nNote: The older plugin/library hybrid package for PHP Markdown and\nPHP Markdown Extra is no longer maintained but will work with PHP 4.0.5 and\nlater.\n\nYou might need to set pcre.backtrack_limit higher than 1 000 000 \n(the default), though the default is usually fine.\n\n\nUsage\n-----\n\nTo use this library with Composer, first install it with:\n\n\t$ composer require michelf/php-markdown\n\nThen include Composer's generated vendor/autoload.php to [enable autoloading]:\n\n\trequire 'vendor/autoload.php';\n\nWithout Composer, for autoloading to work, your project needs an autoloader\ncompatible with PSR-4 or PSR-0. See the included Readme.php file for a minimal\nautoloader setup. (If you cannot use autoloading, see below.)\n\nWith class autoloading in place:\n\n\tuse Michelf\\Markdown;\n\t$my_html = Markdown::defaultTransform($my_text);\n\nMarkdown Extra syntax is also available the same way:\n\n\tuse Michelf\\MarkdownExtra;\n\t$my_html = MarkdownExtra::defaultTransform($my_text);\n\nIf you wish to use PHP Markdown with another text filter function\nbuilt to parse HTML, you should filter the text *after* the `transform`\nfunction call. This is an example with [PHP SmartyPants]:\n\n\tuse Michelf\\Markdown, Michelf\\SmartyPants;\n\t$my_html = Markdown::defaultTransform($my_text);\n\t$my_html = SmartyPants::defaultTransform($my_html);\n\nAll these examples are using the static `defaultTransform` static function\nfound inside the parser class. If you want to customize the parser\nconfiguration, you can also instantiate it directly and change some\nconfiguration variables:\n\n\tuse Michelf\\MarkdownExtra;\n\t$parser = new MarkdownExtra;\n\t$parser-\u003efn_id_prefix = \"post22-\";\n\t$my_html = $parser-\u003etransform($my_text);\n\nTo learn more, see the full list of [configuration variables].\n\n [enable autoloading]: https://getcomposer.org/doc/01-basic-usage.md#autoloading\n [PHP SmartyPants]: https://michelf.ca/projects/php-smartypants/\n [configuration variables]: https://michelf.ca/projects/php-markdown/configuration/\n\n\n### Usage without an autoloader\n\nIf you cannot use class autoloading, you can still use `include` or `require`\nto access the parser. To load the `Michelf\\Markdown` parser, do it this way:\n\n\trequire_once 'Michelf/Markdown.inc.php';\n\nOr, if you need the `Michelf\\MarkdownExtra` parser:\n\n\trequire_once 'Michelf/MarkdownExtra.inc.php';\n\nWhile the plain `.php` files depend on autoloading to work correctly, using the\n`.inc.php` files instead will eagerly load the dependencies that would be\nloaded on demand if you were using autoloading.\n\n\nPublic API and Versioning Policy\n---------------------------------\n\nVersion numbers are of the form *major*.*minor*.*patch*.\n\nThe public API of PHP Markdown consist of the two parser classes `Markdown`\nand `MarkdownExtra`, their constructors, the `transform` and `defaultTransform`\nfunctions and their configuration variables. The public API is stable for\na given major version number. It might get additions when the minor version\nnumber increments.\n\n**Protected members are not considered public API.** This is unconventional\nand deserves an explanation. Incrementing the major version number every time\nthe underlying implementation of something changes is going to give\nnonessential version numbers for the vast majority of people who just use the\nparser.  Protected members are meant to create parser subclasses that behave in\ndifferent ways. Very few people create parser subclasses. I don't want to\ndiscourage it by making everything private, but at the same time I can't\nguarantee any stable hook between versions if you use protected members.\n\n**Syntax changes** will increment the minor number for new features, and the\npatch number for small corrections. A *new feature* is something that needs a\nchange in the syntax documentation. Note that since PHP Markdown Lib includes\ntwo parsers, a syntax change for either of them will increment the minor\nnumber. Also note that there is nothing perfectly backward-compatible with the\nMarkdown syntax: all inputs are always valid, so new features always replace\nsomething that was previously legal, although generally nonsensical to do.\n\n\nBugs\n----\n\nTo file bug reports please send email to:\n\u003cmichel.fortin@michelf.ca\u003e\n\nPlease include with your report: (1) the example input; (2) the output you\nexpected; (3) the output PHP Markdown actually produced.\n\nIf you have a problem where Markdown gives you an empty result, first check\nthat the backtrack limit is not too low by running `php --info | grep pcre`.\nSee Installation and Requirement above for details.\n\n\nDevelopment and Testing\n-----------------------\n\nPull requests for fixing bugs are welcome. Proposed new features are\ngoing to be meticulously reviewed -- taking into account backward compatibility,\npotential side effects, and future extensibility -- before deciding on\nacceptance or rejection.\n\nIf you make a pull request that includes changes to the parser please add\ntests for what is being changed to the `test/` directory. This can be as\nsimple as adding a `.text` (input) file with a corresponding `.xhtml`\n(output) file to proper category under `./test/resources/`.\n\nTraditionally tests were in a separate repository, [MDTest](https://github.com/michelf/mdtest)\nbut they are now located here, alongside the source code.\n\n\nDonations\n---------\n\nIf you wish to make a donation that will help me devote more time to\nPHP Markdown, please visit [michelf.ca/donate].\n\n [michelf.ca/donate]: https://michelf.ca/donate/#!Thanks%20for%20PHP%20Markdown\n\n\nVersion History\n---------------\n\nPHP Markdown Lib 2.0.0 (26 Sep 2022)\n\n*\tNow requiring PHP version 7.4 or later.\n\n*\tAdded type annotations to configuration properties of the parser.\n\t(Thanks to Tac Tacelosky.)\n\n*\tFixing a TypeError in PHP 8 caused by invalid counter variable.\n\t(Thanks to Alexey Kopytko.)\n\t\n*\tComposer package now excludes development files.\n\t(Thanks to Cédric Anne.)\n\t\n\nPHP Markdown Lib 1.9.1 (23 Nov 2021)\n\n*\tNow treating `\u003cdetails\u003e` and `\u003csummary\u003e` as block level so they don't\n\tget wrapped in `\u003cp\u003e`.\n\t(Thanks to Thomas Hochstein for the fix.)\n\n*\tFix for unintended blank title attribute when adding supplementary attributes\n\tto a link in Markdown Extra.\n\t(Thanks to Richie Black for the fix.)\n\n\nPHP Markdown Lib 1.9.0 (1 Dec 2019)\n\n*\tAdded `fn_backlink_label` configuration variable to put some text in the\n\t`aria-label` attribute.\n\t(Thanks to Sunny Walker for the implementation.)\n\n*\tOccurances of \"`^^`\" in `fn_backlink_html`, `fn_backlink_class`,\n\t`fn_backlink_title`, and `fn_backlink_label` will be replaced by the \n\tcorresponding footnote number in the HTML output. Occurances of \"`%%`\" will be \n\treplaced by a number for the reference (footnotes can have multiple references).\n\t(Thanks to Sunny Walker for the implementation.)\n\n*\tAdded configuration variable `omit_footnotes`. When `true` footnotes are not\n\tappended at the end of the generated HTML and the `footnotes_assembled`\n\tvariable will contain the HTML for the footnote list, allowing footnotes to be\n\tmoved somewhere else on the page.\n\t(Thanks to James K. for the implementation.)\n\n\tNote: when placing the content of `footnotes_assembled` on the page, consider\n\tadding the attribute `role=\"doc-endnotes\"` to the `\u003cdiv\u003e` or `\u003csection\u003e` that will\n\tenclose the list of footnotes so they are reachable to accessibility tools the\n\tsame way they would be with the default HTML output.\n\t\n*\tFixed deprecation warnings from PHP about usage of curly braces to access\n\tcharacters in text strings.\n\t(Thanks to Remi Collet and Frans-Willem Post.)\n\n\nPHP Markdown Lib 1.8.0 (14 Jan 2018)\n\n*\tAutoloading with Composer now uses PSR-4.\n\n*\tHTML output for Markdown Extra footnotes now include `role` attributes\n\twith values from [WAI-ARIA](https://www.w3.org/TR/dpub-aria/) to\n\tmake them more accessible.\n\t(Thanks to Tobias Bengfort)\n\n*\tIn Markdown Extra, added the `hashtag_protection` configuration variable.\n\tWhen set to `true` it prevents ATX-style headers with no space after the initial\n\thash from being interpreted as headers. This way your precious hashtags\n\tare preserved.\n\t(Thanks to Jaussoin Timothée for the implementation.)\n\n\nPHP Markdown Lib 1.7.0 (29 Oct 2016)\n\n*\tAdded a `hard_wrap` configuration variable to make all newline characters\n\tin the text become `\u003cbr\u003e` tags in the HTML output. By default, according\n\tto the standard Markdown syntax these newlines are ignored unless they a\n\tpreceded by two spaces. Thanks to Jonathan Cohlmeyer for the implementation.\n\n*\tImproved the parsing of list items to fix problematic cases that came to\n\tlight with the addition of `hard_wrap`. This should have no effect on the\n\toutput except span-level list items that ended with two spaces (and thus\n\tended with a line break).\n\n*\tAdded a `code_span_content_func` configuration variable which takes a\n\tfunction that will convert the content of the code span to HTML. This can\n\tbe useful to implement syntax highlighting. Although contrary to its\n\tcode block equivalent, there is no syntax for specifying a language.\n\tCredits to styxit for the implementation.\n\n*\tFixed a Markdown Extra issue where two-space-at-end-of-line hard breaks\n\twouldn't work inside of HTML block elements such as `\u003cp markdown=\"1\"\u003e`\n\twhere the element expects only span-level content.\n\n*\tIn the parser code, switched to PHPDoc comment format. Thanks to\n\tRobbie Averill for the help.\n\n\nPHP Markdown Lib 1.6.0 (23 Dec 2015)\n\nNote: this version was incorrectly released as 1.5.1 on Dec 22, a number\nthat contradicted the versioning policy.\n\n*\tFor fenced code blocks in Markdown Extra, can now set a class name for the\n\tcode block's language before the special attribute block. Previously, this\n\tclass name was only allowed in the absence of the special attribute block.\n\n*\tAdded a `code_block_content_func` configuration variable which takes a\n\tfunction that will convert the content of the code block to HTML. This is\n\tmost useful for syntax highlighting. For fenced code blocks in Markdown\n\tExtra, the function has access to the language class name (the one outside\n\tof the special attribute block). Credits to Mario Konrad for providing the\n\timplementation.\n\n*\tThe curled arrow character for the backlink in footnotes is now followed\n\tby a Unicode variant selector to prevent it from being displayed in emoji\n\tform on iOS.\n\n\tNote that in older browsers the variant selector is often interpreted as a\n\tseparate character, making it visible after the arrow. So there is now a\n\talso a `fn_backlink_html` configuration variable that can be used to set\n\tthe link text to something else. Credits to Dana for providing the\n\timplementation.\n\n*\tFixed an issue in MarkdownExtra where long header lines followed by a\n\tspecial attribute block would hit the backtrack limit an cause an empty\n\tstring to be returned.\n\n\nPHP Markdown Lib 1.5.0 (1 Mar 2015)\n\n*\tAdded the ability start ordered lists with a number different from 1 and\n\tand have that reflected in the HTML output. This can be enabled with\n\tthe `enhanced_ordered_lists` configuration variable for the Markdown\n\tparser; it is enabled by default for Markdown Extra.\n\tCredits to Matt Gorle for providing the implementation.\n\n*\tAdded the ability to insert custom HTML attributes with simple values\n\teverywhere an extra attribute block is allowed (links, images, headers).\n\tThe value must be unquoted, cannot contains spaces and is limited to\n\talphanumeric ASCII characters.\n\tCredits to Peter Droogmans for providing the implementation.\n\n*\tAdded a `header_id_func` configuration variable which takes a function\n\tthat can generate an `id` attribute value from the header text.\n\tCredits to Evert Pot for providing the implementation.\n\n*\tAdded a `url_filter_func` configuration variable which takes a function\n\tthat can rewrite any link or image URL to something different.\n\n\nPHP Markdown Lib 1.4.1 (4 May 2014)\n\n*\tThe HTML block parser will now treat `\u003cfigure\u003e` as a block-level element\n\t(as it should) and no longer wrap it in `\u003cp\u003e` or parse it's content with\n\tthe as Markdown syntax (although with Extra you can use `markdown=\"1\"`\n\tif you wish to use the Markdown syntax inside it).\n\n*\tThe content of `\u003cstyle\u003e` elements will now be left alone, its content\n\twon't be interpreted as Markdown.\n\n*\tCorrected an bug where some inline links with spaces in them would not\n\twork even when surounded with angle brackets:\n\n\t\t[link](\u003cs p a c e s\u003e)\n\n*\tFixed an issue where email addresses with quotes in them would not always\n\thave the quotes escaped in the link attribute, causing broken links (and\n\tinvalid HTML).\n\n*\tFixed the case were a link definition following a footnote definition would\n\tbe swallowed by the footnote unless it was separated by a blank line.\n\n\nPHP Markdown Lib 1.4.0 (29 Nov 2013)\n\n*\tAdded support for the `tel:` URL scheme in automatic links.\n\n\t\t\u003ctel:+1-111-111-1111\u003e\n\n\tIt gets converted to this (note the `tel:` prefix becomes invisible):\n\n\t\t\u003ca href=\"tel:+1-111-111-1111\"\u003e+1-111-111-1111\u003c/a\u003e\n\n*\tAdded backtick fenced code blocks to MarkdownExtra, originally from\n\tGithub-Flavored Markdown.\n\n*\tAdded an interface called MarkdownInterface implemented by both\n\tthe Markdown and MarkdownExtra parsers. You can use the interface if\n\tyou want to create a mockup parser object for unit testing.\n\n*\tFor those of you who cannot use class autoloading, you can now\n\tinclude `Michelf/Markdown.inc.php` or `Michelf/MarkdownExtra.inc.php` (note\n\tthe \t`.inc.php` extension) to automatically include other files required\n\tby the parser.\n\n\nPHP Markdown Lib 1.3 (11 Apr 2013)\n\nThis is the first release of PHP Markdown Lib. This package requires PHP\nversion 5.3 or later and is designed to work with PSR-0 autoloading and,\noptionally with Composer. Here is a list of the changes since\nPHP Markdown Extra 1.2.6:\n\n*\tPlugin interface for WordPress and other systems is no longer present in\n\tthe Lib package. The classic package is still available if you need it:\n\t\u003chttps://michelf.ca/projects/php-markdown/classic/\u003e\n\n*\tAdded `public` and `protected` protection attributes, plus a section about\n\twhat is \"public API\" and what isn't in the Readme file.\n\n*\tChanged HTML output for footnotes: now instead of adding `rel` and `rev`\n\tattributes, footnotes links have the class name `footnote-ref` and\n\tbacklinks `footnote-backref`.\n\n*\tFixed some regular expressions to make PCRE not shout warnings about POSIX\n\tcollation classes (dependent on your version of PCRE).\n\n*\tAdded optional class and id attributes to images and links using the same\n\tsyntax as for headers:\n\n\t\t[link](url){#id .class}\n\t\t![img](url){#id .class}\n\n\tIt work too for reference-style links and images. In this case you need\n\tto put those attributes at the reference definition:\n\n\t\t[link][linkref] or [linkref]\n\t\t![img][linkref]\n\n\t\t[linkref]: url \"optional title\" {#id .class}\n\n*\tFixed a PHP notice message triggered when some table column separator\n\tmarkers are missing on the separator line below column headers.\n\n*\tFixed a small mistake that could cause the parser to retain an invalid\n\tstate related to parsing links across multiple runs. This was never\n\tobserved (that I know of), but it's still worth fixing.\n\n\nCopyright and License\n---------------------\n\nPHP Markdown Lib\nCopyright (c) 2004-2022 Michel Fortin\n\u003chttps://michelf.ca/\u003e  \nAll rights reserved.\n\nBased on Markdown  \nCopyright (c) 2003-2005 John Gruber  \n\u003chttps://daringfireball.net/\u003e  \nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n*   Redistributions of source code must retain the above copyright\n    notice, this list of conditions and the following disclaimer.\n\n*   Redistributions in binary form must reproduce the above copyright\n    notice, this list of conditions and the following disclaimer in the\n    documentation and/or other materials provided with the\n    distribution.\n\n*   Neither the name \"Markdown\" nor the names of its contributors may\n    be used to endorse or promote products derived from this software\n    without specific prior written permission.\n\nThis software is provided by the copyright holders and contributors \"as\nis\" and any express or implied warranties, including, but not limited\nto, the implied warranties of merchantability and fitness for a\nparticular purpose are disclaimed. In no event shall the copyright owner\nor contributors be liable for any direct, indirect, incidental, special,\nexemplary, or consequential damages (including, but not limited to,\nprocurement of substitute goods or services; loss of use, data, or\nprofits; or business interruption) however caused and on any theory of\nliability, whether in contract, strict liability, or tort (including\nnegligence or otherwise) arising in any way out of the use of this\nsoftware, even if advised of the possibility of such damage.\n","funding_links":[],"categories":["PHP","Markdown parser","标记","Table of Contents","目录","Libraries","Markup","标记( Markup )","类库","标记 Markup"],"sub_categories":["Markup","标记和CSS Markup and CSS","Markup and CSS","PHP","Markdown"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichelf%2Fphp-markdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichelf%2Fphp-markdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichelf%2Fphp-markdown/lists"}