Skip to content

Commit b02f6af

Browse files
authored
Merge pull request #1127 from xcube-dev/forman-add_markdown_component
Add markdown component
2 parents 5351cd7 + 4b7e274 commit b02f6af

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
datasets and variable CF attributes.
1616
* Improved axis labeling in 2D histogram visualization in the Panel demo.
1717

18+
* Added support for the xcube Viewer's `Markdown` component so it can be used in
19+
server-side viewer extensions. See new package `xcube.webapi.viewer.components`
20+
exporting class `Markdown` which has a single `text` property that takes
21+
the markdown text.
22+
1823
### Other changes
1924

2025
* Reformatted code base according to the default settings used by

test/webapi/viewer/test_components.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2018-2025 by xcube team and contributors
2+
# Permissions are hereby granted under the terms of the MIT License:
3+
# https://opensource.org/licenses/MIT.
4+
5+
6+
import unittest
7+
8+
from xcube.webapi.viewer.components import Markdown
9+
10+
11+
class ViewerComponentsTest(unittest.TestCase):
12+
# noinspection PyMethodMayBeStatic
13+
def test_markdown(self):
14+
markdown = Markdown(text="_Hello_ **world**!")
15+
self.assertEqual(
16+
{"type": "Markdown", "text": "_Hello_ **world**!"},
17+
markdown.to_dict(),
18+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2018-2025 by xcube team and contributors
2+
# Permissions are hereby granted under the terms of the MIT License:
3+
# https://opensource.org/licenses/MIT.
4+
5+
from .markdown import Markdown
6+
7+
__all__ = [
8+
"Markdown",
9+
]
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2018-2025 by xcube team and contributors
2+
# Permissions are hereby granted under the terms of the MIT License:
3+
# https://opensource.org/licenses/MIT.
4+
5+
from dataclasses import dataclass
6+
7+
from chartlets import Component
8+
9+
10+
@dataclass(frozen=True)
11+
class Markdown(Component):
12+
"""A div-element in which the given markdown text is rendered."""
13+
14+
text: str | None = None
15+
"""The markdown text."""

xcube/webapi/viewer/context.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ def prepend_sys_path(path: Path | str | None):
101101
finally:
102102
if prev_sys_path:
103103
sys.path = prev_sys_path
104-
LOG.info(f"Restored sys.path")
104+
LOG.info("Restored sys.path")

0 commit comments

Comments
 (0)