Skip to content

Commit

Permalink
🔀 Merge pull request #60 from davep/markdown-notes
Browse files Browse the repository at this point in the history
Render notes as Markdown
  • Loading branch information
davep authored Jan 9, 2025
2 parents fd5ca25 + 21b9221 commit 5312ea8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
name. ([#53](https://github.com/davep/braindrop/pull/53))
- Various cosmetic tweaks to the help screen.
([#53](https://github.com/davep/braindrop/pull/53))
- Notes are now rendered as a Markdown document.
([#60](https://github.com/davep/braindrop/pull/60))

## v0.3.0

Expand Down
2 changes: 1 addition & 1 deletion src/braindrop/app/screens/raindrop_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def compose(self) -> ComposeResult:
yield Label("Excerpt:")
yield TextArea(id="excerpt")
yield Label("Note:")
yield TextArea(id="note")
yield TextArea(id="note", language="markdown")
yield Label("URL:")
yield Input(
placeholder="The URL of the link for the Raindrop",
Expand Down
25 changes: 17 additions & 8 deletions src/braindrop/app/widgets/raindrop_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##############################################################################
# Python imports.
from datetime import datetime
from typing import Any, Callable, Final
from typing import Any, Callable, Final, cast

##############################################################################
# Humanize imports.
Expand All @@ -20,7 +20,7 @@
from textual.binding import Binding
from textual.containers import VerticalScroll
from textual.reactive import var
from textual.widgets import Label
from textual.widgets import Label, Markdown
from textual.widgets.option_list import Option

##############################################################################
Expand Down Expand Up @@ -112,13 +112,20 @@ class RaindropDetails(VerticalScroll):
display: none;
}
Label {
Label, Markdown {
margin: 0 2 1 2;
padding: 1 2 1 2;
width: 1fr;
color: $text;
}
Label {
padding: 1 2 1 2;
}
Markdown {
padding: 1 2 0 2;
}
.detail {
color: $foreground;
background: $boost 150%;
Expand Down Expand Up @@ -196,22 +203,24 @@ def compose(self) -> ComposeResult:
yield Label(id="borked")
yield Label(id="excerpt")
yield Label(id="collection", classes="detail")
yield Label(id="note", classes="detail")
yield Markdown(id="note", classes="detail")
yield Label(id="created-ish", classes="detail ish")
yield Label(id="created", classes="detail exact")
yield Label(id="updated-ish", classes="detail ish")
yield Label(id="updated", classes="detail exact")
yield Link(id="link", classes="detail")
yield Tags().data_bind(RaindropDetails.raindrop)

def _set(self, widget: str, value: str) -> None:
def _set(
self, widget: str, value: str, widget_type: type[Label | Markdown] = Label
) -> None:
"""Set the value of a detail widget.
Args:
widget: The ID of the widget to set.
value: The value to set.
"""
self.query_one(f"#{widget}", Label).update(value)
cast(Label | Markdown, self.query_one(f"#{widget}", widget_type)).update(value)
self.query_one(f"#{widget}").set_class(not bool(value), "empty")

@staticmethod
Expand Down Expand Up @@ -253,7 +262,7 @@ def _refresh_display(self) -> None:
f"{PUBLIC_ICON if self.data.collection(self.raindrop.collection).public else PRIVATE_ICON}"
f" {self.data.collection(self.raindrop.collection).title}",
)
self._set("note", self.raindrop.note)
self._set("note", self.raindrop.note, Markdown)
self._set(
"created-ish", self._time(self.raindrop.created, "Created", naturaltime)
)
Expand Down

0 comments on commit 5312ea8

Please sign in to comment.