Skip to content

Commit 438b2ec

Browse files
committed
Fixed using Paratext and 3.0 markers maps. Exported only 3.0 markers map from PBU becuase we know we will use it long-term
1 parent 0ecd29c commit 438b2ec

File tree

16 files changed

+6691
-2884
lines changed

16 files changed

+6691
-2884
lines changed

extensions/src/platform-scripture-editor/src/comments.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Comments } from '@eten-tech-foundation/platform-editor';
22
import { MarkerContent, MarkerObject, Usj } from '@eten-tech-foundation/scripture-utilities';
33
import {
44
CHAPTER_TYPE,
5+
USFM_MARKERS_MAP_PARATEXT_3_0,
56
UsfmVerseLocation,
67
UsjNodeAndDocumentLocation,
78
UsjReaderWriter,
@@ -256,7 +257,7 @@ function insertAnchorIfNeeded(
256257
* @returns True if some comment anchors were inserted, false if no comment anchors were inserted
257258
*/
258259
export function insertCommentAnchorsIntoUsj(usj: Usj, legacyComments: LegacyComment[]): boolean {
259-
const usjRW = new UsjReaderWriter(usj);
260+
const usjRW = new UsjReaderWriter(usj, { markersMap: USFM_MARKERS_MAP_PARATEXT_3_0 });
260261
let usjChanged = false;
261262

262263
const threads = convertLegacyCommentsToEditorThreads(legacyComments);

extensions/src/platform-scripture-editor/src/main.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
LanguageStrings,
1414
LocalizeKey,
1515
serialize,
16-
USFM_MARKERS_MAP_3_1,
16+
USFM_MARKERS_MAP_PARATEXT_3_0,
1717
UsjReaderWriter,
1818
} from 'platform-bible-utils';
1919
import {
@@ -317,27 +317,7 @@ class ScriptureEditorWebViewFactory extends WebViewFactory<typeof scriptureEdito
317317
);
318318

319319
const usjRW = new UsjReaderWriter(usjChapter, {
320-
markersMap: {
321-
...USFM_MARKERS_MAP_3_1,
322-
// 3.0
323-
version: '3.0',
324-
// Paratext
325-
isSpaceAfterAttributeMarkersContent: true,
326-
shouldOptionalClosingMarkersBePresent: true,
327-
// 3.0
328-
markers: Object.fromEntries(
329-
Object.entries(USFM_MARKERS_MAP_3_1.markers).map(([markerName, markerInfo]) => {
330-
if (!markerInfo) return [markerName, markerInfo];
331-
332-
const newMarkerInfo = { ...markerInfo };
333-
334-
if (newMarkerInfo.defaultAttribute === 'href')
335-
newMarkerInfo.defaultAttribute = 'link-href';
336-
if (markerName === 'k') delete newMarkerInfo.defaultAttribute;
337-
return [markerName, newMarkerInfo];
338-
}),
339-
),
340-
},
320+
markersMap: USFM_MARKERS_MAP_PARATEXT_3_0,
341321
});
342322

343323
// Convert the range now - easy conversion if already jsonPath, but need to run conversion

extensions/src/platform-scripture-editor/src/platform-scripture-editor.web-view.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
isPlatformError,
3434
LocalizeKey,
3535
serialize,
36+
USFM_MARKERS_MAP_PARATEXT_3_0,
3637
UsjReaderWriter,
3738
} from 'platform-bible-utils';
3839
import {
@@ -329,7 +330,7 @@ globalThis.webViewComponent = function PlatformScriptureEditor({
329330

330331
// Remove the milestones that we inserted before writing back to the PDP
331332
const clonedUsj = deepClone(newUsj);
332-
const usjRW = new UsjReaderWriter(clonedUsj);
333+
const usjRW = new UsjReaderWriter(clonedUsj, { markersMap: USFM_MARKERS_MAP_PARATEXT_3_0 });
333334
usjRW.removeContentNodes((node: MarkerContent) => {
334335
if (typeof node === 'string') return false;
335336
if (node.type !== 'ms') return false;
@@ -409,7 +410,9 @@ globalThis.webViewComponent = function PlatformScriptureEditor({
409410
legacyCommentsFromPdp.forEach((existingComment) => legacyCommentIds.add(existingComment.id));
410411

411412
// Determine which "new" comments are actually new
412-
const usjRW = new UsjReaderWriter(usjWithAnchors);
413+
const usjRW = new UsjReaderWriter(usjWithAnchors, {
414+
markersMap: USFM_MARKERS_MAP_PARATEXT_3_0,
415+
});
413416
const newLegacyComments = convertEditorCommentsToLegacyComments(newComments, usjRW, scrRef);
414417
const legacyCommentsToAdd: LegacyComment[] = [];
415418
newLegacyComments.forEach((newComment) => {
@@ -509,9 +512,9 @@ globalThis.webViewComponent = function PlatformScriptureEditor({
509512

510513
let nextTextLocationJsonPath = '';
511514
try {
512-
nextTextLocationJsonPath = new UsjReaderWriter(usjFromPdp).verseRefToNextTextLocation(
513-
scrRef,
514-
).documentLocation.jsonPath;
515+
nextTextLocationJsonPath = new UsjReaderWriter(usjFromPdp, {
516+
markersMap: USFM_MARKERS_MAP_PARATEXT_3_0,
517+
}).verseRefToNextTextLocation(scrRef).documentLocation.jsonPath;
515518
} catch (e) {
516519
logger.debug(`Could not get next text location for verse ref ${serialize(scrRef)}`);
517520
}

extensions/src/platform-scripture/src/project-data-provider/platform-scripture-finder-pdpe.model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
escapeStringRegexp,
99
getErrorMessage,
1010
newGuid,
11+
USFM_MARKERS_MAP_PARATEXT_3_0,
1112
UsjReaderWriter,
1213
} from 'platform-bible-utils';
1314
import {
@@ -193,7 +194,7 @@ export class ScriptureFinderProjectDataProviderEngine
193194
if (!usx) throw new Error(`No scripture found for: ${JSON.stringify(scope)}`);
194195
const scripture: Usj | undefined = usxStringToUsj(usx);
195196

196-
const usj = new UsjReaderWriter(scripture);
197+
const usj = new UsjReaderWriter(scripture, { markersMap: USFM_MARKERS_MAP_PARATEXT_3_0 });
197198
const regexString = job.options.useRegex
198199
? job.options.searchString
199200
: escapeStringRegexp(job.options.searchString);

lib/platform-bible-utils/dist/index.cjs

Lines changed: 23 additions & 11 deletions
Large diffs are not rendered by default.

lib/platform-bible-utils/dist/index.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/platform-bible-utils/dist/index.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,11 @@ export type MarkersMap = {
21832183
* file
21842184
*/
21852185
declare const USFM_MARKERS_MAP: MarkersMap;
2186+
/**
2187+
* A map of all USFM/USX/USJ markers and some information about them. Generated from a `usx.rng`
2188+
* file and adjusted to reflect the way Paratext 9.4 handles USFM.
2189+
*/
2190+
declare const USFM_MARKERS_MAP_PARATEXT: MarkersMap;
21862191
/** USJ content node type for a chapter */
21872192
export declare const CHAPTER_TYPE = "chapter";
21882193
/** USJ content node type for a verse */
@@ -2414,6 +2419,12 @@ export type UsjReaderWriterOptions = {
24142419
/**
24152420
* A map of all USFM/USX/USJ markers and some information about them. Used for translating between
24162421
* the formats
2422+
*
2423+
* Defaults to trying to use a built-in markers map that matches the version of the USJ passed in.
2424+
*
2425+
* Currently supported built-in USFM versions:
2426+
*
2427+
* - 3.0/3.0.x
24172428
*/
24182429
markersMap?: MarkersMap;
24192430
/**
@@ -4719,7 +4730,8 @@ export declare class UsjReaderWriter implements IUsjReaderWriter {
47194730
}
47204731

47214732
export {
4722-
USFM_MARKERS_MAP as USFM_MARKERS_MAP_3_1,
4733+
USFM_MARKERS_MAP as USFM_MARKERS_MAP_3_0,
4734+
USFM_MARKERS_MAP_PARATEXT as USFM_MARKERS_MAP_PARATEXT_3_0,
47234735
};
47244736

47254737
export {};

0 commit comments

Comments
 (0)