RTL in Obsidian Publish

Here’s my CSS for getting my published site right to left oriented (my
website - פנגייה - רשימת סיכומים - פנגייה).

/* Variables */
.published-container {
  --sidebar-left-border-width: 2px;
  --sidebar-right-border-width: 2px;
  --site-name-size: 36px;
  --logo-max-height: 100px;
  --component-title-size: var(--font-ui-medium);
}

/* Make it rtl */
div,
h1,
h2,
h3,
h4,
h5 {
  direction: rtl;
}

:root {
  direction: inherit;
  writing-mode: sideways-rl;
  text-orientation: sideways-right;
}

h1,
h2,
h3,
h4,
h5,
.page-header,
.markdown-rendered th {
  font-weight: bold;
}

.is-collapsed .collapse-icon svg {
  transform: rotate(90deg);
}

/* Fix rtl shenanigans */

.site-body-left-column {
  padding: 32px 18px 0 0;
  border-left: var(--sidebar-left-border-width) solid
    var(--sidebar-left-border-color);
  border-right: 0;
}

.site-body-left-column .site-body-left-column-inner {
  margin-right: auto;
  margin-left: 0;
}

.site-body-left-column-site-logo img {
  margin-left: auto;
  margin-right: auto;
}

.theme-dark .site-body-left-column-site-logo {
  filter: invert(1);
}

.theme-dark .site-header-logo {
  filter: invert(1);
}

.site-body-left-column-site-name {
  padding: 4px 16px 32px 16px;
  margin-right: auto;
  margin-left: auto;
  font-family: "Secular One", sans-serif;
  font-weight: 400;
}

.site-body-left-column-site-theme-toggle .option.mod-light {
  left: 0;
  right: 2px;
}

.site-body-left-column-site-theme-toggle .option.mod-dark {
  left: 0;
  right: 22px;
}

.site-body-left-column .search-view-outer {
  padding-right: 0;
  padding-left: 18px;
}

.extra-title {
  right: 0;
  left: unset;
}

/* Navigation bar */
.nav-view-outer .tree-item-children .tree-item-children {
  padding-right: 18px;
  padding-left: 0;
}

.nav-view-outer .tree-item-self {
  margin-right: -1px;
  border-right: 1px solid transparent;
  padding-right: 16px;
  padding-left: 0.7em;
  margin-left: 0;
  border-left: 0;
}

.nav-view-outer .tree-item-children {
  padding-left: 0;
  padding-right: 6px;
}

.nav-view-outer .tree-item-self:not(.mod-collapsible) {
  border-right: 1px solid var(--nav-item-border-color);
  border-left: 0;
}

.nav-view-outer .tree-item-self:hover:not(.mod-collapsible):not(.mod-active) {
  border-right: 1px solid var(--nav-item-border-color-hover);
  border-left: 0;
}

.nav-view-outer .tree-item-self.mod-active {
  background-color: transparent;
  font-weight: var(--nav-item-weight-active);
  padding-left: 0.1em;
  color: var(--nav-item-color-active);
  border-right: 1px solid var(--nav-item-border-color-active);
  padding-right: 16px;
  border-left: 0;
}

.nav-view-outer .tree-item-self.mod-collapsible.is-clickable {
  margin-left: 0;
  margin-right: -8px;
}

.nav-view-outer .tree-item-children .tree-item-children .tree-item-children {
  padding-right: 18px;
  margin-right: -1px;
  padding-left: 0;
  margin-left: 0;
  border-left: 0;
}

.site-body-right-column {
  right: initial;
  left: 0;
  border-right: var(--sidebar-right-border-width) solid
    var(--sidebar-right-border-color);
  border-left: 0;
}

