Преглед изворни кода

修复题目显示错误以及浅主题色设置

shmily1213 пре 1 месец
родитељ
комит
b00f512ee5
2 измењених фајлова са 69 додато и 6 уклоњено
  1. 1 1
      src/static/theme/var.scss
  2. 68 5
      src/uni_modules/mp-html/components/mp-html/parser.js

+ 1 - 1
src/static/theme/var.scss

@@ -1,5 +1,5 @@
 $ie: #31A0FC;
-$ie-light: #E5F1ED;
+$ie-light: #66b7fa;
 
 // 基础色,不随主题改变
 $fore-title: #222;

+ 68 - 5
src/uni_modules/mp-html/components/mp-html/parser.js

@@ -1262,6 +1262,39 @@ Lexer.prototype.text = function () {
   }
   const c = this.content[this.i + 1]
   if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
+    // 检查是否是有效的标签开头
+    // 查找下一个 > 符号来验证这是否真的是一个标签
+    let tagEndPos = this.content.indexOf('>', this.i + 1)
+    // 如果找不到 > 或者在 > 之前遇到另一个 <,说明这不是有效的标签
+    let nextLtPos = this.content.indexOf('<', this.i + 1)
+    if (tagEndPos === -1 || (nextLtPos !== -1 && nextLtPos < tagEndPos)) {
+      // 这不是有效的标签,将 < 作为普通文本处理
+      this.i++
+      return
+    }
+    
+    // 提取标签名,验证是否是已知的HTML标签
+    let tagNameEnd = this.i + 1
+    while (tagNameEnd < tagEndPos && this.content[tagNameEnd] !== ' ' && this.content[tagNameEnd] !== '/' && !blankChar[this.content[tagNameEnd]]) {
+      tagNameEnd++
+    }
+    const possibleTagName = this.content.substring(this.i + 1, tagNameEnd).toLowerCase()
+    
+    // 检查是否是已知的HTML标签或SVG标签
+    const isValidTag = config.trustTags[possibleTagName] || 
+                       config.blockTags[possibleTagName] || 
+                       config.ignoreTags[possibleTagName] || 
+                       config.voidTags[possibleTagName] ||
+                       config.svgDict[possibleTagName] ||
+                       possibleTagName === 'svg' ||
+                       possibleTagName === 'foreignobject'
+    
+    if (!isValidTag) {
+      // 不是已知标签,将 < 作为普通文本处理
+      this.i++
+      return
+    }
+    
     // 标签开头
     if (this.start !== this.i) {
       this.handler.onText(this.content.substring(this.start, this.i))
@@ -1269,18 +1302,48 @@ Lexer.prototype.text = function () {
     this.start = ++this.i
     this.state = this.tagName
   } else if (c === '/' || c === '!' || c === '?') {
-    if (this.start !== this.i) {
-      this.handler.onText(this.content.substring(this.start, this.i))
-    }
     const next = this.content[this.i + 2]
     if (c === '/' && ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
-      // 标签结尾
+      // 可能是结束标签,需要验证
+      let tagEndPos = this.content.indexOf('>', this.i + 2)
+      if (tagEndPos !== -1) {
+        // 提取结束标签名进行验证
+        let tagNameEnd = this.i + 2
+        while (tagNameEnd < tagEndPos && this.content[tagNameEnd] !== ' ' && this.content[tagNameEnd] !== '/' && !blankChar[this.content[tagNameEnd]]) {
+          tagNameEnd++
+        }
+        const possibleTagName = this.content.substring(this.i + 2, tagNameEnd).toLowerCase()
+        
+        // 检查是否是已知的HTML标签
+        const isValidTag = config.trustTags[possibleTagName] || 
+                           config.blockTags[possibleTagName] || 
+                           config.ignoreTags[possibleTagName] || 
+                           config.voidTags[possibleTagName] ||
+                           config.svgDict[possibleTagName] ||
+                           possibleTagName === 'svg' ||
+                           possibleTagName === 'foreignobject'
+        
+        if (!isValidTag) {
+          // 不是已知标签,将 </ 作为普通文本处理
+          this.i++
+          return
+        }
+      }
+      
+      // 是有效的结束标签
+      if (this.start !== this.i) {
+        this.handler.onText(this.content.substring(this.start, this.i))
+      }
       this.i += 2
       this.start = this.i
       this.state = this.endTag
       return
     }
-    // 处理注释
+    
+    // 处理注释和其他特殊标签
+    if (this.start !== this.i) {
+      this.handler.onText(this.content.substring(this.start, this.i))
+    }
     let end = '-->'
     if (c !== '!' || this.content[this.i + 2] !== '-' || this.content[this.i + 3] !== '-') {
       end = '>'