{"id":23092637,"url":"https://github.com/kjdev/php-ext-hoedown","last_synced_at":"2025-08-16T10:31:11.633Z","repository":{"id":15430170,"uuid":"18162705","full_name":"kjdev/php-ext-hoedown","owner":"kjdev","description":"PHP Extension for Hoedown","archived":false,"fork":false,"pushed_at":"2020-10-23T03:14:17.000Z","size":136,"stargazers_count":16,"open_issues_count":2,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-18T00:52:33.729Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kjdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-27T03:04:23.000Z","updated_at":"2020-10-25T05:01:27.000Z","dependencies_parsed_at":"2022-08-26T05:51:13.985Z","dependency_job_id":null,"html_url":"https://github.com/kjdev/php-ext-hoedown","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjdev%2Fphp-ext-hoedown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjdev%2Fphp-ext-hoedown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjdev%2Fphp-ext-hoedown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjdev%2Fphp-ext-hoedown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kjdev","download_url":"https://codeload.github.com/kjdev/php-ext-hoedown/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230029150,"owners_count":18161990,"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-12-16T21:35:31.635Z","updated_at":"2024-12-16T21:35:32.344Z","avatar_url":"https://github.com/kjdev.png","language":"PHP","readme":"# PHP Extension for Hoedown\n\n[![Build Status](https://secure.travis-ci.org/kjdev/php-ext-hoedown.png?branch=master)](http://travis-ci.org/kjdev/php-ext-hoedown)\n\nThis extension allows Hoedown.\n\n## Requirement\n\n* PHP 5.3 +\n\n## Build\n\n```\n% git clone --recursive --depth=1 https://github.com/kjdev/php-ext-hoedown.git\n% cd php-ext-hoedown\n% phpize\n% ./configure\n% make\n% make test\n% make install\n```\n\n## Configuration\n\nhoedown.ini:\n\n```\nextension=hoedown.so\n; hoedown.options=tables,fenced-code,autolink,strikethrough,no-intra-emphasis\n```\n\n## Usage\n\n```php\n$hoedown = new Hoedown;\necho $hoedown-\u003eparse('markdown text');\n```\n\n## Runtime Configuration\n\nName            | Default                                                     | Changeable\n--------------- | ----------------------------------------------------------- | ----------\nhoedown.options | tables,fenced-code,autolink,strikethrough,no-intra-emphasis | PHP\\_INI\\_ALL\n\n\n* hoedown.options\n\n  Set the options for default of Hoedown class.\n  (set in the constructor before calling)\n\n  * Hoedown::TABLES\n  * Hoedown::FENCED\\_CODE\n  * Hoedown::AUTOLINK\n  * Hoedown::STRIKETHROUGH\n  * Hoedown::NO\\_INTRA\\_EMPHASIS\n\n## Class synopsis\n\n```\nHoedown {\n  public __construct(array $options = [])\n  public mixed getOption(int $option)\n  public bool setOption(int $option, mixed $value)\n  public void setOptions(array $options = [])\n  public bool addRender(string $name, callable $callback)\n  public array getRenders(void)\n  public string parse(string $string, mixed \u0026$state = NULL)\n  public string parseString(string $string, mixed \u0026$state = NULL)\n  public string parseFile(string $filename, mixed \u0026$state = NULL)\n  static public string ofString(string $string, array $options = [], mixed \u0026$state = NULL)\n  static public string ofFile(string $filename, array $options = [], mixed \u0026$state = NULL)\n}\n```\n\n### Predefined Constants\n\nName                             | Type   | Default | Description\n-------------------------------- | -----  | ------- | -----------\nHoedown::RENDERER\\_HTML          | bool   | TRUE    | Render HTML.\nHoedown::RENDERER\\_TOC           | bool   | FALSE   | Render the Table of Contents in HTML.\nHoedown::SKIP\\_HTML              | bool   | FALSE   | Strip all HTML tags.\nHoedown::HARD\\_WRAP              | bool   | FALSE   | Render each linebreak as \\\u003cbr\\\u003e.\nHoedown::USE\\_XHTML              | bool   | FALSE   | Render XHTML.\nHoedown::ESCAPE                  | bool   | FALSE   | Escaple all HTML.\nHoedown::USE\\_TASK\\_LIST         | bool   | FALSE   | Render task lists.\nHoedown::LINE\\_CONTINUE          | bool   | FALSE   | Render line continue.\nHoedown::HEADER\\_ID              | bool   | FALSE   | Render header id.\nHoedown::FENCED\\_CODE\\_SCRIPT    | bool   | FALSE   | Render script of fenced code blocks style.\nHoedown::TABLES                  | bool   | TRUE    | Parse PHP-Markdown style tables.\nHoedown::FENCED\\_CODE            | bool   | TRUE    | Parse fenced code blocks.\nHoedown::FOOTNOTES               | bool   | FALSE   | Parse footnotes.\nHoedown::AUTOLINK                | bool   | TRUE    | Automatically turn URLs into links.\nHoedown::STRIKETHROUGH           | bool   | TRUE    | Parse `~~strikethrough~~` spans.\nHoedown::UNDERLINE               | bool   | FALSE   | Parse `_underline_` instead of emphasis.\nHoedown::HIGHLIGHT               | bool   | FALSE   | Parse `==hightlight==` spans.\nHoedown::QUOTE                   | bool   | FALSE   | Render \"quotes\" as \\\u003cq\\\u003e.\nHoedown::SUPERSCRIPT             | bool   | FALSE   | Parse super\\^script.\nHoedown::NO\\_INTRA\\_EMPHASIS     | bool   | TRUE    | Disable emphasis\\_between\\_words.\nHoedown::SPACE\\_HEADERS          | bool   | FALSE   | Requqire a space after '#' in headers.\nHoedown::DISABLE\\_INDENTED\\_CODE | bool   | FALSE   | Don't parse indented code blocks.\nHoedown::SPECIAL\\_ATTRIBUTE      | bool   | FALSE   | Parse special attributes.\nHoedown::SCRIPT\\_TAGS            | bool   | FALSE   | Parse script tags `\u003c?..?\u003e`.\nHoedown::META\\_BLOCK             | bool   | FALSE   | Parse meta block `\u003c!--*..*--\u003e`.\nHoedown::TOC                     | bool   | FALSE   | Produce links to the Table of Contents.\nHoedown::TOC\\_BEGIN              | int    | 0       | Begin level for headers included in the TOC.\nHoedown::TOC\\_END                | int    | 6       | End level for headers included in the TOC.\nHoedown::TOC\\_HEADER             | string | \"\"      | Render header in the TOC.\nHoedown::TOC\\_FOOTER             | string | \"\"      | Render footer in the TOC.\n\n### Methods\n\n* [Hoedown::\\_\\_construct](#hoedown__construct) - Create a Hoedown instance\n* [Hoedown::getOption](#hoedowngetoption) - Retrieve a Hoedown option value\n* [Hoedown::setOption](#hoedownsetoption) - Set Hoedown option\n* [Hoedown::setOptions](#hoedownsetoptions) - Set Hoedown options\n* [Hoedown::parse](#hoedownparse) - retrieve html by parse string as markdown\n* [Hoedown::parseString](#hoedownparsestring) - retrieve html by parse string as markdown\n* [Hoedown::parseFile](#hoedownparsefile) - retrieve html by parse file as markdown\n* [Hoedown::ofString](#hoedownofstring) - retrieve html by parse string as markdown\n* [Hoedown::ofFile](#hoedownoffile) - retrieve html by parse file as markdown\n* [Hoedown::addRender](#hoedownaddrender) - Set Hoedown renderer function\n* [Hoedown::getRenders](#hoedowngetrenders) - retrieve renderer function\n\n---\n\n### Hoedown::\\_\\_construct\n\n```php\npublic __construct(array $options = [])\n```\n\nCreate a Hoedown instance.\n\n**Parameters:**\n\n* options\n\n  An associative array of options where the key is the option to set and the\n  value is the new value for the option.\n\n**Return Values:**\n\nReturns a new Hoedown object\n\n---\n\n### Hoedown::getOption\n\n```php\npublic mixed getOption(int $option)\n```\n\nRetrieve a Hoedown option value.\n\n**Parameters:**\n\n* option\n\n  One of the Hoedown::* constants.\n\n**Return Values:**\n\nReturns the value of the requested option, or FALSE on error.\n\n---\n\n### Hoedown::setOption\n\n```php\npublic bool setOption(int $option, mixed $value)\n```\n\nSet Hoedown option.\n\n**Parameters:**\n\n* option\n\n  One of the Hoedown::* constants.\n\n* value\n\n  Set option value.\n\n**Return Values:**\n\nReturns TRUE on success or FALSE on failure.\n\n---\n\n### Hoedown::setOptions\n\n```php\npublic void setOptions(array $options = [])\n```\n\nSet Hoedown options.\n\n**Parameters:**\n\n* options\n\n  An associative array of options where the key is the option to set and the\n  value is the new value for the option.\n\n---\n\n### Hoedown::parse\n\n```php\npublic string parse(string $string, mixed \u0026$state = NULL)\n```\n\nretrieve html by parse text as markdown.\n\n**Parameters:**\n\n* string\n\n  Markdown text string.\n\n* state\n\n  Returns the value of extend parse.\n\n**Return Values:**\n\nReturns the retrieve html, or FALSE on error.\n\n---\n\n### Hoedown::parseString\n\n```php\npublic string parseString(string $string, mixed \u0026$state = NULL)\n```\n\nretrieve html by parse string as markdown.\n\nalias: [Hoedown::parse](#hoedownparse)\n\n---\n\n### Hoedown::parseFile\n\n```php\npublic string parseFile(string $filename, mixed \u0026$state = NULL)\n```\n\nretrieve html by parse file as markdown.\n\n**Parameters:**\n\n* filename\n\n  Markdown file name.\n\n* state\n\n  Returns the value of extend parse.\n\n**Return Values:**\n\nReturns the retrieve html, or FALSE on error.\n\n---\n\n### Hoedown::ofString\n\n```php\nstatic public string ofString(string $string, array $options = [], mixed \u0026$state = NULL)\n```\n\nretrieve html by parse string as markdown (static method).\n\n**Parameters:**\n\n* string\n\n  Markdown text string.\n\n* options\n\n  An associative array of options where the key is the option to set and the\n  value is the new value for the option.\n\n* state\n\n  Returns the value of extend parse.\n\n**Return Values:**\n\nReturns the retrieve html, or FALSE on error.\n\n---\n\n### Hoedown::ofFile\n\n```php\nstatic public string ofFile(string $filename, array $options = [], mixed \u0026$state = NULL)\n```\n\nretrieve html by parse file as markdown (static method).\n\n**Parameters:**\n\n* filename\n\n  Markdown file name.\n\n* options\n\n  An associative array of options where the key is the option to set and the\n  value is the new value for the option.\n\n* state\n\n  Returns the value of extend parse.\n\n**Return Values:**\n\nReturns the retrieve html, or FALSE on error.\n\n---\n\n### Hoedown::addRender\n\n```php\npublic bool addRender(string $name, callable $callback)\n```\n\nSet Hoedown renderer function.\n\n**Parameters:**\n\n* name\n\n  Hoedown rederer function name.\n\n* callback\n\n  The callable to be called.\n\n**Return Values:**\n\nReturns TRUE on success or FALSE on failure.\n\n---\n\n### Hoedown::getRenders\n\n```php\npublic array getRenders(void)\n```\n\nretrieve renderer function.\n\n**Return Values:**\n\nReturns the retrieve renderer functions, or NULL.\n\n\n## Examples\n\n* Setting a Hoedown option\n\n```php\n$hoedown = new Hoedown;\n$hoedown-\u003esetOption(Hoedown::USE_XHTML, true);\n$hoedown-\u003esetOption(Hoedown::HARD_WRAP, true);\n// or $hoedown-\u003esetOptions([Hoedown::USE_XHTML =\u003e true, Hoedown::HARD_WRAP =\u003e true]);\n// or new Hoedown([Hoedown::USE_XHTML =\u003e true, Hoedown::HARD_WRAP =\u003e true]);\necho $hoedown-\u003eparse(\"markdown\\ntext\");\n```\n\nThe above example will output:\n\n```\n\u003cp\u003emarkdown\u003cbr/\u003e\ntext\u003c/p\u003e\n```\n\n* Retrieve the Table of Contents\n\n```php\n$hoedown = new Hoedown;\n$hoedown-\u003esetOption(Hoedown::TOC, true);\necho $hoedown-\u003eparse(\"# header\\n##a\\n##b\", $state);\necho \"-- Table of Contents --\\n\";\necho $state['toc'];\n```\n\nThe above example will output:\n\n```\n\u003ch1 id=\"header\"\u003eheader\u003c/h1\u003e\n\n\u003ch2 id=\"a\"\u003ea\u003c/h2\u003e\n\n\u003ch2 id=\"b\"\u003eb\u003c/h2\u003e\n-- Table of Contents --\n\u003cul\u003e\n\u003cli\u003e\n\u003ca href=\"#header\"\u003eheader\u003c/a\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003ca href=\"#a\"\u003ea\u003c/a\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003ca href=\"#b\"\u003eb\u003c/a\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n```\n\nOnly retrieve the Table of Contents.\n\n```php\n$hoedown = new Hoedown;\n$hoedown-\u003esetOption(Hoedown::TOC, true);\n$hoedown-\u003esetOption(Hoedown::RENDERER_TOC, true);\necho $hoedown-\u003eparse(\"# header\\n##a\\n##b\");\n```\n\nThe above example will output:\n\n```\n\u003cul\u003e\n\u003cli\u003e\n\u003ca href=\"#header\"\u003eheader\u003c/a\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003ca href=\"#a\"\u003ea\u003c/a\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003ca href=\"#b\"\u003eb\u003c/a\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n## HTML render\n\n```php\n$hoedown = new Hoedown;\n\n$hoedown-\u003eaddRender('blockcode', function($text, $lang, $attr) {\n        // Use Pygmentize\n        return Pygmentize::highlight($text, $lang);\n    });\n\n// or\n// function blockCode($text, $lang, $attr) {\n//     return Pygmentize::highlight($text, $lang);\n// }\n// $hoedown-\u003eaddRender('blockcode', 'blockCode');\n\n// or\n// $hoedown-\u003esetOption(Hoedown::RENDERS, [\n//                         'blockcode' =\u003e function($text, $lang, $attr) {\n//                             return Pygmentize::highlight($text, $lang);\n//                         }]);\n\necho $hoedown-\u003eparse(\"...markdown string...\");\n```\n\nRender functions:\n\n* blockcode($text, $lang, $attr)\n* blockquote($text)\n* blockhtml($text)\n* paragraph($text)\n* header($text, $attr, $level)\n* hrule()\n* list($text, $attr, $flags)\n* listitem($text, $attr, $flags)\n* table($text, $attr)\n* tableheader($text)\n* tablebody($text)\n* tablerow($text)\n* tablecell($text, $flags)\n* footnotes($text)\n* footnotedef($text, $num)\n* footnoteref($num)\n* codespan($text, $attr)\n* underline($text)\n* highlight($text)\n* quote($text)\n* strikethrough($text)\n* superscript($text)\n* emphasis($text)\n* doubleemphasis($text)\n* tripleemphasis($text)\n* autolink($link, $type)\n* image($link, $title, $alt, $attr)\n* link($content, $link, $title, $attr)\n* linebreak()\n* rawhtmltag($tag)\n* entity($entity)\n* normaltext($text)\n* userblock($text)\n\n## User block\n\nsimple php code.\n\n```php\n$hoedown = new Hoedown;\n\n$hoedown-\u003esetOption(Hoedown::USER_BLOCK, function($text) {\n        // Returns the value of user block length\n        if (preg_match('/^\u003c\\?php.*\\?\u003e/is', $text, $matches)) {\n            return strlen($matches[0]);\n        }\n        return 0;\n    });\n\necho $hoedown-\u003eparse(\"\u003c?php echo 'test'; ?\u003e\"), PHP_EOL;\n\n$hoedown-\u003esetOption(Hoedown::RENDERS, ['userblock' =\u003e function($text) {\n            ob_start();\n            eval(substr($text, 5, -2));\n            $retval = ob_get_contents();\n            ob_end_clean();\n            return $retval;\n        }]);\n\necho $hoedown-\u003eparse(\"\u003c?php echo 'test'; ?\u003e\"), PHP_EOL;\n```\n\noutput:\n\n```\n\u003c?php echo \"test\"; ?\u003e\ntest\n```\n\n## Meta block\n\nAdd the `Hoedown::META_BLOCK` to options.\n\nGet a meta block by running in the following program.\n\n```php\n$text = \u003c\u003c\u003cEOT\n\u003c!--*\n  author: user\n  title: Welcom to use\n  tags: [ markdown, metadata ]\n*--\u003e\ntest\nEOT;\n\n$hoedown = new Hoedown;\n\n$hoedown-\u003esetOption(Hoedown::META_BLOCK, true);\n\necho $hoedown-\u003eparse($text, $meta), PHP_EOL;\n\nvar_dump($meta);\n```\n\noutput:\n\n```\n\u003cp\u003etest\u003c/p\u003e\n\narray(1) {\n  [\"meta\"]=\u003e\n  string(69) \"  author: user\n  title: Welcom to use\n  tags: [ markdown, metadata ]\n\"\n}\n```\n\n* Parse meta block\n\nSet the `Hoedown::META_PARSE` function to options.\n\n```php\n$text = \u003c\u003c\u003cEOT\n\u003c!--*\n  author: user\n  title: Welcom to use\n  tags: [ markdown, metadata ]\n*--\u003e\ntest\nEOT;\n\n$hoedown = new Hoedown;\n\n$hoedown-\u003esetOption(Hoedown::META_BLOCK, true);\n$hoedown-\u003esetOption(Hoedown::META_PARSE, function($text) {\n    return yaml_parse($text);\n});\n\necho $hoedown-\u003eparse($text, $meta), PHP_EOL;\n\nvar_dump($meta);\n```\n\noutput:\n\n```\n\u003cp\u003etest\u003c/p\u003e\n\narray(1) {\n  [\"meta\"]=\u003e\n  array(3) {\n    [\"author\"]=\u003e\n    string(4) \"user\"\n    [\"title\"]=\u003e\n    string(13) \"Welcom to use\"\n    [\"tags\"]=\u003e\n    array(2) {\n      [0]=\u003e\n      string(8) \"markdown\"\n      [1]=\u003e\n      string(8) \"metadata\"\n    }\n  }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkjdev%2Fphp-ext-hoedown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkjdev%2Fphp-ext-hoedown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkjdev%2Fphp-ext-hoedown/lists"}