Skip to content

Commit

Permalink
docs: document the multiple purposes of parseReadalong
Browse files Browse the repository at this point in the history
  • Loading branch information
joanise committed Oct 18, 2024
1 parent 3bf2a85 commit 99ce134
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/studio-web/src/app/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {
}

async parseReadalong(text: string): Promise<string | undefined> {
// This function is designed to parse three related things:
// - An Offline HTML file with the read-along HTML element with attributes href
// pointing to the .readalong file, and audio pointing to the audio file,
// normally both base64 encoded.
// - The .readalong XML file itself
// - An HTML file with the read-along HTML element and its audio attribute, but
// with the contents of the .readalong file included as descendant elements
// of the read-along HTML element.
// This is why we look for audio and href attributes, and a text child element, but
// don't expect to always find them.

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

0 comments on commit 99ce134

Please sign in to comment.