yuque-exporter icon indicating copy to clipboard operation
yuque-exporter copied to clipboard

请问能不能导出语雀公式,并且区分行内和行间公式?

Open alephpiece opened this issue 1 year ago • 2 comments

#29 这个 issue 里面用 python 替换语雀公式图片链接为链接包含的公式,我改写到doc.ts里面之后也可以用。

function recoverMathBlocks(mdstring) {
  return mdstring.replaceAll(
    /\!\[\]\(https.*?\/\_\_latex\/.*?\&code\=(.*?)\\\&.*?\)/g,
    (match, p1, offset, string) => {
      const mathExp = decodeUriComponent(p1);
      return mathExp.includes('\\begin') || mathExp.includes('$')
        ? `\$\$\n${mathExp}\n\$\$`
        : `\$${mathExp}\$`;
    }
  );
}

但是怎么区分行内和行间公式?从链接中的code=部分好像看不出来,不知道有没有其他的解决方法? 而且我这里用了正则表达式,感觉很容易出错。本来想用 remark 直接处理,但是 remark 没有 math node,插件我也完全不熟。

alephpiece avatar Oct 02 '23 04:10 alephpiece

发现有一些链接是![](data:image/svg+xml;...形式的,可能是以前旧链接?在语雀里面把公式拷贝出来重新粘贴到新公式块就会变成cdn.nlark.com链接。

alephpiece avatar Oct 02 '23 06:10 alephpiece

发现有一些链接是![](data:image/svg+xml;...形式的,可能是以前旧链接?在语雀里面把公式拷贝出来重新粘贴到新公式块就会变成cdn.nlark.com链接。

最后我把所有前后有换行<br/>的全都当成行间的独立公式了。

alephpiece avatar Oct 07 '23 08:10 alephpiece