diff --git a/composer.json b/composer.json index 733073030..3ecc83679 100644 --- a/composer.json +++ b/composer.json @@ -65,7 +65,8 @@ "phpunit/phpunit": "^9", "phabel/phabel": "^1", "bamarni/composer-bin-plugin": "^1.4", - "roave/security-advisories": "dev-latest" + "roave/security-advisories": "dev-latest", + "symfony/yaml": "^6.0" }, "suggest": { "ext-libtgvoip": "Install the php-libtgvoip extension to make phone calls (https://github.com/danog/php-libtgvoip)", diff --git a/docs b/docs index b6e8bd260..23e60b270 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit b6e8bd2600e38afa4e6ad60b9bfdf9dea9dbd94c +Subproject commit 23e60b270e4f34d5a74bc9248e741d6badb998ac diff --git a/src/danog/MadelineProto/DocsBuilder/Constructors.php b/src/danog/MadelineProto/DocsBuilder/Constructors.php index 6d6b6fb2d..de1a2fa9c 100644 --- a/src/danog/MadelineProto/DocsBuilder/Constructors.php +++ b/src/danog/MadelineProto/DocsBuilder/Constructors.php @@ -177,10 +177,10 @@ trait Constructors $description = isset($this->TL->getDescriptions()['constructors'][$constructor]) ? $this->TL->getDescriptions()['constructors'][$constructor]['description'] : $constructor.' attributes, type and example'; $symFile = \str_replace('.', '_', $constructor.$layer); $redir = $symFile !== $constructor.$layer ? "\nredirect_from: /API_docs/constructors/{$symFile}.html" : ''; - $description = \rtrim(\explode("\n", $description)[0], ':'); + $description = \str_replace('"', "'", Tools::toString(\rtrim(\explode("\n", $description)[0], ':'))); $header = '--- -title: '.$constructor.' -description: '.$description.' +title: "'.$constructor.'" +description: "'.$description.'" image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png'.$redir.' --- # Constructor: '.StrTools::markdownEscape($constructor.$layer).' diff --git a/src/danog/MadelineProto/Tools.php b/src/danog/MadelineProto/Tools.php index d9fbbc3b0..ca9b2537e 100644 --- a/src/danog/MadelineProto/Tools.php +++ b/src/danog/MadelineProto/Tools.php @@ -25,6 +25,9 @@ use Amp\Loop; use Amp\Promise; use Amp\Success; use Amp\TimeoutException; +use DOMDocument; +use Parsedown; + use function Amp\ByteStream\getOutputBufferStream; use function Amp\ByteStream\getStdin; use function Amp\ByteStream\getStdout; @@ -1017,4 +1020,25 @@ abstract class Tools extends StrTools } return [!!$matches[1], $matches[2]]; } + /** + * Strip markdown tags. + * + * @internal + * + * @param string $markdown + * @return string + */ + public static function toString(string $markdown): string + { + if ($markdown === '') { + return $markdown; + } + $html = (new Parsedown($markdown))->text($markdown); + $document = new DOMDocument('', 'utf-8'); + @$document->loadHTML(\mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); + if (!$document->getElementsByTagName('body')[0]) { + return ''; + } + return $document->getElementsByTagName('body')[0]->childNodes[0]->textContent; + } } diff --git a/src/polyfill.php b/src/polyfill.php index f703f8438..f0b42fc34 100644 --- a/src/polyfill.php +++ b/src/polyfill.php @@ -26,15 +26,6 @@ function __destructure($list, $value): array return $res; } -trait MyCallableMaker -{ - use \Amp\CallableMaker { - callableFromInstanceMethod as public; - callableFromStaticMethod as public; - } -} - - $ampFilePolyfill = 'namespace Amp\\File {'; foreach ([ 'open' => 'openFile', diff --git a/tools/build_docs.php b/tools/build_docs.php index 8b49fe2a7..5a55d090b 100755 --- a/tools/build_docs.php +++ b/tools/build_docs.php @@ -20,6 +20,7 @@ use danog\MadelineProto\Settings\Logger as SettingsLogger; use danog\MadelineProto\TON\API as TONAPI; use danog\MadelineProto\TON\APIFactory as TONAPIFactory; use danog\MadelineProto\TON\Lite; +use danog\MadelineProto\Tools; \chdir($d=__DIR__.'/..'); @@ -159,9 +160,9 @@ foreach ($orderedfiles as $key => $filename) { } \preg_match('|^# (.*)|', $lines[0], $matches); $title = $matches[1]; - $description = $lines[2]; + $description = \str_replace('"', "'", Tools::toString($lines[2])); - \array_unshift($lines, '---', 'title: '.$title, 'description: '.$description, 'image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png', '---'); + \array_unshift($lines, '---', 'title: "'.$title.'"', 'description: "'.$description.'"', 'image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png', '---'); if (isset($orderedfiles[$key + 1])) { $nextfile = 'https://docs.madelineproto.xyz/docs/'.\basename($orderedfiles[$key + 1], '.md').'.html'; diff --git a/tools/build_docs/schemas.php b/tools/build_docs/schemas.php index 08bb60b24..f453fd5e9 100644 --- a/tools/build_docs/schemas.php +++ b/tools/build_docs/schemas.php @@ -38,26 +38,5 @@ function maxLayer(array $schemas): int */ function initDocs(array $layers): array { - $docs = []; - $layer_list = ''; - foreach (\array_slice($layers, 0, -1) as $layer => $file) { - $layer = "v$layer"; - $docs[] = [ - 'tl_schema' => ['telegram' => $file, 'mtproto' => '', 'secret' => '', 'td' => ''], - 'title' => 'MadelineProto API documentation (layer '.$layer.')', - 'description' => 'MadelineProto API documentation (layer '.$layer.')', - 'output_dir' => \getcwd()."/docs/old_docs/API_docs_".$layer, - 'template' => \getcwd()."/docs/template", - 'readme' => true, - ]; - $layer_list .= "[Layer $layer](API_docs_$layer/) \n"; - } - \file_put_contents('docs/old_docs/README.md', '--- -title: Documentation of old mtproto layers -description: Documentation of old mtproto layers ---- -# Documentation of old mtproto layers - -'.$layer_list); - return $docs; + return []; }