Skip to content

Latest commit

 

History

History
223 lines (141 loc) · 8.12 KB

spec.md

File metadata and controls

223 lines (141 loc) · 8.12 KB

Message formatting / parsing of interactive elements and Specification of the format

This list is for every formating thing that goes beyond plain-text.

Modes of the parser

Text Enhancements

Text elements that are displayed as is with no change to the content, just enhanced (made clickable) if necessary.

hello@delta.chat - Email addresses

Make email addresses clickable, opens the chat with that contact and creates it if it does not already exist.

https://delta.chat and mailto:example@example.com - Links

Make URLs clickable.

  • detect all valid hyperlink URLs that have the :// (protocol://host).

  • other links like mailto: (note there is just a single :, no ://) will get separate parsing that includes a whitelisted protocol name, otherwise there will likely be unexpected behavior if user types hello:world - will be recognized as link.

  • .,,,;,: should not be parsed as an ending char of an inline-link(this rule is only for standalone/inline links)

Linkified schemes:

  • all Common Internet Scheme links (containing // after scheme),
  • mailto:, news:, feed:
  • tel:, sms:, geo:, maps:
  • bitcoin:, bitcoincash:, eth:, ethereum:
  • magnet:
mailto:email@address.example.com

Make mailto links clickable with all parameters: ?subject=Sample%20Subject&body=Sample%20Body Should open in delta chat directly.

Custom Deltachat URI Scheme

see https://support.delta.chat/t/custom-deltachat-url-scheme/346 Should open in deltachat directly.

Bot /commands

On click, the command gets prefilled as the draft, so it can be easily send. Also if the draft is not empty it should ask before replacing it.

/(?<=^|\\s)//[a-zA-Z][a-zA-Z@\\d_.-]{0,254}/

#tag

/#[\w]+/i

later we want something like /#[^ \n\r\t#]+/ (# then everything (besides #) until space/line break/tab) to also allow for chars from other locales and emojis, see #8 for more info

Basically a clickable search shortcut. On click, it opens the message search prefilled with that tag.

Inspired by twitters and telegrams #hashtag functionality.

other / internal

  • Text (what remains if nothing else could be detected)
  • line breaks

Markdown subset

The subset of Markdown that Deltachat is going to support, this contains everything that needs to be displayed differently, not only made clickable.

*italics* and _italics_

No whitespace as first nor as end char: correct:

*italics* test
*italics test*

wrong:

* italics* test

**bold** and __bold__

No whitespace as first nor as end char: see italics examples.

~~strikethrough~~

No whitespace as first nor as end char: see italics examples.

`inline-code`

Useful to send non Markdown text in your message, like source code snippets. Should get rendered in a monospace font and with a different background. In contrast to bold, italics and strike through the content of inline-code can contain spaces at beginning and ending.

``` fence code block ```

Similar to `inline-code` but not inline, and it may support code highlighting.

```[lang?] [content]``` A bit modified from the common syntax to allow one-liners. Also get displayed with a monospace font (a side effect of this is that it allows to display small ASCII art). The code highlighting is optional as implementation (time)cost may not be worth the small gain. The language definition should be parsed separately and omitted in this case.

If no language is set in the single line variant, the content must begin with a space: WRONG: ```hello world``` (because hello will be taken as language) RIGHT: ``` hello world```

see https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting

Parsing will remove trailing whitespaces and linebreaks at the end of the codeblock content.

<hello@delta.chat> - Delimited Email addresses

same format as normal email addresses enclosed in <>.

<http://example.org> - Delimited Link

same format as normal Links enclosed in <>.

URL parsing allows all valid URLs, no restrictions on schemes, no whitelist is needed, because the format already specifies that it is a link.

Labeled Links: [Name](url) links

When implementing this, make sure to show the user the hidden URL in a confirmation dialog to make scamming harder. Also show the URL as encode puny code to make puny code attacks useless. Optionally, a client can implement a system to trust a domain (a "don't ask again for links on this domain" checkbox in the confirmation dialog)

URL parsing allows all valid URLs, no restrictions on schemes, no whitelist is needed, because the format already specifies that it is a link.

The label can contain basic markdown elements (bold, italics), but no "complex" linkified elements such as hashtags, links and email addresses.

  • parsers that run for a label:
    • (desktop set): none
    • (markdown set): bold, italics, underline, code-inline
  • parsers that do not run for a label (just returned as part of Text element):
    • hashtag, email, link, labeled link, delimited email & link, codeblock, mentions (basically everything clickable)

Ideas For The Future:

:emoji:

  • ':' + [A-z0-9_-] + ':' ?
  • could also be used for custom DC emojis in the future

Mentions @username

Clickable. (could get replaced with a user hash/email/ID on send/on receive so that it's still valid on name change.)

On sending/receiving, this is transformed into an internal representation:

Implementation idea:

  1. user types @Displayname and at best gets autocompletion while typing the URL
  2. on sending, the username is converted to the transmission format (special format that contains the email address as ID)
  3. on receiving/storing the message inside the database, this format is converted again to contain the local contact ID to allow for future email address migration/rotation. (4.) on forwarding/sharing as chat history, the ID representation needs to be converted from the contact ID format to the transmission format again

see discords mention code for reference/inspiration https://blog.discordapp.com/how-discord-renders-rich-messages-on-the-android-app-67b0e5d56fbe

$[inline TeX]$ and $$[Tex displayed in block(new line)]$$

For sharing math/physics equations in LaTeX format. see https://support.delta.chat/t/latex-code-in-deltachat/558

Things that will NOT be supported:

  • Inline HTML
  • underline - can be confused with links