%ents; ]>
Message Styling This specification defines a formatted text syntax for use in instant messages with simple text styling. &LEGALNOTICE; 0393 Draft 2020-05-26 Standards Track Standards Council XMPP Core XEP-0001 XEP-0071 styling &sam; 1.1.0 2021-01-12 sw

Clarify parsing rules for span directives

1.0.0 2020-10-13 XEP Editor (jsc)

Accepted as Draft as per Council vote from 2020-10-07.

0.4.0 2020-06-02 ssw

Remove description of mechanism for disabling styling on individual spans and blocks, users can do this themselves without us documenting the use of a codepoint that's not specifically for this purpose.

0.3.0 2020-06-02 ssw

Add ability to disable styling, further clarify accessibility considerations, and mention that Styling is not Markdown in the security considerations section.

0.2.2 2020-05-20 ssw

Clarify accessibility considerations section and be consistent about use of the term "styling directives".

0.2.1 2020-01-02 ssw

Make rules consistent with examples that show multiple styling directives being applied to the same text.

0.2.0 2019-09-02 ssw

Clarify block quote termination and white space trimming.

0.1.4 2018-05-01 ssw

Clarify language around strong emphasis.

0.1.3 2018-02-14 ssw

Reorder block and span sections, simplify block parsing, and update the definition of a span.

0.1.2 2018-01-13 ssw

Clarify block quote and plain text parsing and formatting behavior.

0.1.1 2018-01-12 ssw

Minor clarifications and updates, add security considerations, and expand the glossary.

0.1.0 2017-11-22 XEP Editor (ssw)

First draft approved by the XMPP Council.

0.0.1 2017-10-28 ssw

First draft.

Historically, XMPP has had no system for simple text styling. Instead, specifications like &xep0071; that require full layout engines have been used, leading to numerous security issues with implementations. Some entities have also performed their own styling based on identifiers in the body. While this has worked well in the past, it is not interoperable and leads to entities each supporting their own informal styling languages.

This specification aims to provide a single, interoperable formatted text syntax that can be used by entities that do not require full layout engines.

Many important terms used in this document are defined in &unicode;. The terms "left-to-right" (LTR) and "right-to-left" (RTL) are defined in &uax9;. The term "formatted text" is defined in &rfc7764;.

Block
Any chunk of text that can be parsed unambiguously in one pass. Blocks may contain one or more children which may be other blocks or spans. For example:
  • A single line of text comprising one or more spans
  • A block quotation
  • A preformatted code block
Formal markup language
A structured markup language such as LaTeX, SGML, HTML, or XML that is formally defined and may include metadata unrelated to formatting or text style.
Plain text
Text that does not convey any particular formatting or interpretation of the text by computer programs.
Span
A group of text that may be rendered inline alongside other spans. Spans may be either plain text with no formatting applied, or may be formatted text that is enclosed by two styling directives. Spans are always children of blocks and may not escape from their containing block. Some spans may contain child spans. The following all contain spans marked by parenthesis:
  • (plain span)
  • (*strong span*)
  • (_emphasized span_)
  • (_emphasized span containing (*strong span*)_)
  • (span one )(*span two*)
Styling directive
A character or set of characters that indicates the beginning of a span or block. For example, in certain contexts the characters '*' (U+002A ASTERISK), and '_' (U+005F LOW LINE) may be styling directives that indicate the beginning of a strong or emphasis span and the string '```' (U+0060 GRAVE ACCENT) may be a styling directive that indicate the beginning of a preformatted code block.
Whitespace character
Any Unicode scalar value which has the property "White_Space" or is in category Z in the Unicode Character Database.

Clients that support message styling MUST advertise the fact by including a feature of "urn::xmpp:styling:0" in response to &xep0030; information requests and in their &xep0115; profiles.

… ]]>

Parsers implementing message styling will first parse blocks and then parse child blocks or spans if allowed by the specific block type.

Individual lines of text that are not inside of a preformatted text block are considered a "plain" block. Plain blocks are not bound by styling directives and do not imply formatting themselves, but they may contain spans which imply formatting. Plain blocks may not contain child blocks.

(There are three blocks in this body marked by parens,) (but there is no *formatting) (as spans* may not escape blocks.) ]]>

A preformatted text block is started by a line beginning with "```" (U+0060 GRAVE ACCENT), and ended by a line containing only three grave accents or the end of the parent block (whichever comes first). Preformatted text blocks cannot contain child blocks or spans. Text inside a preformatted block SHOULD be displayed in a monospace font.

