mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-25 08:24:06 +01:00
ECharts 图表块支持 loose-json (#6917)
* 🎨 ECharts 图表块支持 loose-json * 📝 更新用户手册 ECharts 相关内容 * 📝 更新用户手册 ECharts 相关内容
This commit is contained in:
parent
a96d6a019f
commit
27c9ac2b25
5 changed files with 799 additions and 28 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import {addScript} from "../util/addScript";
|
||||
import {Constants} from "../../constants";
|
||||
import {hasClosestByClassName} from "../util/hasClosest";
|
||||
import {looseJsonParse} from "../../util/functions";
|
||||
|
||||
export const chartRender = (element: Element, cdn = Constants.PROTYLE_CDN) => {
|
||||
let echartsElements: Element[] = [];
|
||||
|
|
@ -38,7 +39,7 @@ export const chartRender = (element: Element, cdn = Constants.PROTYLE_CDN) => {
|
|||
const renderElement = e.firstElementChild.nextElementSibling as HTMLElement;
|
||||
try {
|
||||
renderElement.style.height = e.style.height;
|
||||
const option = JSON.parse(Lute.UnEscapeHTMLStr(e.getAttribute("data-content")));
|
||||
const option = looseJsonParse(Lute.UnEscapeHTMLStr(e.getAttribute("data-content")));
|
||||
echarts.init(renderElement, window.siyuan.config.appearance.mode === 1 ? "dark" : undefined, {width}).setOption(option);
|
||||
e.setAttribute("data-render", "true");
|
||||
renderElement.classList.remove("ft__error");
|
||||
|
|
|
|||
|
|
@ -45,3 +45,8 @@ export const isDynamicRef = (text: string) => {
|
|||
export const isFileAnnotation = (text: string) => {
|
||||
return /^<<assets\/.+\/\d{14}-\w{7} ".+">>$/.test(text);
|
||||
};
|
||||
|
||||
// REF https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/eval
|
||||
export const looseJsonParse = (text: string) => {
|
||||
return Function(`"use strict";return (${text})`)();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue