docrev 0.8.1 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +9 -0
- package/PLAN-tables-and-postprocess.md +850 -0
- package/README.md +33 -0
- package/bin/rev.js +12 -131
- package/bin/rev.ts +145 -0
- package/dist/bin/rev.d.ts +9 -0
- package/dist/bin/rev.d.ts.map +1 -0
- package/dist/bin/rev.js +118 -0
- package/dist/bin/rev.js.map +1 -0
- package/dist/lib/annotations.d.ts +91 -0
- package/dist/lib/annotations.d.ts.map +1 -0
- package/dist/lib/annotations.js +554 -0
- package/dist/lib/annotations.js.map +1 -0
- package/dist/lib/build.d.ts +171 -0
- package/dist/lib/build.d.ts.map +1 -0
- package/dist/lib/build.js +755 -0
- package/dist/lib/build.js.map +1 -0
- package/dist/lib/citations.d.ts +34 -0
- package/dist/lib/citations.d.ts.map +1 -0
- package/dist/lib/citations.js +140 -0
- package/dist/lib/citations.js.map +1 -0
- package/dist/lib/commands/build.d.ts +13 -0
- package/dist/lib/commands/build.d.ts.map +1 -0
- package/dist/lib/commands/build.js +678 -0
- package/dist/lib/commands/build.js.map +1 -0
- package/dist/lib/commands/citations.d.ts +11 -0
- package/dist/lib/commands/citations.d.ts.map +1 -0
- package/dist/lib/commands/citations.js +428 -0
- package/dist/lib/commands/citations.js.map +1 -0
- package/dist/lib/commands/comments.d.ts +11 -0
- package/dist/lib/commands/comments.d.ts.map +1 -0
- package/dist/lib/commands/comments.js +883 -0
- package/dist/lib/commands/comments.js.map +1 -0
- package/dist/lib/commands/context.d.ts +35 -0
- package/dist/lib/commands/context.d.ts.map +1 -0
- package/dist/lib/commands/context.js +59 -0
- package/dist/lib/commands/context.js.map +1 -0
- package/dist/lib/commands/core.d.ts +11 -0
- package/dist/lib/commands/core.d.ts.map +1 -0
- package/dist/lib/commands/core.js +246 -0
- package/dist/lib/commands/core.js.map +1 -0
- package/dist/lib/commands/doi.d.ts +11 -0
- package/dist/lib/commands/doi.d.ts.map +1 -0
- package/dist/lib/commands/doi.js +373 -0
- package/dist/lib/commands/doi.js.map +1 -0
- package/dist/lib/commands/history.d.ts +11 -0
- package/dist/lib/commands/history.d.ts.map +1 -0
- package/dist/lib/commands/history.js +245 -0
- package/dist/lib/commands/history.js.map +1 -0
- package/dist/lib/commands/index.d.ts +28 -0
- package/dist/lib/commands/index.d.ts.map +1 -0
- package/dist/lib/commands/index.js +35 -0
- package/dist/lib/commands/index.js.map +1 -0
- package/dist/lib/commands/init.d.ts +11 -0
- package/dist/lib/commands/init.d.ts.map +1 -0
- package/dist/lib/commands/init.js +209 -0
- package/dist/lib/commands/init.js.map +1 -0
- package/dist/lib/commands/response.d.ts +11 -0
- package/dist/lib/commands/response.d.ts.map +1 -0
- package/dist/lib/commands/response.js +317 -0
- package/dist/lib/commands/response.js.map +1 -0
- package/dist/lib/commands/sections.d.ts +11 -0
- package/dist/lib/commands/sections.d.ts.map +1 -0
- package/dist/lib/commands/sections.js +1071 -0
- package/dist/lib/commands/sections.js.map +1 -0
- package/dist/lib/commands/utilities.d.ts +19 -0
- package/dist/lib/commands/utilities.d.ts.map +1 -0
- package/dist/lib/commands/utilities.js +2009 -0
- package/dist/lib/commands/utilities.js.map +1 -0
- package/dist/lib/comment-realign.d.ts +50 -0
- package/dist/lib/comment-realign.d.ts.map +1 -0
- package/dist/lib/comment-realign.js +372 -0
- package/dist/lib/comment-realign.js.map +1 -0
- package/dist/lib/config.d.ts +41 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +76 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/crossref.d.ts +108 -0
- package/dist/lib/crossref.d.ts.map +1 -0
- package/dist/lib/crossref.js +597 -0
- package/dist/lib/crossref.js.map +1 -0
- package/dist/lib/dependencies.d.ts +30 -0
- package/dist/lib/dependencies.d.ts.map +1 -0
- package/dist/lib/dependencies.js +95 -0
- package/dist/lib/dependencies.js.map +1 -0
- package/dist/lib/doi-cache.d.ts +29 -0
- package/dist/lib/doi-cache.d.ts.map +1 -0
- package/dist/lib/doi-cache.js +104 -0
- package/dist/lib/doi-cache.js.map +1 -0
- package/dist/lib/doi.d.ts +65 -0
- package/dist/lib/doi.d.ts.map +1 -0
- package/dist/lib/doi.js +710 -0
- package/dist/lib/doi.js.map +1 -0
- package/dist/lib/equations.d.ts +61 -0
- package/dist/lib/equations.d.ts.map +1 -0
- package/dist/lib/equations.js +445 -0
- package/dist/lib/equations.js.map +1 -0
- package/dist/lib/errors.d.ts +60 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +303 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/format.d.ts +104 -0
- package/dist/lib/format.d.ts.map +1 -0
- package/dist/lib/format.js +416 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/git.d.ts +88 -0
- package/dist/lib/git.d.ts.map +1 -0
- package/dist/lib/git.js +304 -0
- package/dist/lib/git.js.map +1 -0
- package/dist/lib/grammar.d.ts +62 -0
- package/dist/lib/grammar.d.ts.map +1 -0
- package/dist/lib/grammar.js +244 -0
- package/dist/lib/grammar.js.map +1 -0
- package/dist/lib/image-registry.d.ts +68 -0
- package/dist/lib/image-registry.d.ts.map +1 -0
- package/dist/lib/image-registry.js +112 -0
- package/dist/lib/image-registry.js.map +1 -0
- package/dist/lib/import.d.ts +184 -0
- package/dist/lib/import.d.ts.map +1 -0
- package/dist/lib/import.js +1581 -0
- package/dist/lib/import.js.map +1 -0
- package/dist/lib/journals.d.ts +55 -0
- package/dist/lib/journals.d.ts.map +1 -0
- package/dist/lib/journals.js +417 -0
- package/dist/lib/journals.js.map +1 -0
- package/dist/lib/merge.d.ts +138 -0
- package/dist/lib/merge.d.ts.map +1 -0
- package/dist/lib/merge.js +603 -0
- package/dist/lib/merge.js.map +1 -0
- package/dist/lib/orcid.d.ts +36 -0
- package/dist/lib/orcid.d.ts.map +1 -0
- package/dist/lib/orcid.js +117 -0
- package/dist/lib/orcid.js.map +1 -0
- package/dist/lib/pdf-comments.d.ts +95 -0
- package/dist/lib/pdf-comments.d.ts.map +1 -0
- package/dist/lib/pdf-comments.js +192 -0
- package/dist/lib/pdf-comments.js.map +1 -0
- package/dist/lib/pdf-import.d.ts +118 -0
- package/dist/lib/pdf-import.d.ts.map +1 -0
- package/dist/lib/pdf-import.js +397 -0
- package/dist/lib/pdf-import.js.map +1 -0
- package/dist/lib/plugins.d.ts +76 -0
- package/dist/lib/plugins.d.ts.map +1 -0
- package/dist/lib/plugins.js +235 -0
- package/dist/lib/plugins.js.map +1 -0
- package/dist/lib/postprocess.d.ts +42 -0
- package/dist/lib/postprocess.d.ts.map +1 -0
- package/dist/lib/postprocess.js +138 -0
- package/dist/lib/postprocess.js.map +1 -0
- package/dist/lib/pptx-template.d.ts +59 -0
- package/dist/lib/pptx-template.d.ts.map +1 -0
- package/dist/lib/pptx-template.js +613 -0
- package/dist/lib/pptx-template.js.map +1 -0
- package/dist/lib/pptx-themes.d.ts +80 -0
- package/dist/lib/pptx-themes.d.ts.map +1 -0
- package/dist/lib/pptx-themes.js +818 -0
- package/dist/lib/pptx-themes.js.map +1 -0
- package/dist/lib/protect-restore.d.ts +137 -0
- package/dist/lib/protect-restore.d.ts.map +1 -0
- package/dist/lib/protect-restore.js +394 -0
- package/dist/lib/protect-restore.js.map +1 -0
- package/dist/lib/rate-limiter.d.ts +27 -0
- package/dist/lib/rate-limiter.d.ts.map +1 -0
- package/dist/lib/rate-limiter.js +79 -0
- package/dist/lib/rate-limiter.js.map +1 -0
- package/dist/lib/response.d.ts +41 -0
- package/dist/lib/response.d.ts.map +1 -0
- package/dist/lib/response.js +150 -0
- package/dist/lib/response.js.map +1 -0
- package/dist/lib/review.d.ts +35 -0
- package/dist/lib/review.d.ts.map +1 -0
- package/dist/lib/review.js +263 -0
- package/dist/lib/review.js.map +1 -0
- package/dist/lib/schema.d.ts +66 -0
- package/dist/lib/schema.d.ts.map +1 -0
- package/dist/lib/schema.js +339 -0
- package/dist/lib/schema.js.map +1 -0
- package/dist/lib/scientific-words.d.ts +6 -0
- package/dist/lib/scientific-words.d.ts.map +1 -0
- package/dist/lib/scientific-words.js +66 -0
- package/dist/lib/scientific-words.js.map +1 -0
- package/dist/lib/sections.d.ts +40 -0
- package/dist/lib/sections.d.ts.map +1 -0
- package/dist/lib/sections.js +288 -0
- package/dist/lib/sections.js.map +1 -0
- package/dist/lib/slides.d.ts +86 -0
- package/dist/lib/slides.d.ts.map +1 -0
- package/dist/lib/slides.js +676 -0
- package/dist/lib/slides.js.map +1 -0
- package/dist/lib/spelling.d.ts +76 -0
- package/dist/lib/spelling.d.ts.map +1 -0
- package/dist/lib/spelling.js +272 -0
- package/dist/lib/spelling.js.map +1 -0
- package/dist/lib/templates.d.ts +30 -0
- package/dist/lib/templates.d.ts.map +1 -0
- package/dist/lib/templates.js +504 -0
- package/dist/lib/templates.js.map +1 -0
- package/dist/lib/themes.d.ts +85 -0
- package/dist/lib/themes.d.ts.map +1 -0
- package/dist/lib/themes.js +652 -0
- package/dist/lib/themes.js.map +1 -0
- package/dist/lib/trackchanges.d.ts +51 -0
- package/dist/lib/trackchanges.d.ts.map +1 -0
- package/dist/lib/trackchanges.js +202 -0
- package/dist/lib/trackchanges.js.map +1 -0
- package/dist/lib/tui.d.ts +76 -0
- package/dist/lib/tui.d.ts.map +1 -0
- package/dist/lib/tui.js +377 -0
- package/dist/lib/tui.js.map +1 -0
- package/dist/lib/types.d.ts +447 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +6 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/undo.d.ts +57 -0
- package/dist/lib/undo.d.ts.map +1 -0
- package/dist/lib/undo.js +185 -0
- package/dist/lib/undo.js.map +1 -0
- package/dist/lib/utils.d.ts +16 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +40 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/variables.d.ts +42 -0
- package/dist/lib/variables.d.ts.map +1 -0
- package/dist/lib/variables.js +141 -0
- package/dist/lib/variables.js.map +1 -0
- package/dist/lib/word.d.ts +80 -0
- package/dist/lib/word.d.ts.map +1 -0
- package/dist/lib/word.js +360 -0
- package/dist/lib/word.js.map +1 -0
- package/dist/lib/wordcomments.d.ts +51 -0
- package/dist/lib/wordcomments.d.ts.map +1 -0
- package/dist/lib/wordcomments.js +587 -0
- package/dist/lib/wordcomments.js.map +1 -0
- package/eslint.config.js +27 -0
- package/lib/annotations.ts +622 -0
- package/lib/apply-buildup-colors.py +88 -0
- package/lib/build.ts +1013 -0
- package/lib/{citations.js → citations.ts} +38 -27
- package/lib/commands/{build.js → build.ts} +80 -27
- package/lib/commands/{citations.js → citations.ts} +36 -18
- package/lib/commands/{comments.js → comments.ts} +187 -54
- package/lib/commands/{context.js → context.ts} +18 -8
- package/lib/commands/{core.js → core.ts} +34 -20
- package/lib/commands/{doi.js → doi.ts} +32 -16
- package/lib/commands/{history.js → history.ts} +25 -12
- package/lib/commands/{index.js → index.ts} +9 -5
- package/lib/commands/{init.js → init.ts} +20 -8
- package/lib/commands/{response.js → response.ts} +47 -20
- package/lib/commands/{sections.js → sections.ts} +273 -68
- package/lib/commands/{utilities.js → utilities.ts} +338 -158
- package/lib/{comment-realign.js → comment-realign.ts} +117 -45
- package/lib/config.ts +84 -0
- package/lib/{crossref.js → crossref.ts} +213 -138
- package/lib/dependencies.ts +106 -0
- package/lib/doi-cache.ts +115 -0
- package/lib/{doi.js → doi.ts} +115 -281
- package/lib/{equations.js → equations.ts} +60 -64
- package/lib/{errors.js → errors.ts} +56 -48
- package/lib/{format.js → format.ts} +137 -63
- package/lib/{git.js → git.ts} +66 -63
- package/lib/{grammar.js → grammar.ts} +45 -32
- package/lib/image-registry.ts +180 -0
- package/lib/import.ts +2060 -0
- package/lib/journals.ts +505 -0
- package/lib/{merge.js → merge.ts} +185 -135
- package/lib/{orcid.js → orcid.ts} +17 -22
- package/lib/{pdf-comments.js → pdf-comments.ts} +76 -18
- package/lib/{pdf-import.js → pdf-import.ts} +148 -70
- package/lib/{plugins.js → plugins.ts} +82 -39
- package/lib/postprocess.ts +188 -0
- package/lib/pptx-color-filter.lua +37 -0
- package/lib/pptx-template.ts +625 -0
- package/lib/pptx-themes/academic.pptx +0 -0
- package/lib/pptx-themes/corporate.pptx +0 -0
- package/lib/pptx-themes/dark.pptx +0 -0
- package/lib/pptx-themes/default.pptx +0 -0
- package/lib/pptx-themes/minimal.pptx +0 -0
- package/lib/pptx-themes/plant.pptx +0 -0
- package/lib/pptx-themes.ts +896 -0
- package/lib/protect-restore.ts +516 -0
- package/lib/rate-limiter.ts +94 -0
- package/lib/{response.js → response.ts} +36 -21
- package/lib/{review.js → review.ts} +53 -43
- package/lib/{schema.js → schema.ts} +70 -25
- package/lib/{sections.js → sections.ts} +71 -76
- package/lib/slides.ts +793 -0
- package/lib/{spelling.js → spelling.ts} +43 -59
- package/lib/{templates.js → templates.ts} +20 -17
- package/lib/themes.ts +742 -0
- package/lib/{trackchanges.js → trackchanges.ts} +52 -23
- package/lib/types.ts +509 -0
- package/lib/{undo.js → undo.ts} +75 -52
- package/lib/utils.ts +41 -0
- package/lib/{variables.js → variables.ts} +60 -54
- package/lib/word.ts +428 -0
- package/lib/{wordcomments.js → wordcomments.ts} +94 -40
- package/package.json +15 -5
- package/skill/REFERENCE.md +67 -0
- package/tsconfig.json +26 -0
- package/lib/annotations.js +0 -414
- package/lib/build.js +0 -639
- package/lib/config.js +0 -79
- package/lib/import.js +0 -1145
- package/lib/journals.js +0 -629
- package/lib/word.js +0 -225
- /package/lib/{scientific-words.js → scientific-words.ts} +0 -0
|
@@ -9,44 +9,59 @@
|
|
|
9
9
|
|
|
10
10
|
import * as fs from 'fs';
|
|
11
11
|
import * as path from 'path';
|
|
12
|
+
// @ts-ignore - nspell has no types
|
|
12
13
|
import nspell from 'nspell';
|
|
14
|
+
// @ts-ignore - dictionary-en has no types
|
|
13
15
|
import dictionaryEn from 'dictionary-en';
|
|
16
|
+
// @ts-ignore - dictionary-en-gb has no types
|
|
14
17
|
import dictionaryEnGb from 'dictionary-en-gb';
|
|
15
18
|
import { scientificWords } from './scientific-words.js';
|
|
19
|
+
import type { SpellingIssue, SpellingResult } from './types.js';
|
|
16
20
|
|
|
17
21
|
const DICT_NAME = '.rev-dictionary';
|
|
18
22
|
|
|
19
23
|
// Cache for the spellchecker instances (one per language)
|
|
20
|
-
const spellcheckerCache = {
|
|
24
|
+
const spellcheckerCache: Record<string, any> = {
|
|
21
25
|
en: null,
|
|
22
26
|
'en-gb': null,
|
|
23
27
|
};
|
|
24
28
|
|
|
29
|
+
interface WordLocation {
|
|
30
|
+
word: string;
|
|
31
|
+
line: number;
|
|
32
|
+
column: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface CheckSpellingOptions {
|
|
36
|
+
projectDir?: string;
|
|
37
|
+
lang?: 'en' | 'en-gb';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface CheckFileOptions {
|
|
41
|
+
projectDir?: string;
|
|
42
|
+
lang?: 'en' | 'en-gb';
|
|
43
|
+
}
|
|
44
|
+
|
|
25
45
|
/**
|
|
26
46
|
* Get the global dictionary path
|
|
27
|
-
* @returns {string}
|
|
28
47
|
*/
|
|
29
|
-
export function getGlobalDictPath() {
|
|
48
|
+
export function getGlobalDictPath(): string {
|
|
30
49
|
const home = process.env.HOME || process.env.USERPROFILE;
|
|
31
|
-
return path.join(home
|
|
50
|
+
return path.join(home!, DICT_NAME);
|
|
32
51
|
}
|
|
33
52
|
|
|
34
53
|
/**
|
|
35
54
|
* Get the project dictionary path
|
|
36
|
-
* @param {string} directory
|
|
37
|
-
* @returns {string}
|
|
38
55
|
*/
|
|
39
|
-
export function getProjectDictPath(directory = '.') {
|
|
56
|
+
export function getProjectDictPath(directory: string = '.'): string {
|
|
40
57
|
return path.join(directory, DICT_NAME);
|
|
41
58
|
}
|
|
42
59
|
|
|
43
60
|
/**
|
|
44
61
|
* Load custom words from a dictionary file
|
|
45
|
-
* @param {string} dictPath
|
|
46
|
-
* @returns {Set<string>}
|
|
47
62
|
*/
|
|
48
|
-
export function loadDictionaryFile(dictPath) {
|
|
49
|
-
const words = new Set();
|
|
63
|
+
export function loadDictionaryFile(dictPath: string): Set<string> {
|
|
64
|
+
const words = new Set<string>();
|
|
50
65
|
|
|
51
66
|
if (fs.existsSync(dictPath)) {
|
|
52
67
|
const content = fs.readFileSync(dictPath, 'utf-8');
|
|
@@ -63,10 +78,8 @@ export function loadDictionaryFile(dictPath) {
|
|
|
63
78
|
|
|
64
79
|
/**
|
|
65
80
|
* Save words to a dictionary file
|
|
66
|
-
* @param {Set<string>} words
|
|
67
|
-
* @param {string} dictPath
|
|
68
81
|
*/
|
|
69
|
-
export function saveDictionaryFile(words
|
|
82
|
+
export function saveDictionaryFile(words: Set<string>, dictPath: string): void {
|
|
70
83
|
const header = `# Custom dictionary for docrev
|
|
71
84
|
# One word per line, lines starting with # are comments
|
|
72
85
|
`;
|
|
@@ -83,10 +96,8 @@ export function saveDictionaryFile(words, dictPath) {
|
|
|
83
96
|
|
|
84
97
|
/**
|
|
85
98
|
* Load all custom words (global + project)
|
|
86
|
-
* @param {string} projectDir
|
|
87
|
-
* @returns {Set<string>}
|
|
88
99
|
*/
|
|
89
|
-
export function loadAllCustomWords(projectDir = '.') {
|
|
100
|
+
export function loadAllCustomWords(projectDir: string = '.'): Set<string> {
|
|
90
101
|
const globalWords = loadDictionaryFile(getGlobalDictPath());
|
|
91
102
|
const projectWords = loadDictionaryFile(getProjectDictPath(projectDir));
|
|
92
103
|
|
|
@@ -95,12 +106,8 @@ export function loadAllCustomWords(projectDir = '.') {
|
|
|
95
106
|
|
|
96
107
|
/**
|
|
97
108
|
* Add word to dictionary
|
|
98
|
-
* @param {string} word
|
|
99
|
-
* @param {boolean} global - Add to global dictionary
|
|
100
|
-
* @param {string} projectDir
|
|
101
|
-
* @returns {boolean} True if word was added
|
|
102
109
|
*/
|
|
103
|
-
export function addWord(word, global = true, projectDir = '.') {
|
|
110
|
+
export function addWord(word: string, global: boolean = true, projectDir: string = '.'): boolean {
|
|
104
111
|
const dictPath = global ? getGlobalDictPath() : getProjectDictPath(projectDir);
|
|
105
112
|
const words = loadDictionaryFile(dictPath);
|
|
106
113
|
const normalizedWord = word.trim().toLowerCase();
|
|
@@ -120,12 +127,8 @@ export function addWord(word, global = true, projectDir = '.') {
|
|
|
120
127
|
|
|
121
128
|
/**
|
|
122
129
|
* Remove word from dictionary
|
|
123
|
-
* @param {string} word
|
|
124
|
-
* @param {boolean} global
|
|
125
|
-
* @param {string} projectDir
|
|
126
|
-
* @returns {boolean} True if word was removed
|
|
127
130
|
*/
|
|
128
|
-
export function removeWord(word, global = true, projectDir = '.') {
|
|
131
|
+
export function removeWord(word: string, global: boolean = true, projectDir: string = '.'): boolean {
|
|
129
132
|
const dictPath = global ? getGlobalDictPath() : getProjectDictPath(projectDir);
|
|
130
133
|
const words = loadDictionaryFile(dictPath);
|
|
131
134
|
const normalizedWord = word.trim().toLowerCase();
|
|
@@ -145,11 +148,8 @@ export function removeWord(word, global = true, projectDir = '.') {
|
|
|
145
148
|
|
|
146
149
|
/**
|
|
147
150
|
* List words in dictionary
|
|
148
|
-
* @param {boolean} global
|
|
149
|
-
* @param {string} projectDir
|
|
150
|
-
* @returns {string[]}
|
|
151
151
|
*/
|
|
152
|
-
export function listWords(global = true, projectDir = '.') {
|
|
152
|
+
export function listWords(global: boolean = true, projectDir: string = '.'): string[] {
|
|
153
153
|
const dictPath = global ? getGlobalDictPath() : getProjectDictPath(projectDir);
|
|
154
154
|
const words = loadDictionaryFile(dictPath);
|
|
155
155
|
return [...words].sort();
|
|
@@ -157,11 +157,8 @@ export function listWords(global = true, projectDir = '.') {
|
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
159
|
* Initialize the spellchecker with custom words
|
|
160
|
-
* @param {string} projectDir
|
|
161
|
-
* @param {string} lang - Language: 'en' (US) or 'en-gb' (British)
|
|
162
|
-
* @returns {Promise<object>}
|
|
163
160
|
*/
|
|
164
|
-
export async function getSpellchecker(projectDir = '.', lang = 'en') {
|
|
161
|
+
export async function getSpellchecker(projectDir: string = '.', lang: 'en' | 'en-gb' = 'en'): Promise<any> {
|
|
165
162
|
if (spellcheckerCache[lang]) {
|
|
166
163
|
return spellcheckerCache[lang];
|
|
167
164
|
}
|
|
@@ -188,24 +185,23 @@ export async function getSpellchecker(projectDir = '.', lang = 'en') {
|
|
|
188
185
|
/**
|
|
189
186
|
* Clear spellchecker cache (call after modifying dictionaries)
|
|
190
187
|
*/
|
|
191
|
-
export function clearCache() {
|
|
188
|
+
export function clearCache(): void {
|
|
192
189
|
spellcheckerCache.en = null;
|
|
193
190
|
spellcheckerCache['en-gb'] = null;
|
|
194
191
|
}
|
|
195
192
|
|
|
196
193
|
/**
|
|
197
194
|
* Extract words from text, filtering out non-words
|
|
198
|
-
* @param {string} text
|
|
199
|
-
* @returns {Array<{word: string, line: number, column: number}>}
|
|
200
195
|
*/
|
|
201
|
-
export function extractWords(text) {
|
|
202
|
-
const words = [];
|
|
196
|
+
export function extractWords(text: string): WordLocation[] {
|
|
197
|
+
const words: WordLocation[] = [];
|
|
203
198
|
const lines = text.split('\n');
|
|
204
199
|
let inCodeBlock = false;
|
|
205
200
|
let inFrontmatter = false;
|
|
206
201
|
|
|
207
202
|
for (let lineNum = 0; lineNum < lines.length; lineNum++) {
|
|
208
203
|
const line = lines[lineNum];
|
|
204
|
+
if (!line) continue;
|
|
209
205
|
const trimmed = line.trim();
|
|
210
206
|
|
|
211
207
|
// Track YAML frontmatter (only at start of file)
|
|
@@ -279,30 +275,23 @@ export function extractWords(text) {
|
|
|
279
275
|
|
|
280
276
|
/**
|
|
281
277
|
* Check if a word looks like a proper noun (name)
|
|
282
|
-
* @param {string} word
|
|
283
|
-
* @returns {boolean}
|
|
284
278
|
*/
|
|
285
|
-
function looksLikeName(word) {
|
|
279
|
+
function looksLikeName(word: string): boolean {
|
|
286
280
|
// Capitalized, not all caps, reasonable length for a name
|
|
287
281
|
return /^[A-Z][a-z]{2,}$/.test(word);
|
|
288
282
|
}
|
|
289
283
|
|
|
290
284
|
/**
|
|
291
285
|
* Check spelling in text
|
|
292
|
-
* @param {string} text
|
|
293
|
-
* @param {object} options
|
|
294
|
-
* @param {string} options.projectDir
|
|
295
|
-
* @param {string} options.lang - 'en' (US) or 'en-gb' (British)
|
|
296
|
-
* @returns {Promise<{misspelled: Array, possibleNames: Array}>}
|
|
297
286
|
*/
|
|
298
|
-
export async function checkSpelling(text, options = {}) {
|
|
287
|
+
export async function checkSpelling(text: string, options: CheckSpellingOptions = {}): Promise<SpellingResult> {
|
|
299
288
|
const { projectDir = '.', lang = 'en' } = options;
|
|
300
289
|
const spell = await getSpellchecker(projectDir, lang);
|
|
301
290
|
const words = extractWords(text);
|
|
302
|
-
const misspelled = [];
|
|
303
|
-
const possibleNames = [];
|
|
304
|
-
const seen = new Set();
|
|
305
|
-
const seenNames = new Set();
|
|
291
|
+
const misspelled: SpellingIssue[] = [];
|
|
292
|
+
const possibleNames: SpellingIssue[] = [];
|
|
293
|
+
const seen = new Set<string>();
|
|
294
|
+
const seenNames = new Set<string>();
|
|
306
295
|
|
|
307
296
|
for (const { word, line, column } of words) {
|
|
308
297
|
// Skip if already reported this word
|
|
@@ -333,13 +322,8 @@ export async function checkSpelling(text, options = {}) {
|
|
|
333
322
|
|
|
334
323
|
/**
|
|
335
324
|
* Check spelling in a file
|
|
336
|
-
* @param {string} filePath
|
|
337
|
-
* @param {object} options
|
|
338
|
-
* @param {string} options.projectDir
|
|
339
|
-
* @param {string} options.lang
|
|
340
|
-
* @returns {Promise<{misspelled: Array, possibleNames: Array}>}
|
|
341
325
|
*/
|
|
342
|
-
export async function checkFile(filePath, options = {}) {
|
|
326
|
+
export async function checkFile(filePath: string, options: CheckFileOptions = {}): Promise<SpellingResult> {
|
|
343
327
|
const text = fs.readFileSync(filePath, 'utf-8');
|
|
344
328
|
const result = await checkSpelling(text, options);
|
|
345
329
|
|
|
@@ -4,7 +4,14 @@
|
|
|
4
4
|
* Used by `rev new` command to create new paper projects
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
interface TemplateDefinition {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
files: Record<string, string>;
|
|
11
|
+
directories: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const TEMPLATES: Record<string, TemplateDefinition> = {
|
|
8
15
|
/**
|
|
9
16
|
* Standard academic paper structure
|
|
10
17
|
*/
|
|
@@ -414,18 +421,15 @@ paper.md
|
|
|
414
421
|
|
|
415
422
|
/**
|
|
416
423
|
* Get template by name
|
|
417
|
-
* @param {string} name
|
|
418
|
-
* @returns {object|null}
|
|
419
424
|
*/
|
|
420
|
-
export function getTemplate(name) {
|
|
425
|
+
export function getTemplate(name: string): TemplateDefinition | null {
|
|
421
426
|
return TEMPLATES[name.toLowerCase()] || null;
|
|
422
427
|
}
|
|
423
428
|
|
|
424
429
|
/**
|
|
425
430
|
* List available templates
|
|
426
|
-
* @returns {Array<{id: string, name: string, description: string}>}
|
|
427
431
|
*/
|
|
428
|
-
export function listTemplates() {
|
|
432
|
+
export function listTemplates(): Array<{ id: string; name: string; description: string }> {
|
|
429
433
|
return Object.entries(TEMPLATES).map(([id, template]) => ({
|
|
430
434
|
id,
|
|
431
435
|
name: template.name,
|
|
@@ -435,10 +439,8 @@ export function listTemplates() {
|
|
|
435
439
|
|
|
436
440
|
/**
|
|
437
441
|
* Convert string to title case for headers
|
|
438
|
-
* @param {string} str
|
|
439
|
-
* @returns {string}
|
|
440
442
|
*/
|
|
441
|
-
function titleCase(str) {
|
|
443
|
+
function titleCase(str: string): string {
|
|
442
444
|
return str
|
|
443
445
|
.split(/[-_\s]+/)
|
|
444
446
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
@@ -447,12 +449,13 @@ function titleCase(str) {
|
|
|
447
449
|
|
|
448
450
|
/**
|
|
449
451
|
* Generate a custom template with specified sections
|
|
450
|
-
* @param {string[]} sections - Array of section names (without .md extension)
|
|
451
|
-
* @param {object} baseTemplate - Base template to extend (default: paper)
|
|
452
|
-
* @returns {object}
|
|
453
452
|
*/
|
|
454
|
-
export function generateCustomTemplate(
|
|
455
|
-
|
|
453
|
+
export function generateCustomTemplate(
|
|
454
|
+
sections: string[],
|
|
455
|
+
baseTemplate?: TemplateDefinition
|
|
456
|
+
): TemplateDefinition {
|
|
457
|
+
const base = baseTemplate || TEMPLATES.paper;
|
|
458
|
+
const files: Record<string, string> = {};
|
|
456
459
|
|
|
457
460
|
// Generate rev.yaml with custom sections
|
|
458
461
|
const sectionsList = sections.map((s) => ` - ${s}.md`).join('\n');
|
|
@@ -502,8 +505,8 @@ docx:
|
|
|
502
505
|
}
|
|
503
506
|
|
|
504
507
|
// Add common files
|
|
505
|
-
files['references.bib'] =
|
|
506
|
-
files['.gitignore'] =
|
|
508
|
+
files['references.bib'] = base.files['references.bib'] || '';
|
|
509
|
+
files['.gitignore'] = base.files['.gitignore'] || `# Build outputs
|
|
507
510
|
*.pdf
|
|
508
511
|
*.docx
|
|
509
512
|
*.tex
|
|
@@ -518,6 +521,6 @@ paper.md
|
|
|
518
521
|
name: 'Custom',
|
|
519
522
|
description: 'Custom sections',
|
|
520
523
|
files,
|
|
521
|
-
directories:
|
|
524
|
+
directories: base.directories || ['figures'],
|
|
522
525
|
};
|
|
523
526
|
}
|