```ignored (println "Hello, world!") ``` This should show up as monospace, preformatted text ⤴ ]]> > ``` > (println "Hello, world!") The entire blockquote is a preformatted text block, but this line is plaintext! ]]>

A quotation is indicated by one or more lines with a byte stream beginning with a '>' (U+003E GREATER-THAN SIGN). They are terminated by the first new line that is not followed by a greater-than sign, or the end of the parent block (whichever comes first). Block quotes may contain any child block, including other quotations. Lines inside the block quote MUST have the first leading whitespace character trimmed before parsing the child block. It is RECOMMENDED that text inside of a block quote be indented or distinguished from the surrounding text in some other way.

> That that is, is. Said the old hermit of Prague. ]]> >> That that is, is. > Said the old hermit of Prague. Who? ]]>

Matches of spans between two styling directives MUST contain some text between the two styling directives, otherwise neither directive is valid. The opening styling directive MUST be located at the beginning of the line, after a whitespace character, or after a different opening styling directive. The opening styling directive MUST NOT be followed by a whitespace character and the closing styling directive MUST NOT be preceeded by a whitespace character. Spans are always parsed from the beginning of the byte stream to the end and are lazily matched. Characters that would be styling directives but do not follow these rules are not considered when matching and thus may be present between two other styling directives.

For example, each of the following would be styled as indicated:

  • *strong*
  • plain *strong* plain
  • *strong* plain *strong*
  • *strong*plain*
  • * plain *strong*

Nothing would be styled in the following messages (where "\n" represents a new line):

  • not strong*
  • *not strong
  • *not \n strong*
  • *not *strong
  • **
  • ***
  • ****

Any text inside of a block that is not part of another span is implicitly considered to be inside of a "plain text" span.

(Two spans, both )(*alike in dignity*) ]]>

Text enclosed by '_' (U+005F LOW LINE) is emphasized and SHOULD be displayed in italics.

The full title is _Twelfth Night, or What You Will_ but _most_ people shorten it. ]]>

Text enclosed by '*' (U+002A ASTERISK) is strongly emphasized and SHOULD be displayed with a heavier font weight than the surrounding text (bold).

The full title is "Twelfth Night, or What You Will" but *most* people shorten it. ]]>

Text enclosed by '~' (U+007E TILDE) SHOULD be displayed with a horizontal line through the middle.

Everyone ~dis~likes cake. ]]>

Text enclosed by a '`' (U+0060 GRAVE ACCENT) is a preformatted span SHOULD be displayed inline in a monospace font. A preformatted span may only contain a single plain span. Inline formatting directives inside the preformatted span are not rendered. For example, the following all contain valid preformatted spans:

  • This is `monospace`
  • This is `*monospace*`
  • This is *`monospace and bold`*
Wow, I can write in `monospace`! ]]>

On rare occasions styling hints may conflict with the contents of a message. For example, if the user sends the emoji "> _ <" it would be interpreted as a block quote. Senders may indicate to the receiver that a particular message SHOULD NOT be styled by adding an empty <unstyled> element qualified by the "urn:xmpp:styling:0" namespace.

> _ < ]]>

This document does not define a regular grammar and thus styling cannot be matched by a regular expression. Instead, a simple parser can be constructed by first parsing all text into blocks and then recursively parsing the child-blocks inside block quotations, the spans inside individual lines, and by returning the text inside preformatted blocks without modification.

It is RECOMMENDED that styling directives be displayed and formatted in the same manner as the text they apply to. For example, the string "*emphasis*" would be rendered as "*emphasis*".

This specification does not provide a mechanism for removing styling from individual spans or blocks within a styled message. Implementations are free to implement their own workarounds, for example by inserting Unicode non-printable characters to invalidate styling directives, but no specific technique is known to be widely supported.

When displaying styling directives, developers should ensure sufficient contrast so that visually impaired users are able to distinguish the styling directives from the background color. Care should also be taken to ensure that formatting designed to differentiate styling directives from surrounding text does not make the text more difficult to read for visually impaired users.

Styled text may be rendered poorly by screen readers. When applying formatting it may be desirable to include directives to exclude styling directives from being read, or to add markers to the final output that have semantic meaning for screen readers. For example, in an web based client an emphasis span might be converted to an HTML <em> element.

Authors of message styling parsers should take care that improperly formatted messages cannot lead to buffer overruns or code execution.

Though message styling is not compatible with Markdown, some of its styles are similar. Markdown parsers often allow arbitrary HTML to be inserted into documents and therefore MUST NOT be used to parse the format defined in this document even if they are flexible enough to do so.

This document requires no interaction with &IANA;.

This specification defines the following XML namespace:

  • urn:xmpp:styling:0

Upon advancement of this specification from a status of Experimental to a status of Draft, the ®ISTRAR; shall add the foregoing namespace to the registries located at &DISCOFEATURES;, as described in Section 4 of &xep0053;.

urn:xmpp:styling:0 Support for rendering message styling. &xep0393; ]]>

The ®ISTRAR; shall also add the foregoing namespace to the Jabber/XMPP Protocol Namespaces Registry located at &NAMESPACES;. Upon advancement of this specification from a status of Experimental to a status of Draft, the ®ISTRAR; shall remove the provisional status from this registry entry.

urn:xmpp:styling:0 &xep0393; provisional ]]>
&NSVER;

This document does not define any new XML structure requiring a schema.

The author wishes to thank Kevin Smith for his review and feedback.