Uniorg是与统一生态系统兼容的准确的机构模式解析器。
我想从org-mode笔记中发布我的脑袋。我尝试过的任何解析器都没有提供足够的精度。
Uniorg努力解析准确性,而不是速度或易于编写解析器。
Uniorg遵循组织语法和组织元素API。它从org-element.el绘制大量绘制,这意味着Uniorg以与Org-Mode相同的方式看到org文件。该代码充满了重视,但这正是Org模式解析文件的方式。
但是,有几个故意与Org模式的偏差,使Uniorg更愉快或更易于使用。
Uniorg成功解析了大多数组织语法。但是,有几个我尚未完成的地方:
该语法的其余部分应与EMAC(包括复杂列表嵌套,链接,抽屉,时钟条目,乳胶等)完全相同的方式工作。如果您想帮助上面的项目,请grep parser.ts for TODO:
此存储库包含以下软件包:
uniorg - Uniorg语法树的打字稿定义uniorg-parse - parse org模式文件到Uniorg语法树uniorg-stringify - Stringify Uniorg语法树到Org-Mode Stringuniorg-rehype - 将Uniorg语法树转换为重新构想uniorg-extract-keywords - 存储org-mode关键字到VFILEuniorg-attach - 转换attachment:链接到file:链接uniorg-slug - 使用GitHub的算法为标题添加锚点orgast-util-to-string - 效用以获取节点的纯文本内容orgast-util-visit-ids - 访问所有有ID的组织节点的实用程序Uniorg与统一的生态系统兼容,因此您可以利用许多现有的插件。
例如,这是您将组织模式转换为HTML的方式。
import { unified } from 'unified' ;
import parse from 'uniorg-parse' ;
import uniorg2rehype from 'uniorg-rehype' ;
import stringify from 'rehype-stringify' ;
const processor = unified ( ) . use ( parse ) . use ( uniorg2rehype ) . use ( stringify ) ;
processor
. process ( `* org-mode examplen your text goes here` )
. then ( ( file ) => console . log ( file . value ) ) ;代码语法的插件突出显示(rehype-highlight, @mapbox/rehype-prism)和latex-formatting(rehype-katex,rehype-mathjax)应开箱即用:
import { unified } from 'unified' ;
import parse from 'uniorg-parse' ;
import uniorg2rehype from 'uniorg-rehype' ;
import highlight from 'rehype-highlight' ;
import katex from 'rehype-katex' ;
import stringify from 'rehype-stringify' ;
const processor = unified ( )
. use ( parse )
. use ( uniorg2rehype )
. use ( highlight )
. use ( katex )
. use ( stringify ) ;
processor
. process (
`* org-mode example
When $a ne 0$, there are two solutions to (ax^2 + bx + c = 0) and they are
$$x = {-b pm sqrt{b^2-4ac} over 2a}.$$
#+begin_src js
console.log('uniorg is cool!');
#+end_src
`
)
. then ( ( file ) => console . log ( file . value ) ) ;GNU通用公共许可证v3.0或更高版本