Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat: justify API (#59)

Akshay Agrawalff3e0e62e333
diff --git a/docs/api/layouts/index.md b/docs/api/layouts/index.md
index dc3c8690be..fa8a46a67e 100644
--- a/docs/api/layouts/index.md
+++ b/docs/api/layouts/index.md
@@ -8,6 +8,7 @@
accordion
callout
image
+ justify
stacks
tabs
tree
@@ -23,7 +24,10 @@ certain way.
marimo.accordion
marimo.callout
+ marimo.center
marimo.hstack
+ marimo.left
+ marimo.right
marimo.vstack
marimo.tabs
marimo.tree
diff --git a/docs/api/layouts/justify.md b/docs/api/layouts/justify.md
new file mode 100644
index 0000000000..32ffd0858a
--- /dev/null
+++ b/docs/api/layouts/justify.md
@@ -0,0 +1,13 @@
+# Justify
+
+```{eval-rst}
+.. autofunction:: marimo.center
+```
+
+```{eval-rst}
+.. autofunction:: marimo.left
+```
+
+```{eval-rst}
+.. autofunction:: marimo.right
+```
diff --git a/marimo/__init__.py b/marimo/__init__.py
index cd8f06f814..30a95f1cc9 100644
--- a/marimo/__init__.py
+++ b/marimo/__init__.py
@@ -19,14 +19,17 @@ __all__ = [
"as_html",
"audio",
"callout",
+ "center",
"config",
"defs",
"doc",
"hstack",
"Html",
"image",
+ "left",
"md",
"refs",
+ "right",
"stop",
"tabs",
"tree",
@@ -40,6 +43,7 @@ from marimo._ast.app import App
from marimo._output.doc import doc
from marimo._output.formatting import as_html
from marimo._output.hypertext import Html
+from marimo._output.justify import center, left, right
from marimo._output.md import md
from marimo._plugins import ui
from marimo._plugins.stateless.accordion import accordion
diff --git a/marimo/_output/justify.py b/marimo/_output/justify.py
new file mode 100644
index 0000000000..7aaf979fdd
--- /dev/null
+++ b/marimo/_output/justify.py
@@ -0,0 +1,37 @@
+# Copyright 2023 Marimo. All rights reserved.
+from marimo._output.formatting import as_html
+from marimo._output.hypertext import Html
+from marimo._output.rich_help import mddoc
+
+
+@mddoc
+def center(item: object) -> Html:
+ """Center an item.
+
+ **Returns.**
+
+ A centered `Html` object.
+ """
+ return as_html(item).center()
+
+
+@mddoc
+def left(item: object) -> Html:
+ """Left-justify an item.
+
+ **Returns.**
+
+ A left-justified `Html` object.
+ """
+ return as_html(item).left()
+
+
+@mddoc
+def right(item: object) -> Html:
+ """Right-justify an item.
+
+ **Returns.**
+
+ A right-justified `Html` object.
+ """
+ return as_html(item).right()