am-editor11212/plugins/math
yanmao 75b12cd0fd Publish
- @aomao/engine@2.7.10
 - @aomao/toolbar-vue@2.7.10
 - @aomao/toolbar@2.7.10
 - @aomao/plugin-alignment@2.7.10
 - @aomao/plugin-backcolor@2.7.10
 - @aomao/plugin-bold@2.7.10
 - @aomao/plugin-code@2.7.10
 - @aomao/plugin-codeblock-vue@2.7.10
 - @aomao/plugin-codeblock@2.7.10
 - @aomao/plugin-embed@2.7.10
 - @aomao/plugin-file@2.7.10
 - @aomao/plugin-fontcolor@2.7.10
 - @aomao/plugin-fontfamily@2.7.10
 - @aomao/plugin-fontsize@2.7.10
 - @aomao/plugin-heading@2.7.10
 - @aomao/plugin-hr@2.7.10
 - @aomao/plugin-image@2.7.10
 - @aomao/plugin-indent@2.7.10
 - @aomao/plugin-italic@2.7.10
 - @aomao/plugin-line-height@2.7.10
 - @aomao/plugin-link-vue@2.7.10
 - @aomao/plugin-link@2.7.10
 - @aomao/plugin-mark-range@2.7.10
 - @aomao/plugin-mark@2.7.10
 - @aomao/plugin-math@2.7.10
 - @aomao/plugin-mention@2.7.10
 - @aomao/plugin-mind@2.7.10
 - @aomao/plugin-orderedlist@2.7.10
 - @aomao/plugin-paintformat@2.7.10
 - @aomao/plugin-quote@2.7.10
 - @aomao/plugin-redo@2.7.10
 - @aomao/plugin-removeformat@2.7.10
 - @aomao/plugin-selectall@2.7.10
 - @aomao/plugin-status@2.7.10
 - @aomao/plugin-strikethrough@2.7.10
 - @aomao/plugin-sub@2.7.10
 - @aomao/plugin-sup@2.7.10
 - @aomao/plugin-table@2.7.10
 - @aomao/plugin-tasklist@2.7.10
 - @aomao/plugin-underline@2.7.10
 - @aomao/plugin-undo@2.7.10
 - @aomao/plugin-unorderedlist@2.7.10
 - @aomao/plugin-video@2.7.10
2022-01-06 16:20:52 +08:00
..
src update: lodash-es -> lodash 2021-12-29 02:53:42 +08:00
README.md feat: yanmao.cc -> aomao.com 2021-12-05 00:37:05 +08:00
package.json Publish 2022-01-06 16:20:52 +08:00
tsconfig.json init 2021-11-03 19:58:08 +08:00

README.md

@aomao/plugin-math

数学公式

安装

$ yarn add @aomao/plugin-math

添加到引擎

import Engine, { EngineInterface } from '@aomao/engine';
import Math , { MathComponent } from '@aomao/plugin-math';

new Engine(...,{ plugins:[ Math ] , cards:[ MathComponent ]})

Math 可选项

//使用配置
new Engine(...,{
    config:{
        [Math.pluginName]:{
            //...相关配置
        }
    }
 })

请求生成公式代码为图片或 SVG

action: 请求地址,始终使用 POST 请求

type: 默认为 json

contentType: 默认以 application/json 类型发起请求

data: 请求时将这些数据一起POST到服务端

/**
 * 请求生成公式svg地址
 */
action: string;
/**
 * 数据返回类型,默认 json
 */
type?: '*' | 'json' | 'xml' | 'html' | 'text' | 'js';
/**
 * 额外携带数据上传
 */
data?: {};
/**
 * 请求类型,默认 application/json;
 */
contentType?: string;

配置后,插件会使用 content 字段 POST 到指定的 action 地址,里面包含了公式代码

解析服务端响应数据

默认会查找

公式对应图片地址或SVG代码response.url || response.data && response.data.url

result: true 生成成功data 为公式对应图片地址或SVG代码。false 生成失败data 为错误消息

/**
 * 解析生成后的Respone返回 result:是否成功data:成功:公式对应图片地址或`SVG`代码,失败:错误信息
 */
parse?: (
    response: any,
) => {
    result: boolean;
    data: string;
};

画图接口

可以使用 https://g.aomao.com/latex 地址生成公式对应的 SVG 代码。该项目使用mathjax 生成 SVG 代码

演示站点:https://drawing.aomao.com/

配置:

[Math.pluginName]: {
    action: `https://g.aomao.com/latex`,
    parse: (res: any) => {
        if(res.success) return { result: true, data: res.svg}
        return { result: false}
    }
}

命令

插入公式代码

参数 1公式代码

参数 2公式对应图片地址或SVG代码

engine.command.execute(
	Math.pluginName,
	'公式代码', //可选
	'公式对应图片地址或`SVG`代码', //可选
);

请求生成公式代码图片或 SVG

参数 1固定为 query 参数 2成功后的回调 参数 3失败后的回调。可选

engine.command.execute(Math.pluginName, "query", success:(url: string) => void, failed: (message: string) => void);