summaryrefslogtreecommitdiff
path: root/ext/js/display/sandbox
diff options
context:
space:
mode:
authorStephen Kraus <8003332+stephenmk@users.noreply.github.com>2022-05-14 08:59:38 -0500
committerGitHub <noreply@github.com>2022-05-14 09:59:38 -0400
commit6a74746113c724e750620d10b58ad6bac94060c9 (patch)
tree9e3cfbc7e7a5bc3b3c243ab1f2608aa46c99a193 /ext/js/display/sandbox
parente9843f67cb6b3ca903015d85e4c1e2ed18557cb0 (diff)
Add new structured content features: lists and the HTML `lang` attribute (#2129)
* Add support for structured content lists and `list-style-type` style A full list of supported style types is documented here: https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type There's nothing in this code preventing a term bank from assigning, for example, a `list-style-type` style to a `div` element, but it doesn't seem like browsers will complain about things like that. * Add support for `lang` attribute in structured content Support added for the following node types: "ruby", "rt", "rp", "table", "thead", "tbody", "tfoot", "tr", "td", "th", "span", "div", "ol", "ul", "li", "a" I couldn't get it to work for the alt-hover text on "img" tags. Tests are included in the file "test/data/dictionaries/valid-dictionary/term_bank_1.json" * Add styles for structured content lists * Add override rules for new structured-content list styles see: https://github.com/FooSoft/yomichan/pull/2129 Co-authored-by: stephenmk <stephenmk@users.noreply.github.com>
Diffstat (limited to 'ext/js/display/sandbox')
-rw-r--r--ext/js/display/sandbox/structured-content-generator.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/js/display/sandbox/structured-content-generator.js b/ext/js/display/sandbox/structured-content-generator.js
index eb847d07..6102cfdd 100644
--- a/ext/js/display/sandbox/structured-content-generator.js
+++ b/ext/js/display/sandbox/structured-content-generator.js
@@ -56,6 +56,9 @@ class StructuredContentGenerator {
return this._createStructuredContentElement(tag, content, dictionary, 'table-cell', true, true);
case 'div':
case 'span':
+ case 'ol':
+ case 'ul':
+ case 'li':
return this._createStructuredContentElement(tag, content, dictionary, 'simple', true, true);
case 'img':
return this.createDefinitionImage(content, dictionary);
@@ -204,8 +207,9 @@ class StructuredContentGenerator {
_createStructuredContentElement(tag, content, dictionary, type, hasChildren, hasStyle) {
const node = this._createElement(tag, `gloss-sc-${tag}`);
- const {data} = content;
+ const {data, lang} = content;
if (typeof data === 'object' && data !== null) { this._setElementDataset(node, data); }
+ if (typeof lang === 'string') { node.lang = lang; }
switch (type) {
case 'table-cell':
{
@@ -239,7 +243,8 @@ class StructuredContentGenerator {
marginTop,
marginLeft,
marginRight,
- marginBottom
+ marginBottom,
+ listStyleType
} = contentStyle;
if (typeof fontStyle === 'string') { style.fontStyle = fontStyle; }
if (typeof fontWeight === 'string') { style.fontWeight = fontWeight; }
@@ -254,6 +259,7 @@ class StructuredContentGenerator {
if (typeof marginLeft === 'number') { style.marginLeft = `${marginLeft}em`; }
if (typeof marginRight === 'number') { style.marginRight = `${marginRight}em`; }
if (typeof marginBottom === 'number') { style.marginBottom = `${marginBottom}em`; }
+ if (typeof listStyleType === 'string') { style.listStyleType = listStyleType; }
}
_createLinkElement(content, dictionary) {
@@ -269,6 +275,9 @@ class StructuredContentGenerator {
const text = this._createElement('span', 'gloss-link-text');
node.appendChild(text);
+ const {lang} = content;
+ if (typeof lang === 'string') { node.lang = lang; }
+
const child = this.createStructuredContent(content.content, dictionary);
if (child !== null) { text.appendChild(child); }