-
Notifications
You must be signed in to change notification settings - Fork 2
/
texml-to-html.js
32 lines (24 loc) · 878 Bytes
/
texml-to-html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { xmlDom, htmlDom } from './lib/doms.js';
import { setHead } from './lib/head.js';
import { Transformer } from './lib/transformer.js';
import { applyHacks } from './lib/hacks.js';
/**
*
* @param {String} xmlstring - XML string
* @param {Object} imageAltDictionary - Key value store with file names and alt text strings
* @returns {Document}
*/
const xml2html = (xmlstring, imageAltDictionary = {}) => {
const xml = xmlDom(xmlstring);
const xmldoc = xml.window.document;
const root = xmldoc.querySelector('book, article');
const isBook = root.tagName === 'book';
const html = htmlDom();
const htmldoc = html.window.document;
setHead(xmldoc, htmldoc);
const transformer = new Transformer(htmldoc, imageAltDictionary, isBook);
transformer.recurseTheDom(htmldoc.body, root);
applyHacks(htmldoc);
return html;
};
export default xml2html;