Skip to content

Commit

Permalink
Merge branch 'main' of github.com:andrewhertog/codex-editor into feat/ci
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhertog committed Sep 18, 2024
2 parents 18b5112 + 0fa22df commit 09685d1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { StatusBarHandler } from '../statusBarHandler';
import * as fs from 'fs';
import * as path from 'path';
import { getWorkSpaceFolder } from '../../../../utils';
import { getCodexCells, cleanCodexCell } from '../../../../utils/verseRefUtils/verseCleanup';

export interface minisearchDoc {
id: string;
vref: string;
Expand Down Expand Up @@ -41,10 +43,10 @@ export async function createTranslationPairsIndex(context: vscode.ExtensionConte
const completeDrafts: string[] = [];

for (const file of targetBibleFiles) {
const document = await vscode.workspace.openNotebookDocument(file);
const cells = document.getCells();
const cells = await getCodexCells(file.fsPath);
for (const cell of cells) {
const lines = cell.document.getText().split('\n');
const cleanedCell = cleanCodexCell(cell);
const lines = cleanedCell.split('\n');
for (const line of lines) {
const match = line.match(verseRefRegex);
if (match) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { cleanWord } from '../../../../utils/spellingUtils';
import { FileHandler } from '../../../../providers/dictionaryTable/utilities/FileHandler';
import { cleanWord } from '../../../../utils/cleaningUtils';

interface WordFrequency {
word: string;
Expand Down
2 changes: 0 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import {
import { createIndexWithContext } from "./activationHelpers/contextAware/miniIndex/indexes/index";
import { initializeWebviews } from "./activationHelpers/contextAware/webviewInitializers";
import { syncUtils } from "./activationHelpers/contextAware/syncUtils";
import { initializeStateStore } from "./stateStore";
import { projectFileExists } from "./utils/fileUtils";
import { registerCompletionsCodeLensProviders } from "./activationHelpers/contextAware/completionsCodeLensProviders";
import { CodexChunkEditorProvider } from "./providers/codexChunkEditorProvider/CodexChunkEditorProvider";
import * as path from "path";
Expand Down
2 changes: 1 addition & 1 deletion src/tsServer/spellCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { URI } from 'vscode-uri';
import { Connection } from 'vscode-languageserver/node';
import { cleanWord } from '../utils/spellingUtils';
import { cleanWord } from '../utils/cleaningUtils';

export class SpellChecker {
private dictionary: Dictionary | null = null;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/spellingUtils.ts → src/utils/cleaningUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function cleanWord(word: string | undefined | null): string {
export function cleanWord(word: string | undefined | null): string { // this is for the spellchecker
if (!word) return '';
return word
// Remove non-alphanumeric characters from start and end
Expand All @@ -9,4 +9,4 @@ export function cleanWord(word: string | undefined | null): string {
.replace(/(?<!\S)'|'(?!\S)|[^\p{L}\p{N}'\s]/gu, '')
// Convert to lowercase
.toLowerCase();
}
}
17 changes: 17 additions & 0 deletions src/utils/verseRefUtils/verseCleanup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as fs from 'fs/promises';

export async function getCodexCells(filePath: string): Promise<string[]> {
const fileContent = await fs.readFile(filePath, 'utf-8');
const cells = JSON.parse(fileContent).cells;
return cells.filter((cell: any) => cell.kind === 2 && cell.language === 'scripture')
.map((cell: any) => cell.value);
}

export function getCleanedCell(cellContent: string): string {
// Remove HTML tags while preserving newlines
return cellContent.replace(/<[^>]*>/g, '');
}

export function cleanCodexCell(cellContent: string): string {
return getCleanedCell(cellContent);
}

0 comments on commit 09685d1

Please sign in to comment.