figer update

This commit is contained in:
wangjinlei
2026-01-06 17:34:05 +08:00
parent 041141a68e
commit 87f6a01c94

View File

@@ -18,7 +18,7 @@ use think\log;
class Production extends Base 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十六进制颜色 // 颜色映射自定义标签颜色对应LaTeX的HTML十六进制颜色
private $colorMap = [ private $colorMap = [
'blue' => '0082AA', 'blue' => '0082AA',
@@ -2225,6 +2225,11 @@ class Production extends Base
if (empty(trim($content))) { if (empty(trim($content))) {
return ''; return '';
} }
//单行处理公式内容
$refArray = []; $refArray = [];
foreach ($references as $ref) { foreach ($references as $ref) {
$refArray[$ref['index'] + 1] = $ref; $refArray[$ref['index'] + 1] = $ref;
@@ -2263,9 +2268,41 @@ class Production extends Base
*/ */
private function textRenderCreate($content,$references) { private function textRenderCreate($content,$references) {
$latex = ''; $latex = '';
while (!empty($content)) {
$nextTag = $this->determineNextTag($content);
if ($nextTag === 'no') {
// 无标签,转义特殊字符后直接拼接
$latex .= $this->escapeLatexSpecialChars($content);
$content = '';
}else {
$tagOpen = "<{$nextTag}>";
$tagClose = "</{$nextTag}>";
$beginTag = strpos($content, $tagOpen);
// 标签前的文本
if ($beginTag > 0) {
$latex .= $this->escapeLatexSpecialChars(substr($content, 0, $beginTag));
}
// 找到标签的最后闭合位置(处理嵌套)
$endTag = $this->getLastTabIndex($content, $nextTag);
if ($endTag === false) {
// 无闭合标签,保留原内容(异常情况处理)
$latex .= $this->escapeLatexSpecialChars(substr($content, $beginTag));
$content = '';
continue;
}
// 截取标签包裹的内容(包含标签)
$tagWrappedContent = substr(
$content,
$beginTag,
$endTag - $beginTag + strlen($tagClose)
);
if (preg_match('/(?:<blue>)?\[(\d+(?:[-,]\d+)*)\](?:<\/blue>)?/', $content, $matches)) { //这里处理引用
if (preg_match('/(?:<blue>)?\[(\d+(?:[-,]\d+)*)\](?:<\/blue>)?/', $tagWrappedContent, $matches)) {
// 去除匹配中的 <blue> 和 </blue> // 去除匹配中的 <blue> 和 </blue>
$cleanedMatch = str_replace(['<blue>', '</blue>'], '', $matches[0]); $cleanedMatch = str_replace(['<blue>', '</blue>'], '', $matches[0]);
// 提取引用编号部分(去掉方括号) // 提取引用编号部分(去掉方括号)
@@ -2302,47 +2339,15 @@ class Production extends Base
} }
} }
} }
return '\parencite{' . implode(',', $latexRefs) . '}'; $latex .= '\parencite{' . implode(',', $latexRefs) . '}';
}
while (!empty($content)) {
$nextTag = $this->determineNextTag($content);
if ($nextTag === 'no') {
// 无标签,转义特殊字符后直接拼接
$latex .= $this->escapeLatexSpecialChars($content);
$content = '';
}else{ }else{
$tagOpen = "<{$nextTag}>";
$tagClose = "</{$nextTag}>";
$beginTag = strpos($content, $tagOpen);
// 标签前的文本
if ($beginTag > 0) {
$latex .= $this->escapeLatexSpecialChars(substr($content, 0, $beginTag));
}
// 找到标签的最后闭合位置(处理嵌套)
$endTag = $this->getLastTabIndex($content, $nextTag);
if ($endTag === false) {
// 无闭合标签,保留原内容(异常情况处理)
$latex .= $this->escapeLatexSpecialChars(substr($content, $beginTag));
$content = '';
continue;
}
// 截取标签包裹的内容(包含标签)
$tagWrappedContent = substr(
$content,
$beginTag,
$endTag - $beginTag + strlen($tagClose)
);
// 解析标签内容并应用样式 // 解析标签内容并应用样式
$style = []; $style = [];
$tagContentList = []; $tagContentList = [];
$this->getTextRenderData($tagWrappedContent, $nextTag, $style, $tagContentList); $this->getTextRenderData($tagWrappedContent, $nextTag, $style, $tagContentList);
// 拼接解析后的标签内容 // 拼接解析后的标签内容
$latex .= implode('', $tagContentList); $latex .= implode('', $tagContentList);
}
// 剩余内容 // 剩余内容
$content = substr($content, $endTag + strlen($tagClose)); $content = substr($content, $endTag + strlen($tagClose));
@@ -2429,6 +2434,16 @@ class Production extends Base
* @param array $textRenderData 输出的LaTeX内容列表 * @param array $textRenderData 输出的LaTeX内容列表
*/ */
private function getTextRenderData($now, $tag, &$style, &$textRenderData) { private function getTextRenderData($now, $tag, &$style, &$textRenderData) {
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;
}
}else{
// 应用当前标签的样式 // 应用当前标签的样式
$this->addStyle($style, $tag); $this->addStyle($style, $tag);
// 提取标签内的内容(去掉前后标签) // 提取标签内的内容(去掉前后标签)
@@ -2480,6 +2495,7 @@ class Production extends Base
} }
} }
} }
}
/** /**
* 对应Java的deepCopy方法深拷贝样式数组 * 对应Java的deepCopy方法深拷贝样式数组