diff options
| author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-06-25 17:24:29 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-25 17:24:29 -0400 | 
| commit | 5756885fa9340f087a168d40c8d0d10a3a8fe4d5 (patch) | |
| tree | e960821662a12b70430590c9ea4f43b1abc4d54c /ext/js/display | |
| parent | cf70b3de6411cfd540f2c3c7f6e1c27afb10ef84 (diff) | |
Structured content updates (#1753)
* Update schema
* Update content generation
* Update styles
* Update test data
* Update style names
Diffstat (limited to 'ext/js/display')
| -rw-r--r-- | ext/js/display/display-generator.js | 71 | 
1 files changed, 63 insertions, 8 deletions
| diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index 6a5b26f1..7de65f78 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -442,23 +442,78 @@ class DisplayGenerator {          }          const {tag} = content;          switch (tag) { +            case 'br': +                return this._createStructuredContentElement(tag, content, dictionary, 'simple', false, false);              case 'ruby':              case 'rt':              case 'rp': -            { -                const node = document.createElement(tag); -                const child = this._createStructuredContent(content.content, dictionary); -                if (child !== null) { -                    node.appendChild(child); -                } -                return node; -            } +                return this._createStructuredContentElement(tag, content, dictionary, 'simple', true, false); +            case 'table': +                return this._createStructuredContentTableElement(tag, content, dictionary); +            case 'thead': +            case 'tbody': +            case 'tfoot': +            case 'tr': +                return this._createStructuredContentElement(tag, content, dictionary, 'table', true, false); +            case 'th': +            case 'td': +                return this._createStructuredContentElement(tag, content, dictionary, 'table-cell', true, true); +            case 'div': +            case 'span': +                return this._createStructuredContentElement(tag, content, dictionary, 'simple', true, true);              case 'img':                  return this._createDefinitionImage(content, dictionary);          }          return null;      } +    _createStructuredContentTableElement(tag, content, dictionary) { +        const container = document.createElement('div'); +        container.classList = 'gloss-sc-table-container'; +        const table = this._createStructuredContentElement(tag, content, dictionary, 'table', true, false); +        container.appendChild(table); +        return container; +    } + +    _createStructuredContentElement(tag, content, dictionary, type, hasChildren, hasStyle) { +        const node = document.createElement(tag); +        node.className = `gloss-sc-${tag}`; +        switch (type) { +            case 'table-cell': +                { +                    const {colSpan, rowSpan} = content; +                    if (typeof colSpan === 'number') { node.colSpan = colSpan; } +                    if (typeof rowSpan === 'number') { node.rowSpan = rowSpan; } +                } +                break; +        } +        if (hasStyle) { +            const {style} = content; +            if (typeof style === 'object' && style !== null) { +                this._setStructuredContentElementStyle(node, style); +            } +        } +        if (hasChildren) { +            const child = this._createStructuredContent(content.content, dictionary); +            if (child !== null) { node.appendChild(child); } +        } +        return node; +    } + +    _setStructuredContentElementStyle(node, contentStyle) { +        const {style} = node; +        const {fontStyle, fontWeight, fontSize, textDecorationLine, verticalAlign} = contentStyle; +        if (typeof fontStyle === 'string') { style.fontStyle = fontStyle; } +        if (typeof fontWeight === 'string') { style.fontWeight = fontWeight; } +        if (typeof fontSize === 'string') { style.fontSize = fontSize; } +        if (typeof verticalAlign === 'string') { style.verticalAlign = verticalAlign; } +        if (typeof textDecorationLine === 'string') { +            style.textDecoration = textDecorationLine; +        } else if (Array.isArray(textDecorationLine)) { +            style.textDecoration = textDecorationLine.join(' '); +        } +    } +      _createTermDisambiguation(disambiguation) {          const node = this._templates.instantiate('definition-disambiguation');          node.dataset.term = disambiguation; |