{"id":25871138,"url":"https://github.com/gashmob/mdgen","last_synced_at":"2026-05-09T05:03:03.048Z","repository":{"id":58678170,"uuid":"530763863","full_name":"Gashmob/MdGen","owner":"Gashmob","description":"Markdown template engine","archived":true,"fork":false,"pushed_at":"2022-09-29T11:05:49.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-02T06:41:30.572Z","etag":null,"topics":["markdown","php","template"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gashmob.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"patreon":"gashmob"}},"created_at":"2022-08-30T17:37:36.000Z","updated_at":"2024-02-21T09:26:17.000Z","dependencies_parsed_at":"2022-09-06T06:40:16.265Z","dependency_job_id":null,"html_url":"https://github.com/Gashmob/MdGen","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Gashmob/MdGen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gashmob%2FMdGen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gashmob%2FMdGen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gashmob%2FMdGen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gashmob%2FMdGen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gashmob","download_url":"https://codeload.github.com/Gashmob/MdGen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gashmob%2FMdGen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32807861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["markdown","php","template"],"created_at":"2025-03-02T06:35:29.257Z","updated_at":"2026-05-09T05:03:03.032Z","avatar_url":"https://github.com/Gashmob.png","language":"PHP","funding_links":["https://patreon.com/gashmob"],"categories":[],"sub_categories":[],"readme":"# MdGen\n\n[![Tests](https://github.com/Gashmob/MdGen/actions/workflows/test.yml/badge.svg)](https://github.com/Gashmob/MdGen/actions/workflows/test.yml)\n[![wakatime](https://wakatime.com/badge/user/c1e2386d-065c-4366-b163-d98f957273dc/project/44c9d956-4bea-471c-8dc6-5752f533022a.svg)](https://wakatime.com/badge/user/c1e2386d-065c-4366-b163-d98f957273dc/project/44c9d956-4bea-471c-8dc6-5752f533022a)\n\nMarkdown template engine. This php library will generate html from markdown templates (`*.mdt` file).\n\n- [Usage](#usage)\n  - [Templates format](#templates-format)\n  - [Special](#special)\n    - [Base template](#base-template)\n    - [Include template](#include-template)\n    - [Scripting](#scripting)\n  - [Generate html](#generate-html)\n  - [Cache](#cache)\n- [Installation](#installation)\n\n## Usage\n\nLet see how to use MdGen. If you want some examples, you can go inside test dir, there is the template with the html\nresult.\n\n### Templates format\n\nFirst, there is all the format that you can use for your template and how it will be translated to html. Essentially\nit's markdown, but there is some difference :\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003eMdGen\u003c/th\u003e\u003cth\u003ehtml\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n# Title 1\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003ch1\u003eTitle 1\u003c/h1\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n## Title 2\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003ch2\u003eTitle 2\u003c/h2\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n### Title 3\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003ch3\u003eTitle 3\u003c/h3\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n#### Title 4\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003ch4\u003eTitle 4\u003c/h4\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n##### Title 5\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003ch5\u003eTitle 5\u003c/h5\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n###### Title 6\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003ch6\u003eTitle 6\u003c/h6\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\nSome text\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\nSome text\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n[Google](https://www.google.com)\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003ca href=\"https://www.google.com\"\u003eGoogle\u003c/a\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n![image](http://image.com/a.png)\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003cimg src=\"http://image.com/a.png\" alt=\"image\"/\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n**Bold**\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003cstrong\u003eBold\u003c/strong\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n*Italic*\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003cem\u003eItalic\u003c/em\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n1. First item\n2. Second item\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\n\u003col\u003e\n    \u003cli\u003eFirst item\u003c/li\u003e\n    \u003cli\u003eSecond item\u003c/li\u003e\n\u003c/ol\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n- First item\n- Second item\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\n\u003cul\u003e\n    \u003cli\u003eFirst item\u003c/li\u003e\n    \u003cli\u003eSecond item\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n---\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\n\u003chr/\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n`code`\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\u003ccode\u003ecode\u003c/code\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n```bash\necho \"Hello world\"\n\\```\n```\n\nWrite the end of code block without the backslash.\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\n\u003cpre\u003e\u003ccode class=\"language-bash\"\u003e\necho \"Hello world\"\n\u003c/code\u003e\u003c/pre\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n\u003e quote\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\n\u003cblockquote\u003e\n    quote\n\u003c/blockquote\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n| Col 1 | Col 2 | Col 3 |\n| :---- | :---: | ----: |\n| 1     |   2   |     3 |\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\n\u003ctable\u003e\n    \u003cthead\u003e\n    \u003ctr\u003e\n        \u003cth style=\"text-align:left;\"\u003e\n            Col 1\n        \u003c/th\u003e\n        \u003cth style=\"text-align:center;\"\u003e\n            Col 2\n        \u003c/th\u003e\n        \u003cth style=\"text-align:right;\"\u003e\n            Col 3\n        \u003c/th\u003e\n    \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n    \u003ctr\u003e\n        \u003ctd style=\"text-align:left;\"\u003e\n            1\n        \u003c/td\u003e\n        \u003ctd style=\"text-align:center;\"\u003e\n            2\n        \u003c/td\u003e\n        \u003ctd style=\"text-align:right;\"\u003e\n            3\n        \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n\u003cdiv\u003eSome html\u003c/div\u003e\n\u003cdiv\u003e# Title\u003c/div\u003e\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\n\n\u003cdiv\u003eSome html\u003c/div\u003e\n\u003cdiv\u003e# Title\u003c/div\u003e\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```md\n{foo}\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```html\nbar\n```\n\nReplace `{foo}` by the value given at the render function :\n\n```php\n$engine-\u003erender('myTemplate.mdt', [ \"foo\" =\u003e \"bar\" ])\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n### Special\n\nBut there is some another statements that can be used in your template.\n\nThe first of generation is pre-rendering. During these steps the library look at the first lines for a special\nstatement. These lines specify some values that the pre-render function should return. It will not appear in final html\ndocument. It works on a key value system :\n\n```md\n[#]: key -\u003e value\n```\n\nThe pre-render function will then return :\n\n```php\n[\n    \"key\" =\u003e \"value\",\n]\n```\n\n#### Base template\n\nFrequently your templates need the same base in html (same header, same footer, ...). For that you can add this\nstatement at the beginning of your template (after the key-value)\n\n```md\n[#]: base someTemplate\n```\n\nThe library will then look for the file `someTemplate.mdt` from where the template is located. You can override this by\nproviding a search path to the library :\n\n```php\n$engine-\u003ebasePath('someWhere/');\n```\n\nIn the file `someTemplate.mdt` you can write all you want. You just need to add the statement below to indicate where to\ninclude the calling template.\n\n```md\n[#]: baseInclude\n```\n\nNote that you can add this statement as much as you want, it will just include the html at each place.\n\n#### Include template\n\nYou can also include another template in your template. For that you just have to write :\n\n```md\n[#]: include someTemplate\n```\n\nIt will then look for the file `someTemplate.mdt` from where the template is located. You can override this by providing\na search path to the library :\n\n```php\n$engine-\u003eincludePath('someWhere');\n```\n\nYour include template can get some values from the calling template. For that, you just need to add these values after\nthe template name :\n\n```md\n[#]: include someTemplate { \"foo\":\"bar\", \"hello\":\"world\" }\n```\n\n#### Scripting\n\nYou can also create conditions and loops. Let's begin with conditions.\n\n```md\n{% if foo == \"bar\" %}\nThe variable foo is equal to bar\n{% else %}\nThe variable foo is not equal to bar\n{% endif %}\n```\n\nThe statements `{%  %}` needs to have their own line. Conditions work like in php.\n\nAnd now, loops :\n\n```md\n{% for value in values %}\n- {value}\n{% endfor %}\n```\n\nLike for conditions, loop statements needs to have their own line.\n\n### Generate html\n\nFinally, there is how to use the engine to generate html document from a template file :\n\n```php\nuse Gashmob\\MdGen\\MdGenEngine;\n\n// Create a new instance of the engine\n$engine = new MdGenEngine();\n\n// Set base and include paths\n$engine-\u003ebasePath('bases/');\n$engine-\u003eincludePath('includes/');\n\n// Pre-render template (this is optional)\n$array = $engine-\u003epreRender('myTemplate.mdt');\n/* Compute some values from $array */\n\n// Render template\n$html = $engine-\u003erender('myTemplate.mdt', [\n    \"foo\" =\u003e \"bar\",\n]);\n```\n\n### Cache\n\nTo avoid long render time each time, you can use the internal cache system that store in a dedicated dir the results of past renders. By default this system is disable, but you can enable it by using :\n\n```php\nuse Gashmob\\MdGen\\MdGenEngine;\n\n$engine = new MdGenEngine();\n\n// Enable cache\n$engine-\u003ecache('path/to/cache/dir');\n\n// Disable cache\n$engine-\u003ecache(false);\n```\n\nIf the dir doesn't exists, it will create it. When you enable the cache, it will be enable for all instances of `MdGenEngine`.\n\nYou can also set the lifespan of cache by using :\n\n```php\nuse Gashmob\\MdGen\\MdGenEngine;\n\nMdGenEngine::$cacheLifespan = 3600 * 24 * 365; // 1 year in seconds\n```\n\nBy default the lifespan is set to 1 month.\n\n## Installation\n\nThe easiest way to use this library is to pass from composer with :\n\n```console\ncomposer require gashmob/mdgen\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgashmob%2Fmdgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgashmob%2Fmdgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgashmob%2Fmdgen/lists"}