Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add a metadata tag to override notebook direction (ltr/rtl)#5052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
blink1073 merged 2 commits intojupyter:masterfromm2-farzan:allow-per-notebook-rtl
Jul 23, 2020

Conversation

@m2-farzan
Copy link
Contributor

Currently, the direction of text flow in a notebook (left-to-right / right-to-left) is determined by browser language settings. If the browser is set to use a language with right-to-left script, all notebooks are displayed in RTL direction and vice versa.

This behavior could be improved, IMHO (I'm a student from the middle east). I write my homework in my mother language, but I also download stuff from the internet which are mostly in English. This means that I have to change my browser language settings frequently, which is not user friendly.

This PR makes it possible to override this default behaviorper notebook using a metadata tag. Here's how to use this tag in order to make a notebook RTL:

"direction": "rtl"

or to force notebook to use LTR:

"direction": "ltr"

The end user could either manually set this tag or use thetoggle rtl layout command from the command palette to change the direction of a notebook permanently, without needing to change the browser settings.

That's it from the end user point of view.

yuval-reshef reacted with thumbs up emoji
Comment on lines 81 to 95
try{
requirejs(['custom/custom'],function(){});
bidi.loadLocale();
}catch(err){
console.log("Error processing custom.js. Logging and continuing");
console.warn(err);
}
Copy link
ContributorAuthor

@m2-farzanm2-farzanNov 12, 2019
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Important note:

I've moved these lines to the very end of the file, because the functionbidi.loadLocale now reads metadata from the notebook and must be called after loading it. The problem is that I don't know if this change could cause any unwanted side effects, especially since there's a line that loads a custom script and I don't know what it is at all.

Please just make sure I'm not breaking things here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

custom.js is meant as a place for users to put arbitrary javascript to customise the notebook interface. Which probably means any change to how it's loaded is going to break something for someone, somewhere, but that can't really be helped.

I'm not sure why loading it is tied to bidi support, though. :-/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hi@m2-farzan, I suggest we break this up: leave thecustom.js loading where it is and move thebidi.locale() handling to the end of the file. This PR also needs a rebase.

@takluyver
Copy link
Member

Thanks! There's some relevant discussion atipython/ipython#10980 . Someone has suggested ignoring the browser locale settings and always using LTR layout by default. That would still be compatible with having a direction stored in the notebook metadata, I think.

(I can't read any RTL languages, so I'm hoping that a consensus will appear among people who can about the best ways to handle them)

yuval-reshef reacted with thumbs up emoji

@m2-farzanm2-farzanforce-pushed theallow-per-notebook-rtl branch from59da182 to30ed681CompareJune 22, 2020 19:18
@m2-farzan
Copy link
ContributorAuthor

So I've been working on this recently, and I hope you like the end result.

30ed681 will allow the users to control the direction of the notebook by the following means:

  • a notebook metadata tag,direction, which could be eitherltrorrtl

  • a cell metadata tag, againdirection, that overrides notebook settings. Eitherrtl orltr.
    (Why this one? A common example is that when writing in RTL languages, users often need to write latex equation blocks for which you need an LTR cell. So cell-level control is essential.)

The behavior is described below:

  • A notebook without adirection tag will be LTR. That is, notebook will ignore browser locale settings from now on. This behavior was suggested by two users inJupyter notebook become RTL after upgrade ipython/ipython#10980. It also keeps a notebook from looking different on different computers. However, please note that we're breaking the previous behavior here.

  • A markdown cell without adirection tag will inherit direction from notebook. Adirection tag overrides it. I've also added an action in the command palette "toggle current cell ltr/rtl layout direction" which sets the tag for the user. (How about a shortcut for it?)

  • In a code cell, the code itself (code mirror) will never become RTL—no one ever writes code in RTL mode. However, adirection tag with valuertl will cause the output to become RTL. The code cell always defaults in LTR (that is, it doesn't inherit from notebook settings), because IMHO RTL output from code is rarely required and it would be a pain change it back every time. Most people are just dealing with math or getting simple English logs/errors.

Copy link
Contributor

@blink1073blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM, thanks! Marking this for 6.2 since we're in a 6.1 release cycle.

@blink1073
Copy link
Contributor

I kicked the CI jobs

@blink1073
Copy link
Contributor

Thanks for fixing the CI!

m2-farzan reacted with heart emoji

@kevin-bateskevin-bates mentioned this pull requestJul 22, 2020
24 tasks
@blink1073blink1073 modified the milestones:6.2,6.1Jul 23, 2020
@blink1073blink1073 merged commit9de5042 intojupyter:masterJul 23, 2020
@zareami10
Copy link

It would be great if we could also have this in Lab.

@m2-farzan
Copy link
ContributorAuthor

@zareami10 I've been working on it recently. It will be ready soon.

zareami10 reacted with hooray emoji

@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJun 6, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@takluyvertakluyvertakluyver left review comments

+1 more reviewer

@blink1073blink1073blink1073 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.1

Development

Successfully merging this pull request may close these issues.

4 participants

@m2-farzan@takluyver@blink1073@zareami10

[8]ページ先頭

©2009-2025 Movatter.jp