latex update
This commit is contained in:
@@ -18,7 +18,7 @@ use think\log;
|
|||||||
class Production extends Base
|
class Production extends Base
|
||||||
{
|
{
|
||||||
|
|
||||||
private $supportedTags = ['sup', 'sub', 'blue', 'b', 'i', 't', 'r', 'wmath'];
|
private $supportedTags = ['sup', 'sub', 'blue', 'b', 'i', 't', 'r', 'wmath','myfigure','mytable'];
|
||||||
// 颜色映射(自定义标签颜色对应LaTeX的HTML十六进制颜色)
|
// 颜色映射(自定义标签颜色对应LaTeX的HTML十六进制颜色)
|
||||||
private $colorMap = [
|
private $colorMap = [
|
||||||
'blue' => '0082AA',
|
'blue' => '0082AA',
|
||||||
@@ -2033,6 +2033,7 @@ class Production extends Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function creatLatex(){
|
public function creatLatex(){
|
||||||
|
die("stop service");
|
||||||
$data = $this->request->post();
|
$data = $this->request->post();
|
||||||
$rule = new Validate([
|
$rule = new Validate([
|
||||||
"article_id"=>"require"
|
"article_id"=>"require"
|
||||||
@@ -2248,8 +2249,8 @@ class Production extends Base
|
|||||||
return jsonError($rule->getError());
|
return jsonError($rule->getError());
|
||||||
}
|
}
|
||||||
$info = $this->article_main_obj->where("am_id",$data['id'])->find();
|
$info = $this->article_main_obj->where("am_id",$data['id'])->find();
|
||||||
if(isset($data["code"])){
|
if(isset($data["content"])){
|
||||||
$content = $data['code'];
|
$content = $data['content'];
|
||||||
}else{
|
}else{
|
||||||
$content = $info['content'];
|
$content = $info['content'];
|
||||||
}
|
}
|
||||||
@@ -2270,9 +2271,21 @@ class Production extends Base
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
//单行处理公式内容
|
//单行处理公式内容
|
||||||
$pattern = '/^<wmath[^>]*?\s+data-latex="([^"]*)"[^>]*?>.*?<\/wmath>$/';
|
/* $pattern = '/^<wmath[^>]*?\s+data-latex="([^"]*)"[^>]*?>.*?<\/wmath>$/';*/
|
||||||
|
// if(preg_match($pattern, $content) === 1){
|
||||||
|
// $pattern1 = '/<wmath[^>]*?\s+data-latex="([^"]*)">/';
|
||||||
|
// if (preg_match($pattern1, $content, $matches)) {
|
||||||
|
// $latexContent = $matches[1];
|
||||||
|
// // 将 $$ 转换为 $,因为equation环境不需要$$
|
||||||
|
// $latexContent = str_replace('$$', '', $latexContent);
|
||||||
|
//
|
||||||
|
// return "\\begin{equation}\n\t{$latexContent}\n\\end{equation}";
|
||||||
|
// }
|
||||||
|
// return $content;
|
||||||
|
// }
|
||||||
|
$pattern = '/^<wmath[^>]*?\s+data-latex="([^"]*)"[^>]*?\s+data-wrap="block"[^>]*?>.*?<\/wmath>$/';
|
||||||
if(preg_match($pattern, $content) === 1){
|
if(preg_match($pattern, $content) === 1){
|
||||||
$pattern1 = '/<wmath[^>]*?\s+data-latex="([^"]*)">/';
|
$pattern1 = '/<wmath[^>]*?\s+data-latex="([^"]*)"[^>]*?\s+data-wrap="block"[^>]*?>/';
|
||||||
if (preg_match($pattern1, $content, $matches)) {
|
if (preg_match($pattern1, $content, $matches)) {
|
||||||
$latexContent = $matches[1];
|
$latexContent = $matches[1];
|
||||||
// 将 $$ 转换为 $,因为equation环境不需要$$
|
// 将 $$ 转换为 $,因为equation环境不需要$$
|
||||||
@@ -2330,10 +2343,9 @@ class Production extends Base
|
|||||||
$latex .= $this->escapeLatexSpecialChars($content);
|
$latex .= $this->escapeLatexSpecialChars($content);
|
||||||
$content = '';
|
$content = '';
|
||||||
}else {
|
}else {
|
||||||
$tagOpen = "<{$nextTag}>";
|
$tagOpen = "<{$nextTag}";
|
||||||
$tagClose = "</{$nextTag}>";
|
$tagClose = "</{$nextTag}>";
|
||||||
$beginTag = strpos($content, $tagOpen);
|
$beginTag = strpos($content, $tagOpen);
|
||||||
|
|
||||||
// 标签前的文本
|
// 标签前的文本
|
||||||
if ($beginTag > 0) {
|
if ($beginTag > 0) {
|
||||||
$latex .= $this->escapeLatexSpecialChars(substr($content, 0, $beginTag));
|
$latex .= $this->escapeLatexSpecialChars(substr($content, 0, $beginTag));
|
||||||
@@ -2341,6 +2353,7 @@ class Production extends Base
|
|||||||
|
|
||||||
// 找到标签的最后闭合位置(处理嵌套)
|
// 找到标签的最后闭合位置(处理嵌套)
|
||||||
$endTag = $this->getLastTabIndex($content, $nextTag);
|
$endTag = $this->getLastTabIndex($content, $nextTag);
|
||||||
|
|
||||||
if ($endTag === false) {
|
if ($endTag === false) {
|
||||||
// 无闭合标签,保留原内容(异常情况处理)
|
// 无闭合标签,保留原内容(异常情况处理)
|
||||||
$latex .= $this->escapeLatexSpecialChars(substr($content, $beginTag));
|
$latex .= $this->escapeLatexSpecialChars(substr($content, $beginTag));
|
||||||
@@ -2355,7 +2368,6 @@ class Production extends Base
|
|||||||
$endTag - $beginTag + strlen($tagClose)
|
$endTag - $beginTag + strlen($tagClose)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
//这里处理引用
|
//这里处理引用
|
||||||
if ($check_refer&&preg_match('/(?:<blue>)?\[(\d+(?:[-,]\d+)*)\](?:<\/blue>)?/', $tagWrappedContent, $matches)) {
|
if ($check_refer&&preg_match('/(?:<blue>)?\[(\d+(?:[-,]\d+)*)\](?:<\/blue>)?/', $tagWrappedContent, $matches)) {
|
||||||
// 去除匹配中的 <blue> 和 </blue>
|
// 去除匹配中的 <blue> 和 </blue>
|
||||||
@@ -2419,7 +2431,7 @@ class Production extends Base
|
|||||||
* @return int|false 闭合标签的起始位置
|
* @return int|false 闭合标签的起始位置
|
||||||
*/
|
*/
|
||||||
private function getLastTabIndex($content, $tag) {
|
private function getLastTabIndex($content, $tag) {
|
||||||
$tagOpen = "<{$tag}>";
|
$tagOpen = "<{$tag}";
|
||||||
$tagClose = "</{$tag}>";
|
$tagClose = "</{$tag}>";
|
||||||
|
|
||||||
$beginTag = strpos($content, $tagOpen);
|
$beginTag = strpos($content, $tagOpen);
|
||||||
@@ -2435,7 +2447,7 @@ class Production extends Base
|
|||||||
|
|
||||||
// 统计当前标签内的开放标签数量
|
// 统计当前标签内的开放标签数量
|
||||||
$caNowStr = substr($content, $beginTag, $endTagCa - $beginTag + strlen($tagClose));
|
$caNowStr = substr($content, $beginTag, $endTagCa - $beginTag + strlen($tagClose));
|
||||||
$caCount = preg_match_all("/<{$tag}>/", $caNowStr, $matches);
|
$caCount = preg_match_all("/<{$tag}/", $caNowStr, $matches);
|
||||||
|
|
||||||
if ($caCount === 1) {
|
if ($caCount === 1) {
|
||||||
return $endTagCa;
|
return $endTagCa;
|
||||||
@@ -2448,7 +2460,7 @@ class Production extends Base
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$substring = substr($content, $beginTag, $numIndex - $beginTag + strlen($tagClose));
|
$substring = substr($content, $beginTag, $numIndex - $beginTag + strlen($tagClose));
|
||||||
$ccaCount = preg_match_all("/<{$tag}>/", $substring, $matches);
|
$ccaCount = preg_match_all("/<{$tag}/", $substring, $matches);
|
||||||
if ($ccaCount !== $caCount) {
|
if ($ccaCount !== $caCount) {
|
||||||
$caCount = $ccaCount;
|
$caCount = $ccaCount;
|
||||||
} else {
|
} else {
|
||||||
@@ -2601,7 +2613,7 @@ class Production extends Base
|
|||||||
* @return string 标签名或'no'
|
* @return string 标签名或'no'
|
||||||
*/
|
*/
|
||||||
private function determineNextTag($content) {
|
private function determineNextTag($content) {
|
||||||
$tagPattern = '/<(' . implode('|', $this->supportedTags) . ')>/i';
|
$tagPattern = '/<(' . implode('|', $this->supportedTags) . ')\b[^>]*>/i';
|
||||||
if (preg_match($tagPattern, $content, $matches)) {
|
if (preg_match($tagPattern, $content, $matches)) {
|
||||||
return $matches[1];
|
return $matches[1];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user