Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

audio_player: Postprocess audio for added structure, classes.

Karl Stolley05b8fea10fd0
diff --git a/web/src/postprocess_content.ts b/web/src/postprocess_content.ts
index 7a3ecb7978c..c646ec9b889 100644
--- a/web/src/postprocess_content.ts
+++ b/web/src/postprocess_content.ts
@@ -198,6 +198,19 @@ export function postprocess_content(html: string): string {
}
}
+ for (const audio of template.content.querySelectorAll("audio")) {
+ const audio_wrapper = inertDocument.createElement("span");
+ audio_wrapper.classList.add("media-audio-wrapper");
+ // We want a class to refer to audio elements
+ audio.classList.add("media-audio-element");
+ audio_wrapper.append(audio.cloneNode());
+ // Now we'll use a template to build additional DOM
+ // structures out of the original <audio> element
+ // const audio_html_string = audio.outerHTML;
+ // const rendered_audio_html = render_markdown_audio({audio_html: audio_html_string});
+ audio.replaceWith(audio_wrapper);
+ }
+
for (const ol of template.content.querySelectorAll("ol")) {
const list_start = Number(ol.getAttribute("start") ?? 1);
// We don't count the first item in the list, as it
diff --git a/web/tests/postprocess_content.test.cjs b/web/tests/postprocess_content.test.cjs
index 19a1e0011ac..42cab72c194 100644
--- a/web/tests/postprocess_content.test.cjs
+++ b/web/tests/postprocess_content.test.cjs
@@ -43,7 +43,8 @@ run_test("postprocess_content", () => {
"</div>" +
'<div class="message_embed_description">All about us.</div>' +
"</div>" +
- "</div>",
+ "</div>" +
+ '<p><audio controls preload="metadata" src="http://zulip.zulipdev.com/user_uploads/w/ha/tever/inline.mp3" title="inline.mp3"></audio></p>',
),
'<a href="http://example.com" target="_blank" rel="noopener noreferrer" title="http://example.com/">good</a> ' +
'<a href="http://zulip.zulipdev.com/user_uploads/w/ha/tever/file.png" target="_blank" rel="noopener noreferrer" title="translated: Download file.png">upload</a> ' +
@@ -74,7 +75,8 @@ run_test("postprocess_content", () => {
"</div>" +
'<div class="message_embed_description">All about us.</div>' +
"</div>" +
- "</div>",
+ "</div>" +
+ '<p><span class="media-audio-wrapper"><audio controls="" preload="metadata" src="http://zulip.zulipdev.com/user_uploads/w/ha/tever/inline.mp3" title="inline.mp3" class="media-audio-element"></audio></span></p>',
);
});