From 195e245f0aa640d0af18467883161f32c10e3b5b Mon Sep 17 00:00:00 2001 From: inhere Date: Mon, 30 Oct 2023 17:38:23 +0800 Subject: [PATCH] master fix: parse markdown table error on has special chars --- app/Lib/Parser/DBMdTable.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Lib/Parser/DBMdTable.php b/app/Lib/Parser/DBMdTable.php index e8b1ced..0c731cd 100644 --- a/app/Lib/Parser/DBMdTable.php +++ b/app/Lib/Parser/DBMdTable.php @@ -46,14 +46,15 @@ public function parse(string $mdTable): DBTable $dbt->setSource($mdTable); $lines = array_values( - array_filter( - explode("\n", trim($mdTable)) - ) + array_filter(explode("\n", trim($mdTable)), function ($line) { + return trim($line) !== ''; + }) ); - // $table = trim($lines[0], '# '); - [$tableComment, $tableName] = array_filter(explode(' ', trim($lines[0], '`:#\' '))); - + // parse first line: "### 应用表(app)" + $first = trim(trim($lines[0]), '))`:#\' '); + $first = str_replace(['(', '('], ' ', $first); + [$tableComment, $tableName] = array_filter(explode(' ', $first)); $tableName = trim($tableName, '` '); $titleLine = trim($lines[1], '| '); $colNumber = count(explode('|', $titleLine));