{"id":24540674,"url":"https://github.com/mistralys/markdown-renderer","last_synced_at":"2025-04-15T08:42:17.257Z","repository":{"id":251558156,"uuid":"837594167","full_name":"Mistralys/markdown-renderer","owner":"Mistralys","description":"CommonMark Markdown renderer for PHP with pre- and post-processors.","archived":false,"fork":false,"pushed_at":"2025-03-27T12:32:17.000Z","size":73,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T13:31:56.703Z","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/Mistralys.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","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":"2024-08-03T12:39:55.000Z","updated_at":"2025-03-27T12:31:59.000Z","dependencies_parsed_at":"2025-03-27T13:28:44.890Z","dependency_job_id":"2138e34f-5643-4323-96ae-2d70e2b8d824","html_url":"https://github.com/Mistralys/markdown-renderer","commit_stats":null,"previous_names":["mistralys/markdown-renderer"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fmarkdown-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fmarkdown-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fmarkdown-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fmarkdown-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mistralys","download_url":"https://codeload.github.com/Mistralys/markdown-renderer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249038887,"owners_count":21202803,"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":"2025-01-22T18:14:39.368Z","updated_at":"2025-04-15T08:42:17.243Z","avatar_url":"https://github.com/Mistralys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Markdown Renderer\n\nCommonMark Markdown renderer for PHP with the capability to define\npre- and post-processors with custom syntax.\n\n## Usage\n\n### From a Markdown string\n\n```php\nuse Mistralys\\Markdown\\MarkdownRenderer;\n\n$markdown = \u003c\u003c\u003cMD\n# Markdown test\n\nSome text with **formatting**.\nMD;\n\necho Renderer::factory($markdown)-\u003erender();\n```\n\n### From a Markdown file\n\n```php\nuse Mistralys\\Markdown\\MarkdownRenderer;\nuse \\AppUtils\\FileHelper\\FileInfo;\n\n$file = FileInfo::factory('/path/to/markdown.md');\n\necho Renderer::factory($file)-\u003erender();\n```\n\n### Adding a processor\n\nAny number of processors can be added with the `addProcessor()` \nmethod. They are executed in the order that they are added.\n\nExample: Adding the bundled video processor.\n\n```php\nuse Mistralys\\Markdown\\MarkdownRenderer;\nuse Mistralys\\MarkdownRenderer\\Processors\\Bundled\\VideosProcessor;\n\n$file = FileInfo::factory('/path/to/markdown.md');\n\necho Renderer::factory($file)\n    -\u003eaddProcessor(new VideosProcessor($renderer))\n    -\u003erender();\n```\n\n## Bundled commands\n\nSeveral commands are bundled with the library, provided by the\nprocessor classes located at:\n\n[Processors/Bundled](/src/MarkdownRenderer/Processors/Bundled)\n\n### Displaying images\n\n#### Configuration\n\n```php\nuse Mistralys\\MarkdownRenderer\\Processors\\Bundled\\ImagesProcessor;\n\n$processor = new ImagesProcessor($renderer);\n\n// The base URL is prepended to all image paths.\n$processor-\u003esetImageBaseURL('/img/');\n```\n\n#### Syntax\n\nIt uses the following syntax for images:\n\n```\n{image: \"test.jpg\"\n    id=\"imageID\"  \n    width=\"150px\"\n    height=\"150px \n    class=\"classA classB\" \n    alt=\"Alternative text\"\n    title=\"Tooltip title\"\n}\n```\n\nThe image path is mandatory, all other attributes are optional.\nIf no alternative text is provided, the title is used. If both1\nare empty, an empty `alt=\"\"` attribute is used.\n\nNested double quotes must be escaped like this:\n \n```\ntitle=\"Something \\\"here\\\"\"\n```\n\n\u003e NOTE: Attributes are not passed through as-is.\n\u003e Only attributes known by the processor are used, so any\n\u003e additional attributes are ignored.\n\n## Adding custom commands\n\nThe library is based on a simple syntax for defining custom commands,\nwhich follow the following scheme with pseudo HTML attributes:\n\n```\n{commandName: \"value\" name=\"named value\" property}\n```\n\nThe parsing of these commands is handled automatically by the library,\nand the attributes can easily be accessed via a helper class when rendering\nthe matching content.\n\n### Adding a custom processor\n\nIf you want to do your own syntax parsing, create a class based on\n`BaseProcessor`. Use the `BaseCommandBasedProcessor` class if you want\nto use the library's command syntax (easiest to implement). Simply\nimplement all abstract methods, and you're good to go.\n\n\u003e Every abstract method has documentation on what you are supposed to do.\n\nYou can create your processor class anywhere in your project, and add\nit to the renderer with the `addProcessor()` method.\n\n```php\nuse Mistralys\\Markdown\\MarkdownRenderer;\nuse My\\Custom\\CommandProcessor;\n\n$file = FileInfo::factory('/path/to/markdown.md');\n\necho Renderer::factory($file)\n    -\u003eaddProcessor(new CommandProcessor($renderer))\n    -\u003erender();\n```\n\n## Origin\n\nI had created similar Markdown filters in several of my personal and\nprofessional projects. Each project had different enough requirements\nfor syntax and content, and were easy enough to implement, so for a\nlong time I did not take the step to move the common functionality to\na separate library.\n\nAnother recent project made me take the step. As is often the case, I \nwas annoyed enough by having to create regexes to parse the commands\nthat I decided to do it right.\n\n## Philosophy\n\nI have read quite a few discussions on what kind of information should\nbe included in a Markdown file. Image widths are one thing that the \ncommunity is divided on. I agree that the width of an image is layout\ninformation, not content. The requirement is real, however, and appears\noften enough for me to take a pragmatic approach.\n\nMy philosophy is that as long as the Markdown content stays easily \nreadable, and that the added syntax does not interfere with reading\nthe document, I don't mind.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fmarkdown-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmistralys%2Fmarkdown-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fmarkdown-renderer/lists"}