Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#437 优化插入公式选择模板的功能,并增加预览区域公式导出、复制操作 #537

Merged
merged 1 commit into from
Aug 21, 2023

Conversation

ufec
Copy link
Collaborator

@ufec ufec commented Aug 20, 2023

@ufec
Copy link
Collaborator Author

ufec commented Aug 20, 2023

获取 https://www.latexlive.com 上的数据,配置到cherry上的方法
至于怎么获取 api.json,参考 https://www.latexlive.com

const fs = require('node:fs');

const jsonStr = fs.readFileSync('./api.json', 'utf8');

const api = JSON.parse(jsonStr);

const myobj = {};

const oss = 'https://latexlive-resourse.oss-cn-beijing.aliyuncs.com';

api.shortcut.reduce((acc, cur) => {
  const obj = {
    title: cur.descript,
    subCategory: {},
  };
  cur.layer1.cont.reduce((layer1Acc, layer1Cur) => {
    const obj2 = {
      title: layer1Cur.descript,
      img: oss + cur.layer1.path + layer1Cur.name,
      formulas: cur.layer2.cont[layer1Cur.tag].cont.map((layer2Val) => {
        let img = '';
        let name = '';
        if (layer2Val.name.includes('.svg') || layer2Val.name.includes('.png')) {
          img = `${oss + cur.layer2.path + layer1Cur.tag}/${layer2Val.name}`;
        } else {
          name = layer2Val.name;
        }
        let formulaStyle = '';
        if (layer2Val.latex !== '') {
          const isNum = isNaN(Number(cur.layer2.cont[layer1Cur.tag].defaultsize));
          formulaStyle = `width: ${cur.layer2.cont[layer1Cur.tag].defaultsize}${isNum ? '' : 'rem'}`;
        }
        return {
          name,
          img,
          latex: layer2Val.latex,
          formulaStyle,
        };
      }),
    };
    layer1Acc[layer1Cur.tag] = obj2;
    return layer1Acc;
  }, obj.subCategory);
  acc[cur.name] = obj;
  return acc;
}, myobj);

console.log(JSON.stringify(myobj));

@sunsonliu sunsonliu merged commit 0e40577 into Tencent:dev Aug 21, 2023
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants