From 99767ad9865b385678864ca93238209a4c22faf1 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 22 Oct 2024 22:58:10 +0200 Subject: [PATCH] Use guides to parse and render markdown --- composer.json | 5 +- composer.lock | 680 +++++++++++++++--- config/services.xml | 4 + config/services/static-website-generator.xml | 2 +- lib/Application.php | 3 +- .../GuidesMarkdownConverter.php | 51 ++ 6 files changed, 660 insertions(+), 85 deletions(-) create mode 100644 lib/Guides/StaticWebsiteGenerator/GuidesMarkdownConverter.php diff --git a/composer.json b/composer.json index e8f76922..1a88316b 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,9 @@ "knplabs/github-api": "^3.9", "monolog/monolog": "^3.7", "php-http/guzzle7-adapter": "^1.0", - "phpdocumentor/guides": "^1.4", - "phpdocumentor/guides-restructured-text": "^1.4", + "phpdocumentor/guides": "^1.6", + "phpdocumentor/guides-markdown": "^1.6", + "phpdocumentor/guides-restructured-text": "^1.6", "scrivo/highlight.php": "^9.18", "symfony/cache": "^6.4", "symfony/config": "^6.4", diff --git a/composer.lock b/composer.lock index 40ed9c4b..eb77b59e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a83b1d43596b5f2689b30b43593fac1c", + "content-hash": "b94ea6cfa99e65a311981399c771cb3b", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -146,6 +146,81 @@ ], "time": "2022-02-21T13:15:14+00:00" }, + { + "name": "dflydev/dot-access-data", + "version": "v3.0.3", + "source": { + "type": "git", + "url": "https://github.com/dflydev/dflydev-dot-access-data.git", + "reference": "a23a2bf4f31d3518f3ecb38660c95715dfead60f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dflydev/dflydev-dot-access-data/zipball/a23a2bf4f31d3518f3ecb38660c95715dfead60f", + "reference": "a23a2bf4f31d3518f3ecb38660c95715dfead60f", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.42", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3", + "scrutinizer/ocular": "1.6.0", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Dflydev\\DotAccessData\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dragonfly Development Inc.", + "email": "info@dflydev.com", + "homepage": "http://dflydev.com" + }, + { + "name": "Beau Simensen", + "email": "beau@dflydev.com", + "homepage": "http://beausimensen.com" + }, + { + "name": "Carlos Frutos", + "email": "carlos@kiwing.it", + "homepage": "https://github.com/cfrutos" + }, + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com" + } + ], + "description": "Given a deep data structure, access data by dot notation.", + "homepage": "https://github.com/dflydev/dflydev-dot-access-data", + "keywords": [ + "access", + "data", + "dot", + "notation" + ], + "support": { + "issues": "https://github.com/dflydev/dflydev-dot-access-data/issues", + "source": "https://github.com/dflydev/dflydev-dot-access-data/tree/v3.0.3" + }, + "time": "2024-07-08T12:26:09+00:00" + }, { "name": "doctrine/collections", "version": "2.2.2", @@ -1497,6 +1572,194 @@ ], "time": "2023-11-19T21:08:19+00:00" }, + { + "name": "league/commonmark", + "version": "2.5.3", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/commonmark.git", + "reference": "b650144166dfa7703e62a22e493b853b58d874b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/b650144166dfa7703e62a22e493b853b58d874b0", + "reference": "b650144166dfa7703e62a22e493b853b58d874b0", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "league/config": "^1.1.1", + "php": "^7.4 || ^8.0", + "psr/event-dispatcher": "^1.0", + "symfony/deprecation-contracts": "^2.1 || ^3.0", + "symfony/polyfill-php80": "^1.16" + }, + "require-dev": { + "cebe/markdown": "^1.0", + "commonmark/cmark": "0.31.1", + "commonmark/commonmark.js": "0.31.1", + "composer/package-versions-deprecated": "^1.8", + "embed/embed": "^4.4", + "erusev/parsedown": "^1.0", + "ext-json": "*", + "github/gfm": "0.29.0", + "michelf/php-markdown": "^1.4 || ^2.0", + "nyholm/psr7": "^1.5", + "phpstan/phpstan": "^1.8.2", + "phpunit/phpunit": "^9.5.21 || ^10.5.9 || ^11.0.0", + "scrutinizer/ocular": "^1.8.1", + "symfony/finder": "^5.3 | ^6.0 || ^7.0", + "symfony/yaml": "^2.3 | ^3.0 | ^4.0 | ^5.0 | ^6.0 || ^7.0", + "unleashedtech/php-coding-standard": "^3.1.1", + "vimeo/psalm": "^4.24.0 || ^5.0.0" + }, + "suggest": { + "symfony/yaml": "v2.3+ required if using the Front Matter extension" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.6-dev" + } + }, + "autoload": { + "psr-4": { + "League\\CommonMark\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com", + "role": "Lead Developer" + } + ], + "description": "Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)", + "homepage": "https://commonmark.thephpleague.com", + "keywords": [ + "commonmark", + "flavored", + "gfm", + "github", + "github-flavored", + "markdown", + "md", + "parser" + ], + "support": { + "docs": "https://commonmark.thephpleague.com/", + "forum": "https://github.com/thephpleague/commonmark/discussions", + "issues": "https://github.com/thephpleague/commonmark/issues", + "rss": "https://github.com/thephpleague/commonmark/releases.atom", + "source": "https://github.com/thephpleague/commonmark" + }, + "funding": [ + { + "url": "https://www.colinodell.com/sponsor", + "type": "custom" + }, + { + "url": "https://www.paypal.me/colinpodell/10.00", + "type": "custom" + }, + { + "url": "https://github.com/colinodell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/league/commonmark", + "type": "tidelift" + } + ], + "time": "2024-08-16T11:46:16+00:00" + }, + { + "name": "league/config", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/config.git", + "reference": "754b3604fb2984c71f4af4a9cbe7b57f346ec1f3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/config/zipball/754b3604fb2984c71f4af4a9cbe7b57f346ec1f3", + "reference": "754b3604fb2984c71f4af4a9cbe7b57f346ec1f3", + "shasum": "" + }, + "require": { + "dflydev/dot-access-data": "^3.0.1", + "nette/schema": "^1.2", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.8.2", + "phpunit/phpunit": "^9.5.5", + "scrutinizer/ocular": "^1.8.1", + "unleashedtech/php-coding-standard": "^3.1", + "vimeo/psalm": "^4.7.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.2-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Config\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com", + "role": "Lead Developer" + } + ], + "description": "Define configuration arrays with strict schemas and access values with dot notation", + "homepage": "https://config.thephpleague.com", + "keywords": [ + "array", + "config", + "configuration", + "dot", + "dot-access", + "nested", + "schema" + ], + "support": { + "docs": "https://config.thephpleague.com/", + "issues": "https://github.com/thephpleague/config/issues", + "rss": "https://github.com/thephpleague/config/releases.atom", + "source": "https://github.com/thephpleague/config" + }, + "funding": [ + { + "url": "https://www.colinodell.com/sponsor", + "type": "custom" + }, + { + "url": "https://www.paypal.me/colinpodell/10.00", + "type": "custom" + }, + { + "url": "https://github.com/colinodell", + "type": "github" + } + ], + "time": "2022-12-11T20:36:23+00:00" + }, { "name": "league/csv", "version": "9.16.0", @@ -1964,6 +2227,73 @@ ], "time": "2024-03-23T07:42:40+00:00" }, + { + "name": "masterminds/html5", + "version": "2.8.1", + "source": { + "type": "git", + "url": "https://github.com/Masterminds/html5-php.git", + "reference": "f47dcf3c70c584de14f21143c55d9939631bc6cf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/f47dcf3c70c584de14f21143c55d9939631bc6cf", + "reference": "f47dcf3c70c584de14f21143c55d9939631bc6cf", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Masterminds\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Butcher", + "email": "technosophos@gmail.com" + }, + { + "name": "Matt Farina", + "email": "matt@mattfarina.com" + }, + { + "name": "Asmir Mustafic", + "email": "goetas@gmail.com" + } + ], + "description": "An HTML5 parser and serializer.", + "homepage": "http://masterminds.github.io/html5-php", + "keywords": [ + "HTML5", + "dom", + "html", + "parser", + "querypath", + "serializer", + "xml" + ], + "support": { + "issues": "https://github.com/Masterminds/html5-php/issues", + "source": "https://github.com/Masterminds/html5-php/tree/2.8.1" + }, + "time": "2023-05-10T11:58:31+00:00" + }, { "name": "monolog/monolog", "version": "3.7.0", @@ -2065,6 +2395,154 @@ ], "time": "2024-06-28T09:40:51+00:00" }, + { + "name": "nette/schema", + "version": "v1.3.2", + "source": { + "type": "git", + "url": "https://github.com/nette/schema.git", + "reference": "da801d52f0354f70a638673c4a0f04e16529431d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/schema/zipball/da801d52f0354f70a638673c4a0f04e16529431d", + "reference": "da801d52f0354f70a638673c4a0f04e16529431d", + "shasum": "" + }, + "require": { + "nette/utils": "^4.0", + "php": "8.1 - 8.4" + }, + "require-dev": { + "nette/tester": "^2.5.2", + "phpstan/phpstan-nette": "^1.0", + "tracy/tracy": "^2.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "📐 Nette Schema: validating data structures against a given Schema.", + "homepage": "https://nette.org", + "keywords": [ + "config", + "nette" + ], + "support": { + "issues": "https://github.com/nette/schema/issues", + "source": "https://github.com/nette/schema/tree/v1.3.2" + }, + "time": "2024-10-06T23:10:23+00:00" + }, + { + "name": "nette/utils", + "version": "v4.0.5", + "source": { + "type": "git", + "url": "https://github.com/nette/utils.git", + "reference": "736c567e257dbe0fcf6ce81b4d6dbe05c6899f96" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/utils/zipball/736c567e257dbe0fcf6ce81b4d6dbe05c6899f96", + "reference": "736c567e257dbe0fcf6ce81b4d6dbe05c6899f96", + "shasum": "" + }, + "require": { + "php": "8.0 - 8.4" + }, + "conflict": { + "nette/finder": "<3", + "nette/schema": "<1.2.2" + }, + "require-dev": { + "jetbrains/phpstorm-attributes": "dev-master", + "nette/tester": "^2.5", + "phpstan/phpstan": "^1.0", + "tracy/tracy": "^2.9" + }, + "suggest": { + "ext-gd": "to use Image", + "ext-iconv": "to use Strings::webalize(), toAscii(), chr() and reverse()", + "ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()", + "ext-json": "to use Nette\\Utils\\Json", + "ext-mbstring": "to use Strings::lower() etc...", + "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.", + "homepage": "https://nette.org", + "keywords": [ + "array", + "core", + "datetime", + "images", + "json", + "nette", + "paginator", + "password", + "slugify", + "string", + "unicode", + "utf-8", + "utility", + "validation" + ], + "support": { + "issues": "https://github.com/nette/utils/issues", + "source": "https://github.com/nette/utils/tree/v4.0.5" + }, + "time": "2024-08-07T15:39:19+00:00" + }, { "name": "php-http/cache-plugin", "version": "1.8.1", @@ -2670,16 +3148,16 @@ }, { "name": "phpdocumentor/guides", - "version": "1.4.1", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/guides-core.git", - "reference": "1f21f606ce030fd8989eb783f726cf32c44d61ef" + "reference": "529c19d60e25882e7cc07189bd648ff7fcf80056" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/guides-core/zipball/1f21f606ce030fd8989eb783f726cf32c44d61ef", - "reference": "1f21f606ce030fd8989eb783f726cf32c44d61ef", + "url": "https://api.github.com/repos/phpDocumentor/guides-core/zipball/529c19d60e25882e7cc07189bd648ff7fcf80056", + "reference": "529c19d60e25882e7cc07189bd648ff7fcf80056", "shasum": "" }, "require": { @@ -2693,7 +3171,8 @@ "phpdocumentor/flyfinder": "^1.1", "psr/event-dispatcher": "^1.0", "symfony/clock": "^6.4.3", - "symfony/http-client": "^6.4.4", + "symfony/html-sanitizer": "^6.4.8", + "symfony/http-client": "^6.4.9", "symfony/string": "^5.4 || ^6.3 || ^7.0", "symfony/translation-contracts": "^3.4.1", "twig/twig": "~2.15 || ^3.0", @@ -2716,22 +3195,59 @@ "homepage": "https://www.phpdoc.org", "support": { "issues": "https://github.com/phpDocumentor/guides-core/issues", - "source": "https://github.com/phpDocumentor/guides-core/tree/1.4.1" + "source": "https://github.com/phpDocumentor/guides-core/tree/1.6.1" }, - "time": "2024-09-25T20:40:25+00:00" + "time": "2024-10-25T20:20:41+00:00" + }, + { + "name": "phpdocumentor/guides-markdown", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/guides-markdown.git", + "reference": "980a631e16f80aaabea7638c21043438450df5c0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/guides-markdown/zipball/980a631e16f80aaabea7638c21043438450df5c0", + "reference": "980a631e16f80aaabea7638c21043438450df5c0", + "shasum": "" + }, + "require": { + "league/commonmark": "^2.4", + "php": "^8.1", + "phpdocumentor/guides": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Guides\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Adds Markdown support to the phpDocumentor's Guides library.", + "homepage": "https://www.phpdoc.org", + "support": { + "issues": "https://github.com/phpDocumentor/guides-markdown/issues", + "source": "https://github.com/phpDocumentor/guides-markdown/tree/1.6.1" + }, + "time": "2024-10-25T20:20:41+00:00" }, { "name": "phpdocumentor/guides-restructured-text", - "version": "1.4.0", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/guides-restructured-text.git", - "reference": "f21a69f2d39ae04eea8550a90863a74c5ef97d4b" + "reference": "9b82adb8d9566c6a39b12514c4d3f345532a3025" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/guides-restructured-text/zipball/f21a69f2d39ae04eea8550a90863a74c5ef97d4b", - "reference": "f21a69f2d39ae04eea8550a90863a74c5ef97d4b", + "url": "https://api.github.com/repos/phpDocumentor/guides-restructured-text/zipball/9b82adb8d9566c6a39b12514c4d3f345532a3025", + "reference": "9b82adb8d9566c6a39b12514c4d3f345532a3025", "shasum": "" }, "require": { @@ -2754,9 +3270,9 @@ "description": "Adds reStructuredText Markup support to the phpDocumentor's Guides library.", "homepage": "https://www.phpdoc.org", "support": { - "source": "https://github.com/phpDocumentor/guides-restructured-text/tree/1.4.0" + "source": "https://github.com/phpDocumentor/guides-restructured-text/tree/1.6.1" }, - "time": "2024-09-25T17:25:09+00:00" + "time": "2024-10-25T20:20:41+00:00" }, { "name": "psr/cache", @@ -4265,6 +4781,75 @@ ], "time": "2024-05-31T14:49:08+00:00" }, + { + "name": "symfony/html-sanitizer", + "version": "v6.4.12", + "source": { + "type": "git", + "url": "https://github.com/symfony/html-sanitizer.git", + "reference": "b58efe8ed0d8f5bf84913380a2f9da0c242f4200" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/html-sanitizer/zipball/b58efe8ed0d8f5bf84913380a2f9da0c242f4200", + "reference": "b58efe8ed0d8f5bf84913380a2f9da0c242f4200", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "league/uri": "^6.5|^7.0", + "masterminds/html5": "^2.7.2", + "php": ">=8.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HtmlSanitizer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Titouan Galopin", + "email": "galopintitouan@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an object-oriented API to sanitize untrusted HTML input for safe insertion into a document's DOM.", + "homepage": "https://symfony.com", + "keywords": [ + "Purifier", + "html", + "sanitizer" + ], + "support": { + "source": "https://github.com/symfony/html-sanitizer/tree/v6.4.12" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-20T08:21:33+00:00" + }, { "name": "symfony/http-client", "version": "v6.4.12", @@ -6143,73 +6728,6 @@ }, "time": "2023-04-24T17:43:28+00:00" }, - { - "name": "masterminds/html5", - "version": "2.8.1", - "source": { - "type": "git", - "url": "https://github.com/Masterminds/html5-php.git", - "reference": "f47dcf3c70c584de14f21143c55d9939631bc6cf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/f47dcf3c70c584de14f21143c55d9939631bc6cf", - "reference": "f47dcf3c70c584de14f21143c55d9939631bc6cf", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Masterminds\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Matt Butcher", - "email": "technosophos@gmail.com" - }, - { - "name": "Matt Farina", - "email": "matt@mattfarina.com" - }, - { - "name": "Asmir Mustafic", - "email": "goetas@gmail.com" - } - ], - "description": "An HTML5 parser and serializer.", - "homepage": "http://masterminds.github.io/html5-php", - "keywords": [ - "HTML5", - "dom", - "html", - "parser", - "querypath", - "serializer", - "xml" - ], - "support": { - "issues": "https://github.com/Masterminds/html5-php/issues", - "source": "https://github.com/Masterminds/html5-php/tree/2.8.1" - }, - "time": "2023-05-10T11:58:31+00:00" - }, { "name": "mikey179/vfsstream", "version": "v1.6.11", diff --git a/config/services.xml b/config/services.xml index 540df311..205d0588 100644 --- a/config/services.xml +++ b/config/services.xml @@ -175,6 +175,10 @@ + + + + website-document.html.twig phpDocumentor\Guides\Nodes\DocumentNode diff --git a/config/services/static-website-generator.xml b/config/services/static-website-generator.xml index 7bfb5765..7a5e4f25 100644 --- a/config/services/static-website-generator.xml +++ b/config/services/static-website-generator.xml @@ -20,8 +20,8 @@ - + /\/api\// diff --git a/lib/Application.php b/lib/Application.php index a4031def..44903f97 100644 --- a/lib/Application.php +++ b/lib/Application.php @@ -12,6 +12,7 @@ use Doctrine\Website\Commands\SyncRepositoriesCommand; use Doctrine\Website\Guides\DependencyInjection\ThemeCompilerPass; use phpDocumentor\Guides\DependencyInjection\GuidesExtension; +use phpDocumentor\Guides\Markdown\DependencyInjection\MarkdownExtension; use phpDocumentor\Guides\RestructuredText\DependencyInjection\ReStructuredTextExtension; use Symfony\Component\Config\FileLocator; use Symfony\Component\Console\Application as BaseApplication; @@ -91,7 +92,7 @@ public static function getContainer(string $env): ContainerBuilder $container->setParameter('vendor_dir', realpath(__DIR__ . '/../vendor')); $container->addCompilerPass(new ThemeCompilerPass()); - foreach ([new GuidesExtension(), new ReStructuredTextExtension()] as $extension) { + foreach ([new GuidesExtension(), new ReStructuredTextExtension(), new MarkdownExtension()] as $extension) { $container->registerExtension($extension); $container->loadFromExtension($extension->getAlias()); } diff --git a/lib/Guides/StaticWebsiteGenerator/GuidesMarkdownConverter.php b/lib/Guides/StaticWebsiteGenerator/GuidesMarkdownConverter.php new file mode 100644 index 00000000..ddde4baa --- /dev/null +++ b/lib/Guides/StaticWebsiteGenerator/GuidesMarkdownConverter.php @@ -0,0 +1,51 @@ + $nodeRenderer */ + public function __construct( + private Parser $parser, + private NodeRenderer $nodeRenderer, + ) { + } + + /** @inheritDoc */ + #[Override] + public function getExtensions(): array + { + return ['md', 'markdown']; + } + + #[Override] + public function convertSourceFile(SourceFile $sourceFile): string + { + $document = $this->parser->parse($sourceFile->getContents(), 'md'); + + $renderContext = RenderContext::forDocument( + $document, + [$document], + new Filesystem(new NullAdapter()), + new Filesystem(new NullAdapter()), + '/', + 'html', + new ProjectNode(), + ); + + return $this->nodeRenderer->render($document, $renderContext); + } +}