@media screen and (max-width: 750px) {
  .nav-view-outer .tree-item-self.is-clickable {
    padding: unset;
    padding-right: 16px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  .nav-view-outer .tree-item-self.is-clickable .tree-item-icon.collapse-icon {
    order: unset;
  }
  .nav-view-outer
    .tree-item-children
    .tree-item-children
    .tree-item-self.is-clickable:not(.mod-collapsible)
    .tree-item-inner {
    padding-right: unset;
    padding-left: unset;
  }
  .published-container.has-navigation .site-body-left-column {
    transform: translateX(100%);
  }
}

@media screen and (max-width: 1000px) {
  .publish-renderer {
    margin-left: 0;
  }
}

@media screen and (min-width: 1000px) {
  body:not(.sliding-windows)
    .is-readable-line-width.has-outline.has-navigation
    .publish-renderer
    > .markdown-preview-view
    > .markdown-preview-sizer,
  body:not(.sliding-windows)
    .is-readable-line-width.has-graph.has-navigation
    .publish-renderer
    > .markdown-preview-view
    > .markdown-preview-sizer {
    margin-right: 0;
  }
  .published-container.is-readable-line-width .publish-renderer {
    margin-left: max(calc((100vw - var(--page-width)) / 2), var(--sidebar-right-width));
  }
}

.not-found-container {
  right: 0;
  top: 0;
  left: 0;
  margin-right: auto;
  margin-left: auto;
}

/* Left "On This Page" bar */
.site-body-right-column .site-body-right-column-inner {
  margin-right: unset;
  margin-left: auto;
}

.outline-view-outer .tree-item-self {
  padding-left: 0.7em;
  padding-right: unset;
}

.outline-view-outer .tree-item-children {
  border-right: 1px solid var(--nav-item-border-color);
  border-left: 0;
}

.tree-item-children {
  padding-right: 18px;
  padding-left: 0;
}

.list-item .published-section-header {
  font-size: var(--font-ui-medium);
}

.site-footer {
  left: 18px;
  right: auto;
}
1 Like

Hi is your site still active? The link here doesn’t seem to work

Id like to publish sometimes rtl in Hebrew and some ltr in English. Have you been able to do that?

Thanks

Shaiya

You will want to use cssClasses on the notes you want to change, to enforce a different styling.

For example, say the default format of the text is LTR, but you want some notes to be RTL. The top of your note would contain the frontmatter/property below:

---
cssClasses: righty
---

And the CSS you would add to your publish would be.

/* Variables */
.righty .published-container {
  --sidebar-left-border-width: 2px;
  --sidebar-right-border-width: 2px;
  --site-name-size: 36px;
  --logo-max-height: 100px;
  --component-title-size: var(--font-ui-medium);
}

/* Make it rtl */
.righty div,
.righty h1,
.righty h2,
.righty h3,
.righty h4,
.righty h5 {
  direction: rtl;
}

And so on, adding .righty to the front of every existing selector

If you want RTL to be the default, and LTR to be the exception, you would use @NuclearGandhi’s Publish.css, and then also add a .lefty selector that reverts the changes.

---
cssClasses: lefty
---
/* Make it rtl */
.lefty div,
.lefty h1,
.lefty h2,
.lefty h3,
.lefty h4,
.lefty h5 {
  direction: ltr;
}

And so on, once again.

1 Like

Thanks! This is very helpful. Would it also be possible to use this code to make just part of a note RTL ? Maybe I could add the rightly code in the middle of the note, and another code to send it back to LTR, or does the code apply to the whole note only?

Or maybe I could get a section of a note to be RTL by embedding a RTL note inside a LRT note?

Or a different way?

Is there perhaps a cssClasses code that’s like the “auto” setting in the RTL plugin, so that it automatically knows to put Hebrew RTL and English LTR?

Thanks again

Hello again!

Would it also be possible to use this code to make just part of a note RTL ?

Wrap the part of the note you want in a HTML div. Note Markdown works different in HTML tags like shown below. You may have to use <b>bold</b> for bold, <I>italic</I> for italic, and so on.

<div class="lefty">
my content
</div>

or does the code apply to the whole note only?

cssClasses would apply to the whole note.

Is there perhaps a cssClasses code that’s like the “auto” setting in the RTL plugin, so that it automatically knows to put Hebrew RTL and English LTR?

No, since cssClasses is CSS.

A suggestion I have, if you want your notes to be half and half, is use a custom “invisible” callout that sets the text direction to the one you need for that content. See the div content callout code in the GitHub link. Add some of your RTL or LTR css in those.

1 Like

There is also this simpler Div callout css by @sailKite

.callout[data-callout="div-m"] {
    margin: unset;
    border: unset;
    border-radius: unset;
    padding: unset;
    margin-block: 1em;
    padding: unset;
    background: unset;
    mix-blend-mode: normal;

    & > .callout-title { display: none; }

    & > .callout-content {
        & > :first-child { margin-top: 0 !important; }
        & > :last-child { margin-bottom: 0 !important; }
    }
}

Hi! I’m trying to use the html wrap, but it doesn’t seem to work. Do I need to add something to the publish.css?

Right now in the publish.css I have:

/* Variables */
.righty .published-container {
  --sidebar-left-border-width: 2px;
  --sidebar-right-border-width: 2px;
  --site-name-size: 36px;
  --logo-max-height: 100px;
  --component-title-size: var(--font-ui-medium);
}

/* Make it rtl */
.righty div,
.righty h1,
.righty h2,
.righty h3,
.righty h4,
.righty h5 {
  direction: rtl;
}

Then, in the note, I put this:

<div class="righty">
Here I put a few words in Hebrew
</div>

But it still publishes it LTR. Human Identity - Obsidian Publish

I expect I’m missing something very basic and obvious :upside_down_face:

Thanks again for your help

Shaiya

You would need more than just the publish.css you are using. I used that small amount of CSS as an example of what you would need to do to all of the CSS posted in the opening post. RTL in Obsidian Publish?

I think for your use case, the callout option will be better, especially if you are mostly defaulting LTR and then only occasionally doing RTL.

.callout[data-callout="righty"] {
    float: right;
    margin: unset;
    border: unset;
    border-radius: unset;
    padding: unset;
    align-content: end;
    margin-block: 1em;
    padding: unset;
    background: unset;
    mix-blend-mode: normal;
    direction: rtl;

    & > .callout-title { display: none; }

    & > .callout-content {
        & > :first-child { margin-top: 0 !important; }
        & > :last-child { margin-bottom: 0 !important; }
    }
}
> [!righty] Hidden Title
> Text here
1 Like

Yeah, changed my domain. better have this link.

Thanks! Looks great.