Commit 0fcbe48a authored by Christian Sadilek's avatar Christian Sadilek
Browse files

Closes #2651: ReaderView must respect reading direction

parent 623ddcc6
......@@ -153,9 +153,12 @@ body.dark > .container > .content blockquote {
/*======= Article content =======*/
.content {
padding-left: 0px;
padding-right: 0px;
}
.moz-reader-content {
margin-left: -20px;
margin-right: -20px;
font-size: 1em;
}
......
......@@ -27,16 +27,20 @@ class ReaderView {
show({fontSize = 4, fontType = "sans-serif", colorScheme = "light"} = {}) {
var documentClone = document.cloneNode(true);
var result = new Readability(documentClone).parse();
result.language = document.documentElement.lang;
var article = Object.assign(
result,
{url: location.hostname},
{readingTime: this.getReadingTime(result.length, result.language)},
{byline: this.getByline()}
{byline: this.getByline()},
{dir: this.getTextDirection(result)}
);
document.body.outerHTML = this.createHtml(article);
this.setFontSize(fontSize);
this.setFontType(fontType)
this.setColorScheme(colorScheme)
this.setFontType(fontType);
this.setColorScheme(colorScheme);
}
hide() {
......@@ -116,7 +120,7 @@ class ReaderView {
createHtml(article) {
return `
<body>
<div id="readerview" class="container">
<div id="readerview" class="container" dir=${article.dir}>
<div class="header reader-header">
<a class="domain reader-domain">${article.url}</a>
<div class="domain-border"></div>
......@@ -239,6 +243,22 @@ class ReaderView {
return values["dc:creator"] || values["dcterm:creator"] || values["author"] || "";
}
/**
* Attempts to read the optional text direction from the article and uses
* language mapping to detect rtl, if missing.
*/
getTextDirection(article) {
if (article.dir) {
return article.dir
}
if (["ar", "fa", "he", "ug", "ur"].includes(article.language)) {
return "rtl";
}
return "ltr";
}
}
// TODO remove hostname check (for testing purposes only)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment