SelfscribeDownloadOpen the app

Group chat

Paste a chat as plain lines and get bubbles, colours and day dividers.

Document · Simple · uses markup

Edit it in the playgroundRead the file

What it shows

Turn lines that start with a name into a chat, with a bubble and a colour for each person.

What you learn

A line rule per speaker, group to wrap neighbouring lines in one chat, one shared class with a colour per person, a name drawn from a value, marks inside a bubble for replies, reactions and times.

Try this

  • Add a line starting with Ana: anywhere in the chat, and a blue bubble with her name appears.
  • Give a new person a colour in the palette and a rule like Lu's, and their lines become bubbles too.
examples/group-chat.self · 84 lines
~~~ selfscribe
# Lesson: Turn lines that start with a name into a chat, with a bubble and a colour for each person.
# You learn: a line rule per speaker, group to wrap neighbouring lines in one chat, one shared class with a colour per person, a name drawn from a value, marks inside a bubble for replies, reactions and times.
# Try this: add a line starting with `Ana:` anywhere in the chat, and a blue bubble with her name appears.
# Try this: give a new person a colour in the palette and a rule like Lu's, and their lines become bubbles too.
# summary: Paste a chat as plain lines and get bubbles, colours and day dividers.
# category: fun
# tags: document, simple, social
# uses: markup
use markdown
set title Group chat

# ---- One colour per person, and one bubble look everyone shares -----------------------
palette
  ana   #1c6fd1  dark #74b5ff
  tom   #2b8a3e  dark #69db7c
  lu    #a33ac2  dark #e599f7
  me    #1f6feb  dark #2f6fd0
  panel color-mix(in srgb, currentColor 4%, transparent)

# The group wrapper is the chat window: a header, then a column of bubbles.
class chat  { display: flex; flex-direction: column; gap: 0.4em; padding: 0 1.1em 1.2em; margin: 0 0 1.8em; border-radius: 22px; background: var(--panel); border: 1px solid color-mix(in srgb, currentColor 10%, transparent); font-family: var(--doc-font-ui); font-size: 0.94em; line-height: 1.4; overflow: hidden }
# A bubble tints itself with --who and shows --name above the text; each person's rule sets both.
class msg  { align-self: flex-start; max-width: 76%; padding: 0.45em 0.85em 0.55em; border-radius: 18px 18px 18px 5px; background: color-mix(in srgb, var(--who) 13%, transparent) }
class msg::before  { content: var(--name, none); display: block; font-size: 0.74em; font-weight: 700; color: var(--who); margin-bottom: 0.1em }

# ---- "== Lake trip | Ana, Tom, Lu and you ==": the window's header ----------------------
line   == _ ==         -> div.chat-head  group div.chat  split "|" span  { display: flex; flex-direction: column; gap: 0.15em; margin: 0 -1.1em 0.6em; padding: 0.9em 1.1em; text-align: center; border-bottom: 1px solid color-mix(in srgb, currentColor 10%, transparent); background: color-mix(in srgb, currentColor 3%, transparent) }  as gc-head
class chat-head > span:first-child  { font-weight: 700 }
class chat-head > span:last-child  { font-size: 0.78em; opacity: 0.6 }

# ---- "Ana: hello" on its own line: a bubble in that person's colour ----------------------
# group div.chat: lines next to each other share one chat window.
line   Ana: _          -> div.msg    group div.chat  { --who: var(--ana); --name: "Ana" }  as gc-ana
line   Tom: _          -> div.msg    group div.chat  { --who: var(--tom); --name: "Tom" }  as gc-tom
line   Lu: _           -> div.msg    group div.chat  { --who: var(--lu); --name: "Lu" }   as gc-lu
# Your own lines sit on the right, filled in, as on a phone.
line   Me: _           -> div.msg    group div.chat  { align-self: flex-end; border-radius: 18px 18px 5px 18px; background: var(--me); color: #fff }  as gc-me

# ---- "-- Friday 11 September --" on its own line: a day, centred between the bubbles ------
line   -- _ --         -> div.day    group div.chat  { align-self: center; font: 600 0.7em/1 var(--doc-font-ui); letter-spacing: 0.06em; padding: 0.5em 0.9em; border-radius: 999px; background: color-mix(in srgb, currentColor 7%, transparent); margin: 0.7em 0 0.3em }  as gc-day

# ---- Inside a bubble: "[re: …]" quotes, "(+👍)" reacts, "<09:12>" is the time ----------
inline [re: _]         -> span.reply     { display: block; font-size: 0.8em; opacity: 0.75; border-left: 2px solid currentColor; padding-left: 0.5em; margin: 0.15em 0 0.3em }  as gc-reply
inline (+_)            -> span.react     { display: inline-block; margin-left: 0.4em; padding: 0 0.4em; border-radius: 999px; background: color-mix(in srgb, currentColor 12%, transparent); font-size: 0.85em }  as gc-react
inline <_>             -> span.time      bound  { float: right; margin: 0.35em 0 0 0.9em; font-size: 0.68em; opacity: 0.6 }  as gc-time
~~~
== Lake trip 🏕️ | Ana, Tom, Lu and you ==
-- Friday 11 September --
Ana: <18:02> Lake tomorrow? The forecast finally looks decent
Tom: <18:05> I'm in. Bus or bikes?
Me: <18:06> [re: Bus or bikes?] bus, the 11:40 goes all the way to the beach (+👍)
Lu: <18:20> can't until 2, meet you there? (+❤️)
Ana: <18:21> perfect, we'll save you a spot by the big rock
Tom: <18:24> I'll bring the speaker. And the frisbee nobody can throw
-- Saturday 12 September --
Tom: <09:12> who's bringing the good knife
Me: <09:13> me, and bread and cheese
Ana: <09:15> peaches from the market!! (+🍑) (+🎉)
Lu: <13:58> on the bus, 20 min
Me: <14:01> [re: on the bus, 20 min] we're by the big rock, you'll hear Tom before you see him
Lu: <14:02> 😂 on my way

## Decided

- Bus at 11:40, back on the 18:10
- Ana: peaches · Tom: drinks and the speaker · Me: bread, cheese and the knife
- Lu joins at two, by the big rock

## How it's made

- Every line that starts with a name and a colon is a bubble. One rule per person sets two values, `--who` for the colour and `--name` for the label, and the shared `msg` class does the rest. `Me:` lines sit on the right.
- Lines in a row share one chat window, because each rule says `group div.chat`. The `==` line at the top is the window's header.
- `-- Saturday 12 September --` marks a day. Inside a bubble, `[re: …]` quotes the message being answered, `(+🎉)` is a reaction and `<09:12>` the time.
- The lines under "Decided" start with a dash, so they stay an ordinary list.

## Try it yourself

1. Add `Tom: <14:03> I heard that (+😂)` under the last line of the chat. A green bubble with Tom's name joins Saturday.
2. Add `-- Sunday 13 September --` and then `Lu: <10:20> sunburnt but happy` at the end of the chat. A new day starts with Lu's bubble.
3. Change `ana  #1c6fd1` in the palette to `ana  #e8590c`. Every one of Ana's bubbles turns orange.
4. Write `[re: peaches from the market!!]` at the start of Lu's 13:58 message. Her bubble quotes Ana.

Next: *Changelog* gives each kind of line its own colour; *Your own notation* turns short lines into drawings.