17426: Add dialog box with form to example plugin.
[arvados-workbench2.git] / src / common / xml.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string) => {
6     const [el] = Array.from(document.getElementsByTagName(tagName));
7     return decodeURI(el ? htmlDecode(el.innerHTML) : defaultValue);
8 };
9
10 const htmlDecode = (input: string) => {
11     const out = input.split(' ').map((i) => {
12         const doc = new DOMParser().parseFromString(i, "text/html");
13         if (doc.documentElement !== null) {
14             return doc.documentElement.textContent || '';
15         }
16         return '';
17     });
18     return out.join(' ');
19 };