{"record":{"id":"e3da05b1d4ff3cc6","repo":"twigphp/Twig","slug":"you-cannot-use-the-markdown-to-html-filter-as-no-markdown","errorCode":null,"errorMessage":"You cannot use the \"markdown_to_html\" filter as no Markdown library is available; try running \"composer require league/commonmark\".","messagePattern":"You cannot use the \"markdown_to_html\" filter as no Markdown library is available; try running \"composer require league/commonmark\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"extra/markdown-extra/DefaultMarkdown.php","lineNumber":33,"sourceCode":"use Michelf\\MarkdownExtra;\nuse Tempest\\Markdown\\Markdown;\n\nclass DefaultMarkdown implements MarkdownInterface\n{\n    private $converter;\n\n    public function __construct()\n    {\n        if (class_exists(CommonMarkConverter::class)) {\n            $this->converter = new LeagueMarkdown();\n        } elseif (class_exists(MarkdownExtra::class)) {\n            $this->converter = new MichelfMarkdown();\n        } elseif (class_exists(\\Parsedown::class)) {\n            $this->converter = new ErusevMarkdown();\n        } elseif (class_exists(Markdown::class)) {\n            $this->converter = new TempestMarkdown();\n        } else {\n            throw new \\LogicException('You cannot use the \"markdown_to_html\" filter as no Markdown library is available; try running \"composer require league/commonmark\".');\n        }\n    }\n\n    public function convert(string $body): string\n    {\n        return $this->converter->convert($body);\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":42,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/markdown-extra/DefaultMarkdown.php#L15-L42","documentation":"DefaultMarkdown's constructor probes for any supported Markdown library (league/commonmark, michelf/php-markdown, erusev/parsedown, tempest/markdown) via class_exists(). If none is installed it throws a LogicException, because the markdown_to_html filter has no converter to delegate to. Being a LogicException, it typically surfaces during container wiring/filter setup rather than per-render.","triggerScenarios":"Installing twig/markdown-extra (or registering MarkdownExtension) without installing any of the Markdown packages it supports, then constructing DefaultMarkdown or using the markdown_to_html filter.","commonSituations":"composer require twig/markdown-extra alone (it does not pull a Markdown lib by itself); moving to a new server/CI image without composer install of optional deps; removing league/commonmark during dependency cleanup while templates still use the filter.","solutions":["Run \"composer require league/commonmark\" (the recommended library).","Or install another supported lib: michelf/php-markdown, erusev/parsedown, or tempest/markdown.","Or implement MarkdownInterface yourself and inject it instead of DefaultMarkdown."],"exampleFix":"// before\ncomposer require twig/markdown-extra\n// after\ncomposer require twig/markdown-extra league/commonmark","handlingStrategy":"fallback","validationCode":"if (!class_exists(\\League\\CommonMark\\CommonMarkConverter::class)\n && !class_exists(\\Michelf\\MarkdownExtra::class)\n && !class_exists(\\Parsedown::class)\n && !class_exists(\\Tempest\\Markdown\\Markdown::class)) {\n    throw new LogicException('markdown_to_html requires a Markdown package; composer require league/commonmark');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $markdown = new \\Twig\\Extra\\Markdown\\DefaultMarkdown();\n} catch (\\LogicException $e) {\n    // install a Markdown package or provide a custom MarkdownInterface implementation\n}","preventionTips":["Require a concrete Markdown package (league/commonmark) explicitly in composer.json rather than relying on transitive installs.","Run composer install in CI the same way as production (watch --no-dev).","Register MarkdownExtension only when a converter is available, or bind your own MarkdownInterface implementation in the container."],"tags":["php","composer","markdown","missing-package","dependency-injection"],"backgroundTag":"missing-optional-dependency","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}