Initial commit

This commit is contained in:
admin
2025-12-08 14:39:07 +08:00
commit 9d4f78656b
782 changed files with 66418 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
# latex
功能:渲染 *latex* 公式
大小:**≈300KB**
作者:[@Zeng-J](https://github.com/Zeng-J)
支持平台:
| 微信小程序 | QQ 小程序 | 百度小程序 | 支付宝小程序 | 头条小程序 | uni-app |
|:---:|:---:|:---:|:---:|:---:|:---:|
| √ | √ | √ | √ | √ | √ |
说明:
引入本插件后,会将 *$xxx$* 的文本内容按照 *latex* 规则进行解析和渲染
> 与 *editable* 插件共用时,编辑状态下,公式不会渲染,可以直接修改公式文本
> 本插件通过 [katex-mini](https://github.com/rojer95/katex-mini) 解析 *latex* 文本,[字体文件](https://github.com/KaTeX/KaTeX/tree/main/fonts) 建议自行转存

View File

@@ -0,0 +1,14 @@
module.exports = {
import: 'katex.css',
handler (file) {
if (file.isBuffer()) {
let content = file.contents.toString()
if (file.basename === 'node.wxml') {
content = content.replace(/(n.?)\.name==='a'\|\|/g, "$1.name==='a'||$1.l||")
} else if (file.basename === 'node.vue') {
content = content.replace(/!handler.isInline\((.*?)\)/, '(n.l||!handler.isInline($1))')
}
file.contents = Buffer.from(content)
}
}
}

View File

@@ -0,0 +1,80 @@
/**
* @fileoverview latex 插件
* katex.min.js来源 https://github.com/rojer95/katex-mini
*/
const parse = require('./katex.min')
function Latex () {
}
Latex.prototype.onParse = function (node, vm) {
// $...$包裹的内容为latex公式
if (!vm.options.editable && node.type === 'text' && node.text.includes('$')) {
const part = node.text.split(/(\${1,2})/)
const children = []
let status = 0
for (let i = 0; i < part.length; i++) {
if (i % 2 === 0) {
// 文本内容
if (part[i]) {
if (status === 0) {
children.push({
type: 'text',
text: part[i]
})
} else {
if (status === 1) {
// 行内公式
const nodes = parse.default(part[i])
children.push({
name: 'span',
attrs: {},
l: 'T',
f: 'display:inline-block',
children: nodes
})
} else {
// 块公式
const nodes = parse.default(part[i], {
displayMode: true
})
children.push({
name: 'div',
attrs: {
style: 'text-align:center'
},
children: nodes
})
}
}
}
} else {
// 分隔符
if (part[i] === '$' && part[i + 2] === '$') {
// 行内公式
status = 1
part[i + 2] = ''
} else if (part[i] === '$$' && part[i + 2] === '$$') {
// 块公式
status = 2
part[i + 2] = ''
} else {
if (part[i] && part[i] !== '$$') {
// 普通$符号
part[i + 1] = part[i] + part[i + 1]
}
// 重置状态
status = 0
}
}
}
delete node.type
delete node.text
node.name = 'span'
node.attrs = {}
node.children = children
}
}
module.exports = Latex

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long