Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/resources/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ export function failIfHasValue(
export function standardContentManipulations($: any) {
failIfPresent($, ['ipa', 'bdo']);

// A language course used whitespace-only foreign elements for foreign-text spacing.
// Torus authoring removes these, so we unwrap them into ordinary space text
$('foreign').each((_i: any, elem: any) => {
if ($(elem).children().length === 0 && $(elem).text().trim() === '') {
DOM.stripElement($, elem);
}
});

handleJmolApplets($);
handleCommandButtons($);

Expand Down
1 change: 1 addition & 0 deletions test/content/x-oli-workbook_page/foreign-whitespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
</head>
<body>
<p><foreign xml:lang="fr">Il est grand. </foreign><foreign xml:lang="fr"> Il </foreign><foreign xml:lang="fr">est </foreign><foreign xml:lang="fr"> grand.</foreign></p>
<p><em><foreign xml:lang="fr">ellui</foreign></em><foreign xml:lang="en_US"> </foreign>as <em><foreign xml:lang="fr">iels</foreign></em><foreign xml:lang="en_US"> </foreign><em><foreign xml:lang="fr">elleux</foreign></em></p>
</body>
</workbook_page>
24 changes: 22 additions & 2 deletions test/foreign-whitespace-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,31 @@ describe('foreign text whitespace', () => {
true
).convert(projectSummary);

const paragraph = results[0].content.model[0].children[0];
const foreignText = paragraph.children.map(
const [boundaryParagraph, blankForeignParagraph] =
results[0].content.model[0].children;
const foreignText = boundaryParagraph.children.map(
(foreign: any) => foreign.children[0].text
);

expect(foreignText).toEqual(['Il est grand. ', ' Il ', 'est ', ' grand.']);
expect(blankForeignParagraph.children).toEqual([
{
type: 'foreign',
children: [{ text: 'ellui', strong: true }],
'xml:lang': 'fr',
},
{ text: ' as ' },
{
type: 'foreign',
children: [{ text: 'iels', strong: true }],
'xml:lang': 'fr',
},
{ text: ' ' },
{
type: 'foreign',
children: [{ text: 'elleux', strong: true }],
'xml:lang': 'fr',
},
]);
});
});
15 changes: 15 additions & 0 deletions test/resources/common-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ describe('cdata and codeblocks', () => {
expect(img2.type).toBe('img_inline');
});

test('should unwrap whitespace-only foreign elements', () => {
const content =
'<p><foreign xml:lang="fr">bonjour</foreign><foreign xml:lang="en_US"> </foreign><foreign xml:lang="fr">monde</foreign></p>';
const $ = cheerio.load(content, {
normalizeWhitespace: true,
xmlMode: true,
});

standardContentManipulations($);

expect($.xml()).toEqual(
'<p><foreign xml:lang="fr">bonjour</foreign> <foreign xml:lang="fr">monde</foreign></p>'
);
});

test('should reorder default alternative to be first', async () => {
const content = `
<alternatives id="abc" group="statistics.package">
Expand Down
Loading