From 87f6a01c94bdf870546d64890849833cff054188 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Tue, 6 Jan 2026 17:34:05 +0800 Subject: [PATCH] figer update --- application/api/controller/Production.php | 204 ++++++++++++---------- 1 file changed, 110 insertions(+), 94 deletions(-) diff --git a/application/api/controller/Production.php b/application/api/controller/Production.php index e2bb844..f6b6a3e 100644 --- a/application/api/controller/Production.php +++ b/application/api/controller/Production.php @@ -18,7 +18,7 @@ use think\log; class Production extends Base { - private $supportedTags = ['sup', 'sub', 'blue', 'b', 'i', 't', 'r']; + private $supportedTags = ['sup', 'sub', 'blue', 'b', 'i', 't', 'r', 'wmath']; // 颜色映射(自定义标签颜色对应LaTeX的HTML十六进制颜色) private $colorMap = [ 'blue' => '0082AA', @@ -2225,6 +2225,11 @@ class Production extends Base if (empty(trim($content))) { return ''; } + //单行处理公式内容 + + + + $refArray = []; foreach ($references as $ref) { $refArray[$ref['index'] + 1] = $ref; @@ -2263,55 +2268,13 @@ class Production extends Base */ private function textRenderCreate($content,$references) { $latex = ''; - - - if (preg_match('/(?:)?\[(\d+(?:[-,]\d+)*)\](?:<\/blue>)?/', $content, $matches)) { - // 去除匹配中的 - $cleanedMatch = str_replace(['', ''], '', $matches[0]); - // 提取引用编号部分(去掉方括号) - $referencePart = trim($cleanedMatch, '[]'); - - // 分割逗号分隔的不同引用项 - $parts = explode(',', $referencePart); - $latexRefs = []; - - foreach ($parts as $part) { - // 判断是否是范围形式如 3-5 - if (strpos($part, '-') !== false) { - list($start, $end) = explode('-', $part); - $start = intval($start); - $end = intval($end); - - // 展开范围并逐个查找 ref_id - for ($i = $start; $i <= $end; $i++) { - $arrayIndex = $i; - if (isset($references[$arrayIndex]) && !empty($references[$arrayIndex]['p_refer_id'])) { - $latexRefs[] = 'ref_' . $references[$arrayIndex]['p_refer_id']; - } else { - $latexRefs[] = $i; - } - } - } else { - // 单个引用编号处理 - $index = intval($part); - $arrayIndex = $index; - if (isset($references[$arrayIndex]) && !empty($references[$arrayIndex]['p_refer_id'])) { - $latexRefs[] = 'ref_' . $references[$arrayIndex]['p_refer_id']; - } else { - $latexRefs[] = $index; - } - } - } - return '\parencite{' . implode(',', $latexRefs) . '}'; - } - while (!empty($content)) { $nextTag = $this->determineNextTag($content); if ($nextTag === 'no') { // 无标签,转义特殊字符后直接拼接 $latex .= $this->escapeLatexSpecialChars($content); $content = ''; - } else { + }else { $tagOpen = "<{$nextTag}>"; $tagClose = ""; $beginTag = strpos($content, $tagOpen); @@ -2337,12 +2300,54 @@ class Production extends Base $endTag - $beginTag + strlen($tagClose) ); - // 解析标签内容并应用样式 - $style = []; - $tagContentList = []; - $this->getTextRenderData($tagWrappedContent, $nextTag, $style, $tagContentList); - // 拼接解析后的标签内容 - $latex .= implode('', $tagContentList); + + //这里处理引用 + if (preg_match('/(?:)?\[(\d+(?:[-,]\d+)*)\](?:<\/blue>)?/', $tagWrappedContent, $matches)) { + // 去除匹配中的 + $cleanedMatch = str_replace(['', ''], '', $matches[0]); + // 提取引用编号部分(去掉方括号) + $referencePart = trim($cleanedMatch, '[]'); + + // 分割逗号分隔的不同引用项 + $parts = explode(',', $referencePart); + $latexRefs = []; + + foreach ($parts as $part) { + // 判断是否是范围形式如 3-5 + if (strpos($part, '-') !== false) { + list($start, $end) = explode('-', $part); + $start = intval($start); + $end = intval($end); + + // 展开范围并逐个查找 ref_id + for ($i = $start; $i <= $end; $i++) { + $arrayIndex = $i; + if (isset($references[$arrayIndex]) && !empty($references[$arrayIndex]['p_refer_id'])) { + $latexRefs[] = 'ref_' . $references[$arrayIndex]['p_refer_id']; + } else { + $latexRefs[] = $i; + } + } + } else { + // 单个引用编号处理 + $index = intval($part); + $arrayIndex = $index; + if (isset($references[$arrayIndex]) && !empty($references[$arrayIndex]['p_refer_id'])) { + $latexRefs[] = 'ref_' . $references[$arrayIndex]['p_refer_id']; + } else { + $latexRefs[] = $index; + } + } + } + $latex .= '\parencite{' . implode(',', $latexRefs) . '}'; + }else{ + // 解析标签内容并应用样式 + $style = []; + $tagContentList = []; + $this->getTextRenderData($tagWrappedContent, $nextTag, $style, $tagContentList); + // 拼接解析后的标签内容 + $latex .= implode('', $tagContentList); + } // 剩余内容 $content = substr($content, $endTag + strlen($tagClose)); @@ -2429,54 +2434,65 @@ class Production extends Base * @param array $textRenderData 输出的LaTeX内容列表 */ private function getTextRenderData($now, $tag, &$style, &$textRenderData) { - // 应用当前标签的样式 - $this->addStyle($style, $tag); - // 提取标签内的内容(去掉前后标签) - $tagOpen = "<{$tag}>"; - $tagClose = ""; - $content = substr($now, strlen($tagOpen), strlen($now) - strlen($tagOpen) - strlen($tagClose)); - - while (!empty($content)) { - $nextTag = $this->determineNextTag($content); - if ($nextTag === 'no') { - // 无子标签,应用样式并添加内容 - $styledContent = $this->applyStyleToContent($this->escapeLatexSpecialChars($content), $style); + if($tag === 'wmath'){ + $pattern = '/data-latex="(.*?)"/'; + if (preg_match($pattern,$now, $matches1)) { + $latexContent = $matches1[1]; + // 将 $$ 转换为 $ + $latexContent = str_replace('$$', '$', $latexContent); + $styledContent = $this->applyStyleToContent($latexContent, $style); $textRenderData[] = $styledContent; - $content = ''; - } else { - $subTagOpen = "<{$nextTag}>"; - $subBeginTag = strpos($content, $subTagOpen); + } + }else{ + // 应用当前标签的样式 + $this->addStyle($style, $tag); + // 提取标签内的内容(去掉前后标签) + $tagOpen = "<{$tag}>"; + $tagClose = ""; + $content = substr($now, strlen($tagOpen), strlen($now) - strlen($tagOpen) - strlen($tagClose)); - // 子标签前的内容 - if ($subBeginTag > 0) { - $prefixContent = $this->escapeLatexSpecialChars(substr($content, 0, $subBeginTag)); - $styledPrefix = $this->applyStyleToContent($prefixContent, $style); - $textRenderData[] = $styledPrefix; - } - - // 找到子标签的最后闭合位置 - $subEndTag = $this->getLastTabIndex($content, $nextTag); - if ($subEndTag === false) { - // 无闭合标签,保留原内容 - $textRenderData[] = $this->escapeLatexSpecialChars(substr($content, $subBeginTag)); + while (!empty($content)) { + $nextTag = $this->determineNextTag($content); + if ($nextTag === 'no') { + // 无子标签,应用样式并添加内容 + $styledContent = $this->applyStyleToContent($this->escapeLatexSpecialChars($content), $style); + $textRenderData[] = $styledContent; $content = ''; - continue; + } else { + $subTagOpen = "<{$nextTag}>"; + $subBeginTag = strpos($content, $subTagOpen); + + // 子标签前的内容 + if ($subBeginTag > 0) { + $prefixContent = $this->escapeLatexSpecialChars(substr($content, 0, $subBeginTag)); + $styledPrefix = $this->applyStyleToContent($prefixContent, $style); + $textRenderData[] = $styledPrefix; + } + + // 找到子标签的最后闭合位置 + $subEndTag = $this->getLastTabIndex($content, $nextTag); + if ($subEndTag === false) { + // 无闭合标签,保留原内容 + $textRenderData[] = $this->escapeLatexSpecialChars(substr($content, $subBeginTag)); + $content = ''; + continue; + } + + // 子标签包裹的内容 + $subNow = substr( + $content, + $subBeginTag, + $subEndTag - $subBeginTag + strlen("") + ); + + // 深拷贝样式(避免父级样式被修改) + $newStyle = $this->deepCopy($style); + // 递归解析子标签 + $this->getTextRenderData($subNow, $nextTag, $newStyle, $textRenderData); + + // 剩余内容 + $content = substr($content, $subEndTag + strlen("")); } - - // 子标签包裹的内容 - $subNow = substr( - $content, - $subBeginTag, - $subEndTag - $subBeginTag + strlen("") - ); - - // 深拷贝样式(避免父级样式被修改) - $newStyle = $this->deepCopy($style); - // 递归解析子标签 - $this->getTextRenderData($subNow, $nextTag, $newStyle, $textRenderData); - - // 剩余内容 - $content = substr($content, $subEndTag + strlen("")); } } }