Skip to content

Commit 2d9db2c

Browse files
committed
fix: Arabic and other Right To Left metadata accessibility summary in publication info dialog (Fixes #2491)
1 parent 46ac923 commit 2d9db2c

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/renderer/common/components/dialog/publicationInfos/PublicationInfoDescription.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export default class PublicationInfoDescription extends React.Component<IProps,
6565
const { publicationViewMaybeOpds: { description }, __ } = this.props;
6666

6767
if (!description) return <></>;
68-
const textSanitize = DOMPurify.sanitize(description).replace(/font-size:/g, "font-sizexx:");
69-
if (!textSanitize) return <></>;
68+
const descriptionSanitized = DOMPurify.sanitize(description).replace(/font-size:/g, "font-sizexx:");
69+
if (!descriptionSanitized) return <></>;
7070
return (
7171
<>
7272
<div className={stylePublication.publicationInfo_heading}>
@@ -84,7 +84,7 @@ export default class PublicationInfoDescription extends React.Component<IProps,
8484
<div
8585
ref={this.descriptionRef}
8686
className={stylesBookDetailsDialog.allowUserSelect}
87-
dangerouslySetInnerHTML={{ __html: textSanitize }}
87+
dangerouslySetInnerHTML={{ __html: descriptionSanitized }}
8888
>
8989
</div>
9090
</div>

src/renderer/common/components/dialog/publicationInfos/publicationInfoA11y.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as debug_ from "debug";
1515
import DOMPurify from "dompurify";
1616
import * as React from "react";
1717
import { TPublication } from "readium-desktop/common/type/publication.type";
18-
import { convertMultiLangStringToString } from "readium-desktop/renderer/common/language-string";
18+
import { convertMultiLangStringToString, langStringIsRTL } from "readium-desktop/renderer/common/language-string";
1919
import isURL from "validator/lib/isURL";
2020
import { IRendererCommonRootState } from "readium-desktop/common/redux/states/rendererCommonRootState";
2121
import { connect } from "react-redux";
@@ -109,13 +109,13 @@ export class PublicationInfoA11y extends React.Component<IProps, IState> {
109109

110110
if (!a11y_accessibilitySummary) return undefined;
111111

112-
let textSanitize_a11y = "";
113-
const [, text] = convertMultiLangStringToString(a11y_accessibilitySummary, this.props.locale);
114-
if (text) {
115-
textSanitize_a11y = DOMPurify.sanitize(text).replace(/font-size:/g, "font-sizexx:");
116-
}
112+
const accessibilitySummaryLangStr = convertMultiLangStringToString(a11y_accessibilitySummary, this.props.locale);
113+
const accessibilitySummaryLang = accessibilitySummaryLangStr && accessibilitySummaryLangStr[0] ? accessibilitySummaryLangStr[0].toLowerCase() : "";
114+
const accessibilitySummaryIsRTL = langStringIsRTL(accessibilitySummaryLang);
115+
const accessibilitySummaryStr = accessibilitySummaryLangStr && accessibilitySummaryLangStr[1] ? accessibilitySummaryLangStr[1] : "";
116+
const accessibilitySummaryStrSanitized = accessibilitySummaryStr ? DOMPurify.sanitize(accessibilitySummaryStr).replace(/font-size:/g, "font-sizexx:") : "";
117117

118-
return textSanitize_a11y ?
118+
return accessibilitySummaryStr ?
119119
<div className={classNames(stylesBlocks.description_see_more)}>
120120
<div
121121
ref={this.descriptionWrapperRef_a11y}
@@ -127,7 +127,8 @@ export class PublicationInfoA11y extends React.Component<IProps, IState> {
127127
<div
128128
ref={this.descriptionRef_a11y}
129129
className={stylesBookDetailsDialog.allowUserSelect}
130-
dangerouslySetInnerHTML={{ __html: textSanitize_a11y }}
130+
dir={accessibilitySummaryIsRTL ? "rtl" : undefined}
131+
dangerouslySetInnerHTML={{ __html: accessibilitySummaryStrSanitized }}
131132
>
132133
</div>
133134
</div>

src/renderer/library/components/searchResult/AllPublicationPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ const CellTags: React.FC<ITableCellProps_Column & ITableCellProps_GenericCell &
882882
const CellDescription: React.FC<ITableCellProps_Column & ITableCellProps_GenericCell & ITableCellProps_StringValue> = (props) => {
883883

884884
const textNeedToBeSanitized = props.value || "";
885-
const textSanitize = DOMPurify.sanitize(textNeedToBeSanitized).replace(/font-size:/g, "font-sizexx:");
885+
const cellTextSanitized = DOMPurify.sanitize(textNeedToBeSanitized).replace(/font-size:/g, "font-sizexx:");
886886
const [isOpen, setIsOpen] = React.useState(false);
887887

888888
return (<div
@@ -901,7 +901,7 @@ const CellDescription: React.FC<ITableCellProps_Column & ITableCellProps_Generic
901901
// textAlign: props.displayType === DisplayType.Grid ? "justify" : "start",
902902
textAlign: "start",
903903
}}>
904-
<p dangerouslySetInnerHTML={{ __html: textSanitize }}></p>
904+
<p dangerouslySetInnerHTML={{ __html: cellTextSanitized }}></p>
905905
{props.value ?
906906
<Popover.Root onOpenChange={() => setIsOpen(!isOpen)}>
907907
<Popover.Trigger style={{maxWidth: "15px"}}>
@@ -913,7 +913,8 @@ const CellDescription: React.FC<ITableCellProps_Column & ITableCellProps_Generic
913913
</Popover.Trigger>
914914
<Popover.Portal>
915915
<Popover.Content collisionPadding={{top : 280}} avoidCollisions sideOffset={5} align="end" alignOffset={-10} hideWhenDetached>
916-
<p className={stylesDropDown.dropdown_description} dangerouslySetInnerHTML={{ __html: textSanitize }}></p>
916+
<p className={stylesDropDown.dropdown_description}
917+
dangerouslySetInnerHTML={{ __html: cellTextSanitized }}></p>
917918
<Popover.Arrow className={stylesDropDown.PopoverArrow} aria-hidden />
918919
</Popover.Content>
919920
</Popover.Portal>

src/renderer/reader/components/ReaderMenuSearch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ class ReaderMenuSearch extends React.Component<IProps, IState> {
404404
// }
405405
// data-href={link.Href}
406406
// >
407-
// <span dangerouslySetInnerHTML={{ __html: link.Title}}></span>
407+
// <span dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(link.Title)}}></span>
408408
// </a>
409409
// </div>
410410
// )}

0 commit comments

Comments
 (0)