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或更高版本