-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reoff-unified-latex): add reoff-unified-latex converter
- Loading branch information
Showing
13 changed files
with
1,083 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/swcrc", | ||
"jsc": { | ||
"target": "es2017", | ||
"parser": { | ||
"syntax": "typescript", | ||
"decorators": true, | ||
"dynamicImport": true | ||
}, | ||
"transform": { | ||
"decoratorMetadata": true, | ||
"legacyDecorator": true | ||
}, | ||
|
||
"externalHelpers": true, | ||
"loose": true | ||
}, | ||
"module": { | ||
"type": "es6", | ||
"strict": true, | ||
"noInterop": true | ||
}, | ||
"sourceMaps": true, | ||
"exclude": [ | ||
"jest.config.ts", | ||
".*.spec.tsx?$", | ||
".*.test.tsx?$", | ||
"./src/jest-setup.ts$", | ||
"./**/jest-setup.ts$", | ||
".*.js$" | ||
] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# reoff-unified-latex | ||
|
||
Plugin for `reoff` that takes an `ooxast` tree and turns it into a `unified-latex` tree, allowing for .docx to .tex conversion | ||
|
||
## Contents | ||
|
||
- [reoff-unified-latex](#reoff-unified-latex) | ||
- [Contents](#contents) | ||
- [What is this?](#what-is-this) | ||
- [When should I use this?](#when-should-i-use-this) | ||
- [Install](#install) | ||
- [Use](#use) | ||
- [API](#api) | ||
- [Syntax tree](#syntax-tree) | ||
- [Types](#types) | ||
- [Compatibility](#compatibility) | ||
- [Security](#security) | ||
- [Related](#related) | ||
- [Contribute](#contribute) | ||
- [License](#license) | ||
|
||
## What is this? | ||
|
||
## When should I use this? | ||
|
||
## Install | ||
|
||
## Use | ||
|
||
## API | ||
|
||
## Syntax tree | ||
|
||
## Types | ||
|
||
## Compatibility | ||
|
||
## Security | ||
|
||
## Related | ||
|
||
## Contribute | ||
|
||
## License | ||
|
||
GPL-3.0-or-later © Thomas F. K. Jorna | ||
|
||
[unified]: https://unifiedjs.com | ||
[unifiedgh]: https://github.com/unifiedjs/unified | ||
[xast-from-xml]: https://github.com/syntax-tree/xast-util-from-xml | ||
[rehype]: https://github.com/rehypejs/rehype | ||
[rejour]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour | ||
[rejour-parse]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-parse | ||
[rejour-stringify]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-stringify | ||
[rejour-move-abstract]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-move-abstract | ||
[rejour-meta]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-meta | ||
[rejour-relatex]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/rejour-relatex | ||
[relatex]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/relatex | ||
[relatex-parse]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/relatex/relatex-parse | ||
[jast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/jast | ||
[jast-util-to-texast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/jast-util-to-texast | ||
[jastscript]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/rejour/jastscript | ||
[texast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/relatex/texast | ||
[texast-util-to-latex]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/relatex/texast-util-to-latex | ||
[hast]: https://github.com/syntax-tree/hast | ||
[xast]: https://github.com/syntax-tree/xast | ||
[mdast]: https://github.com/syntax-tree/mdast | ||
[mdast-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown | ||
[latex-utensils]: https://github.com/tamuratak/latex-utensils | ||
[latexjs]: https://github.com/latexjs/latexjs | ||
[reoff]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/reoff | ||
[reoff-parse]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/reoff/reoff-parse | ||
[reoff-rejour]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/reoff/reoff-rejour | ||
[ooxast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/ooxast/ooxast | ||
[ooxast]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/ooxast/ooxast-util-to-jast | ||
[reoff-unified-latex]: https://github.com/TrialAndErrorOrg/parsers/tree/main/libs/reoff-unified-latex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const config = { | ||
displayName: 'reoff-unified-latex', | ||
preset: '../../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
useESM: true, | ||
}, | ||
}, | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]sx?$': ['@swc/jest', { swcrc: false }], | ||
}, | ||
transformIgnorePatterns: [], | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../../coverage/libs/reoff-unified-latex', | ||
extensionsToTreatAsEsm: ['.ts'], | ||
moduleNameMapper: { | ||
'^(\\.{1,2}/.*)\\.js$': '$1', | ||
}, | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "reoff-unified-latex", | ||
"version": "0.0.1", | ||
"license": "GPL-3.0-or-later", | ||
"repository": "https://github.com/TrialAndErrorOrg/reoff-unified-latex", | ||
"homepage": "https://github.com/TrialAndErrorOrg/parsers", | ||
"author": "Thomas F. K. Jorna <[email protected]>", | ||
"type": "module", | ||
"description": "Plugin for `reoff` that takes an `ooxast` tree and turns it into a `unified-latex` tree, allowing for .docx to .tex conversion", | ||
"keywords": [ | ||
"unified", | ||
"reoff", | ||
"ooxast", | ||
"latex", | ||
"docx", | ||
"converter", | ||
"unified-latex", | ||
"ast" | ||
], | ||
"typedoc": { | ||
"entryPoint": "./src/index.ts", | ||
"readmeFile": "./README.md", | ||
"displayName": "reoff-unified-latex", | ||
"tsconfig": "./tsconfig.lib.json" | ||
}, | ||
"exports": { | ||
".": { | ||
"types": "./index.d.ts", | ||
"import": "./index.js" | ||
} | ||
}, | ||
"main": "./index.js", | ||
"types": "./index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js", | ||
"./lib" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"name": "reoff-unified-latex", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/reoff/reoff-unified-latex/src", | ||
"projectType": "library", | ||
"targets": { | ||
"readme": { | ||
"executor": "@jote/utils/readme:update-readme", | ||
"options": { | ||
"readme": "libs/reoff/reoff-unified-latex/README.md", | ||
"packageJSON": "libs/reoff/reoff-unified-latex/package.json" | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["libs/reoff/reoff-unified-latex/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["coverage/libs/reoff/reoff-unified-latex"], | ||
"options": { | ||
"jestConfig": "libs/reoff/reoff-unified-latex/jest.config.js", | ||
"passWithNoTests": true | ||
} | ||
}, | ||
"build": { | ||
"executor": "better-nx-tsc:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"rootDir": "libs/reoff/reoff-unified-latex/src", | ||
"outputPath": "dist/libs/reoff/reoff-unified-latex", | ||
"tsConfig": "libs/reoff/reoff-unified-latex/tsconfig.lib.json", | ||
"packageJson": "libs/reoff/reoff-unified-latex/package.json", | ||
"main": "libs/reoff/reoff-unified-latex/src/index.ts", | ||
"assets": ["libs/reoff/reoff-unified-latex/*.md"], | ||
"updateBuildableProjectDepsInPackageJson": true, | ||
"clean": true, | ||
"buildableProjectDepsInPackageJsonType": "dependencies" | ||
}, | ||
"dependsOn": [ | ||
{ | ||
"projects": "dependencies", | ||
"target": "build", | ||
"params": "forward" | ||
}, | ||
{ | ||
"projects": "self", | ||
"target": "lint" | ||
} | ||
] | ||
}, | ||
"deploy": { | ||
"executor": "ngx-deploy-npm:deploy", | ||
"options": { | ||
"access": "public" | ||
} | ||
}, | ||
"version": { | ||
"executor": "@jscutlery/semver:version", | ||
"options": { | ||
"preset": "conventional", | ||
"trackDeps": true, | ||
"postTargets": [ | ||
"reoff-unified-latex:npm", | ||
"reoff-unified-latex:github", | ||
"reoff-unified-latex:github-standalone" | ||
] | ||
}, | ||
"dependsOn": [ | ||
{ | ||
"projects": "dependencies", | ||
"target": "version", | ||
"params": "forward" | ||
} | ||
] | ||
}, | ||
"github": { | ||
"executor": "@jscutlery/semver:github", | ||
"options": { | ||
"tag": "${tag}", | ||
"notes": "${notes}" | ||
} | ||
}, | ||
"github-standalone": { | ||
"executor": "@jscutlery/semver:github", | ||
"options": { | ||
"tag": "${tag}", | ||
"notes": "${notes}", | ||
"repo": "TrialAndErrorOrg/reoff-unified-latex" | ||
} | ||
}, | ||
"npm": { | ||
"executor": "ngx-deploy-npm:deploy", | ||
"options": { | ||
"access": "public" | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './lib/reoff-unified-latex.js' | ||
export { Options } from 'ooxast-util-to-unified-latex' |
7 changes: 7 additions & 0 deletions
7
libs/reoff/reoff-unified-latex/src/lib/reoff-unified-latex.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import reoffUnifiedLatex from './reoff-unified-latex.js' | ||
|
||
describe('reoffUnifiedLatex', () => { | ||
it('should work', () => { | ||
expect(reoffUnifiedLatex).toBeDefined() | ||
}) | ||
}) |
68 changes: 68 additions & 0 deletions
68
libs/reoff/reoff-unified-latex/src/lib/reoff-unified-latex.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Processor as UnifiedProcessor, Transformer, Plugin } from 'unified' | ||
import { toUnifiedLatex, Options } from 'ooxast-util-to-unified-latex' | ||
import { Root as OoxastRoot } from 'ooxast' | ||
import { Root } from '@unified-latex/unified-latex-types' | ||
|
||
type Processor = UnifiedProcessor<any, any, any, any> | ||
/** | ||
* Bridge-mode. | ||
* Runs the destination with the new mdast tree. | ||
* | ||
*/ | ||
function bridge( | ||
destination: Processor, | ||
options?: Options, | ||
): void | Transformer<OoxastRoot, OoxastRoot> { | ||
return (node, file, next) => { | ||
destination.run(toUnifiedLatex(node, options), file, (error) => { | ||
next(error) | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* Mutate-mode. | ||
* Further transformers run on the texast tree. | ||
*/ | ||
function mutate( | ||
options: void | Options | undefined = {}, | ||
): ReturnType<Plugin<[Options?] | void[], OoxastRoot, Root>> { | ||
//Transformer<JastRoot, JastRoot> | void { | ||
return (node, file) => { | ||
const result = toUnifiedLatex(node, options) | ||
return result | ||
} | ||
} | ||
|
||
/** | ||
* Plugin to bridge or mutate to relatex | ||
* | ||
* If a destination is given, runs the destination with the new jast | ||
* tree (bridge-mode). | ||
* Without destination, returns the jast tree: further plugins run on that | ||
* tree (mutate-mode). | ||
* | ||
* @param destination | ||
* Optional unified processor. | ||
* @param options | ||
* Options passed to `ooxast-util-to-unified-latex`. | ||
*/ | ||
const reoffUnifiedLatex = function (destination?: Processor | Options, options?: Options) { | ||
let settings: Options | undefined | ||
let processor: Processor | undefined | ||
|
||
if (typeof destination === 'function') { | ||
processor = destination | ||
settings = options | ||
} else { | ||
settings = destination | ||
} | ||
|
||
if (settings?.document === undefined || settings.document === null) { | ||
settings = Object.assign({}, settings, { document: true }) | ||
} | ||
|
||
return processor ? bridge(processor, settings) : mutate(settings) | ||
} as Plugin<[Processor, Options?], OoxastRoot> & Plugin<[Options?] | void[], OoxastRoot, Root> | ||
|
||
export default reoffUnifiedLatex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
Oops, something went wrong.