Skip to content

Commit

Permalink
fix: cannot download other formats (#351)
Browse files Browse the repository at this point in the history
* fix: cannot download other formats

* fix: remove xmlns from tags

Fixes #347
  • Loading branch information
deltork authored and joanise committed Oct 16, 2024
1 parent 5682329 commit d9377aa
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/studio-web/src/app/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {

async parseReadalong(text: string): Promise<string | undefined> {
const parser = new DOMParser();

const readalong = parser.parseFromString(text, "text/html");
const element = readalong.querySelector("read-along");

if (element === undefined || element === null) {
return undefined;
}
Expand All @@ -263,16 +263,20 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {
// Create missing body element
const body = document.createElement("body");
body.id = "t0b0";
const textNode = element.children[0];
if (textNode) {
while (textNode.hasChildNodes()) {
const textNode = element.querySelector("text");
if (textNode?.querySelector("body") == null) {
while (textNode?.hasChildNodes()) {
// @ts-ignore
body.appendChild(textNode.firstChild);
}
textNode.appendChild(body);
}
textNode?.appendChild(body);
} /**/
const serializer = new XMLSerializer();
const xmlString = serializer.serializeToString(element);
const xmlString = serializer
.serializeToString(element)
.replace("arpabet=", "ARPABET=")
.replace(/xmlns="[\w\/\:\.]*"/g, "");
//console.log(xmlString);
this.editorService.rasControl$.setValue(
parser.parseFromString(xmlString, "text/xml"),
); // re-parse as XML
Expand Down

0 comments on commit d9377aa

Please sign in to comment.