Skip to content

Commit

Permalink
feat: apply dir="auto" to callout container elements for automatic …
Browse files Browse the repository at this point in the history
…text direction
  • Loading branch information
lin-stephanie committed Nov 9, 2024
1 parent fa7aa88 commit 5e2dbd0
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Then running `node example.js` or `pnpm astro dev` yields:

```html
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand All @@ -124,6 +125,7 @@ Then running `node example.js` or `pnpm astro dev` yields:
</div>

<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(236, 117, 0); --callout-color-dark: rgb(233, 151, 63);"
>
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const rehypeCallouts: Plugin<[UserOptions?], Root> = (options) => {
// modify the blockquote element
// @ts-expect-error (Type '"div" | "details"' is not assignable to type '"blockquote"')
node.tagName = collapsable ? 'details' : 'div'
node.properties.dir = 'auto'
node.properties.className = [
'callout',
collapsable && 'callout-collapsible',
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/basic/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand All @@ -11,6 +12,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand All @@ -23,6 +25,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand All @@ -35,6 +38,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(236, 117, 0); --callout-color-dark: rgb(233, 151, 63);"
>
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/collapsibleCallouts/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand Down Expand Up @@ -26,6 +27,7 @@
</details>

<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand Down Expand Up @@ -53,6 +55,7 @@
</details>

<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand Down Expand Up @@ -80,6 +83,7 @@
</details>

<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(236, 117, 0); --callout-color-dark: rgb(233, 151, 63);"
>
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/customAliases/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand All @@ -11,6 +12,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand All @@ -23,6 +25,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand All @@ -35,6 +38,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/customCallouts/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(227, 107, 167); --callout-color-dark: rgb(227, 107, 167);"
>
Expand Down Expand Up @@ -28,6 +29,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(227, 107, 167); --callout-color-dark: rgb(227, 107, 167);"
>
Expand Down Expand Up @@ -57,6 +59,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: #e36ba7; --callout-color-dark: #f86bb7;"
>
Expand All @@ -69,6 +72,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: #e36ba7; --callout-color-dark: #f86bb7;"
>
Expand All @@ -83,6 +87,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(227, 107, 167); --callout-color-dark: rgb(227, 107, 167);"
>
Expand Down Expand Up @@ -112,6 +117,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(227, 107, 167); --callout-color-dark: rgb(227, 107, 167);"
>
Expand Down Expand Up @@ -143,6 +149,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: #888; --callout-color-dark: #888;"
>
Expand All @@ -155,6 +162,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: #888; --callout-color-dark: #888;"
>
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/customTheme/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(142, 150, 170); --callout-color-dark: rgb(101, 117, 133);"
>
Expand All @@ -25,6 +26,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(100, 108, 255); --callout-color-dark: rgb(100, 108, 255);"
>
Expand Down Expand Up @@ -54,6 +56,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(159, 122, 234); --callout-color-dark: rgb(159, 122, 234);"
>
Expand Down Expand Up @@ -83,6 +86,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(234, 179, 8); --callout-color-dark: rgb(234, 179, 8);"
>
Expand Down Expand Up @@ -116,6 +120,7 @@
</blockquote>

<div
dir="auto"
class="callout"
style="--callout-color-light: #888; --callout-color-dark: #888;"
>
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/fromHtml/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand All @@ -11,6 +12,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand All @@ -23,6 +25,7 @@
</div>

<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(236, 117, 0); --callout-color-dark: rgb(233, 151, 63);"
>
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/markdownInTitle/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/modifyCallouts/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand Down Expand Up @@ -27,6 +28,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand Down Expand Up @@ -56,6 +58,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: #e36ba7; --callout-color-dark: #f86bb7;"
>
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/nestedCallouts/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand All @@ -8,6 +9,7 @@
<div class="callout-content">
<p>This is the content!</p>
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand All @@ -20,6 +22,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand All @@ -29,6 +32,7 @@
<div class="callout-content">
<p>This is the content!</p>
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand All @@ -42,6 +46,7 @@
</div>

<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand All @@ -66,6 +71,7 @@
<div class="callout-content">
<p>This is the content!</p>
<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/openOrClose/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(236, 117, 0); --callout-color-dark: rgb(233, 151, 63);"
>
Expand Down Expand Up @@ -45,6 +46,7 @@
</details>

<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(236, 117, 0); --callout-color-dark: rgb(233, 151, 63);"
open
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/readmeExample/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand Down Expand Up @@ -27,6 +28,7 @@
</div>

<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(236, 117, 0); --callout-color-dark: rgb(233, 151, 63);"
>
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/showIndicator/output.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand Down Expand Up @@ -27,6 +28,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand Down Expand Up @@ -56,6 +58,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand Down Expand Up @@ -85,6 +88,7 @@
</div>

<div
dir="auto"
class="callout"
style="--callout-color-light: rgb(236, 117, 0); --callout-color-dark: rgb(233, 151, 63);"
>
Expand Down Expand Up @@ -118,6 +122,7 @@
<blockquote><p>[!cantio] This is a non-existent callout type!</p></blockquote>

<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(8, 109, 221); --callout-color-dark: rgb(2, 122, 255);"
>
Expand Down Expand Up @@ -158,6 +163,7 @@
<div class="callout-content">
<p>This is the content!</p>
<details
dir="auto"
class="callout callout-collapsible"
style="--callout-color-light: rgb(0, 191, 188); --callout-color-dark: rgb(83, 223, 221);"
>
Expand Down

0 comments on commit 5e2dbd0

Please sign in to comment.