SelfscribeDownloadOpen the app

Chat

Write a conversation as Name: message lines and read it as chat bubbles, yours on the right.

A rulebook. Save it in the app's library, then start any document with use chat.

Edit it in the playgroundRead the file

What it shows

Turn "Name: message" lines into chat bubbles.

What you learn

A line rule with two slots, a more exact rule that wins for your own lines, one group that gathers every chat line into a frame, small marks for names and times, a line split into parts.

Try this

  • Change me in the palette to #2b8a3e, and your own bubbles turn green.
examples/rulebooks/chat.self · 80 lines
~~~ selfscribe
# Chat: write conversations as "Name: message" and get bubbles. Use it with:  use chat
# Lesson: Turn "Name: message" lines into chat bubbles.
# You learn: a line rule with two slots, a more exact rule that wins for your own lines, one group that gathers every chat line into a frame, small marks for names and times, a line split into parts.
# Try this: change `me` in the palette to #2b8a3e, and your own bubbles turn green.
# summary: Write a conversation as Name: message lines and read it as chat bubbles, yours on the right.
# category: syntax
set title Chat

# ---- Colours, each with its shade for dark pages -------------------------------------
palette
  me    #1c64d8  dark #74a7ff
  name  #6741d9  dark #b197fc

# ---- The frame: every chat line below has group div.chat, so they gather into one -------
class chat  { display: flex; flex-direction: column; gap: 0.35em; max-width: 31em; margin: 0 auto 2em; padding: 0 1em 1.2em; border-radius: 22px; border: 1px solid color-mix(in srgb, currentColor 13%, transparent); background: color-mix(in srgb, currentColor 3%, transparent); font: 0.95em/1.45 var(--doc-font-ui); overflow: hidden }

# ---- "# Name of the chat | who is in it": the bar at the top of the frame -------------
line   # _           -> div.chat-head   split "|" span  group div.chat  { margin: 0 -1.1em 0.3em; padding: 0.85em 1em 0.75em; text-align: center; font-weight: 700; border-bottom: 1px solid color-mix(in srgb, currentColor 11%, transparent); background: color-mix(in srgb, currentColor 4%, transparent) }  as ch-head
class chat-head > span:last-child  { display: block; font-weight: 400; font-size: 0.8em; opacity: 0.65 }

# ---- "Name: message" on a line: a bubble on the left ------------------------------------
# The first slot is the name, the second the message; _1 _2 writes both into the bubble.
class bubble  { align-self: flex-start; max-width: 80%; padding: 0.45em 0.85em 0.5em; border-radius: 4px 18px 18px 18px; background: color-mix(in srgb, currentColor 8%, transparent) }
line   _: _          -> div.bubble      _1 _2  group div.chat  as ch-bubble

# ---- "Me: message": your own bubble, on the right in blue ------------------------------
# Me: has more written characters than _: _, so this rule wins for your lines.
line   Me: _         -> div.bubble.me   group div.chat  { align-self: flex-end; border-radius: 18px 4px 18px 18px; background: color-mix(in srgb, var(--me) 22%, transparent) }  as ch-me

# ---- <Name> shows the name above the message; [09:12] puts the time on the right ------
inline <_>           -> b.who           { display: block; font-size: 0.78em; color: var(--name) }  as ch-who
inline [_]           -> time            { float: right; margin: 0.25em 0 0 0.9em; font: 0.72em/1.6 var(--doc-font-mono); opacity: 0.55 }  as ch-time

# ---- "-- Saturday --" on its own line: a divider between days ---------------------------
line   -- _ --       -> div.divider     group div.chat  { align-self: center; margin: 0.8em 0 0.3em; padding: 0.3em 0.9em; border-radius: 999px; font: 600 0.7em/1.2 var(--doc-font-ui); letter-spacing: 0.12em; text-transform: uppercase; background: color-mix(in srgb, currentColor 7%, transparent); opacity: 0.75 }  as ch-divider

# ---- *italic*, **bold** and `code` inside a message --------------------------------------
inline *_*           -> em
inline **_**         -> strong
inline `_`           -> code            verbatim

# ---- "## Heading": a heading outside the chat, for notes around it ----------------------
line   ## _          -> h2
~~~
# Saturday hike | Priya, Tom and you
-- Saturday --
<Priya>: [09:12] Are we still on for the hike?
Me: [09:14] Yes! Meet at the station at ten?
<Tom>: [09:15] I'll bring the **good** sandwiches.
<Priya>: [09:16] Rain after *three*, so let's be off the top by two.
Me: [09:18] Then it's settled. The 10.24 to Hathersage, platform 2.
<Tom>: [10:11] Running *slightly* late. Save me a seat.
Me: [10:12] Seat saved. Coffee too.

-- Sunday --
<Priya>: [18:05] The photos are in the shared album. Tom's sandwiches made the cover.
<Tom>: [18:06] As they should.
Me: [18:07] Same time next month?
<Priya>: [18:09] Edale next time. I'll look up the trains.

## How it's made

A line with a name, a colon and a space is a bubble on the left. A line that starts with `Me` and a colon is yours, on the right. The rule for it is longer, so it wins.

A name in angle brackets shows above its message, and a time in square brackets sits at the right. A line between two pairs of dashes divides the days, and the line that starts with `#` is the bar at the top.

Every chat line has `group div.chat`, so they gather into one frame, blank lines and all. Any other line, like this one, ends it.

## Try it yourself

1. Change Tom to Sam in one of his lines. The name above the bubble follows.

2. Write a line of your own that starts with Me and a colon, under the last one. It appears on the right.

3. Change `me` in the palette to `#2b8a3e`. Your bubbles turn green.

4. Put two stars on each side of a word in a message. It turns bold.

**Next:** *Group chat* in the examples is a whole group's conversation, written with rules like these.