FB2: fix tables

Fixes https://github.com/johnfactotum/foliate/issues/1445
This commit is contained in:
John Factotum
2024-12-02 09:47:58 +08:00
parent b5ae4c22c1
commit 936c4f78e5
+10 -7
View File
@@ -27,9 +27,10 @@ const STYLE = {
} }
const TABLE = { const TABLE = {
'tr': ['tr', ['align']], 'tr': ['tr', {
'th': ['th', ['colspan', 'rowspan', 'align', 'valign']], 'th': ['th', STYLE, ['colspan', 'rowspan', 'align', 'valign']],
'td': ['td', ['colspan', 'rowspan', 'align', 'valign']], 'td': ['td', STYLE, ['colspan', 'rowspan', 'align', 'valign']],
}, ['align']]
} }
const POEM = { const POEM = {
@@ -125,7 +126,7 @@ class FB2Converter {
if (!d) return null if (!d) return null
if (typeof d === 'string') return this[d](node) if (typeof d === 'string') return this[d](node)
const [name, opts] = d const [name, opts, attrs] = d
const el = this.doc.createElement(name) const el = this.doc.createElement(name)
// copy the ID, and set class name from original element name // copy the ID, and set class name from original element name
@@ -133,11 +134,13 @@ class FB2Converter {
el.classList.add(node.nodeName) el.classList.add(node.nodeName)
// copy attributes // copy attributes
if (Array.isArray(opts)) for (const attr of opts) if (Array.isArray(attrs)) for (const attr of attrs) {
el.setAttribute(attr, node.getAttribute(attr)) const value = node.getAttribute(attr)
if (value) el.setAttribute(attr, value)
}
// process child elements recursively // process child elements recursively
const childDef = opts === 'self' ? def : Array.isArray(opts) ? null : opts const childDef = opts === 'self' ? def : opts
let child = node.firstChild let child = node.firstChild
while (child) { while (child) {
const childEl = this.convert(child, childDef) const childEl = this.convert(child, childDef)