Ducktype Conditionals 1.0 DRAFT

This is a draft specification. It is likely that changes will still be made before the final specification.

The Ducktype Conditionals extension provides a shorthand syntax for Mallard Conditionals. Mallard Conditionals can be used in Ducktype without any extension simply by declaring the namespace and using the elements and attributes as normal. Ducktype Condititionals provide a simpler alternate syntax that doesn't require namespaced elements.

Notes

  • Use Ducktype Conditionals 1.0 by adding if/1.0 to the Ducktype directive.

  • Ducktype Conditionals automatically binds the if namespace prefix to http://projectmallard.org/if/1.0/.

  • A single leading question mark and a space creates:

    • An if:when element in an if:choose element.

    • Otherwise, an if:if element.

  • The text after the space after a single leading question mark is taken as the content of the test attribute.

  • Two question marks on an otherwise empty line creates:

    • An if:else element in an if:choose element.

    • Otherwise, an if:choose element.

Examples

The following examples show text using the Ducktype Conditionals extension, followed by the equivalent snippet in Ducktype using Mallard Conditionals with namespaces.

Wrap a single paragraph in a conditional:

@ducktype/1.0 if/1.0
= Conditional Example

? target:html
  This is only displayed when converting to HTML.
@ducktype/1.0
@namespace if http://projectmallard.org/if/1.0/
= Conditional Example

[if:if test=target:html]
  This is only displayed when converting to HTML.

Put any number of any block elements in a conditional:

@ducktype/1.0 if/1.0
= Conditional Example

? target:html
  This is only displayed when converting to HTML.

  [note]
    This note is also in the conditional with this list:
    * one
    * two
@ducktype/1.0
@namespace if http://projectmallard.org/if/1.0/
= Conditional Example

[if:if test=target:html]
  This is only displayed when converting to HTML.

  [note]
    This note is also in the conditional with this list:
    * one
    * two

Provide multiple conditions with branching and fallback:

@ducktype/1.0 if/1.0
= Conditional Example

??
  ? platform:fedora platform:centos platform:rhel
    This is only displayed on Fedora, CentOS, and RHEL.
  ? platform:ubuntu
    This is only displayed on Ubuntu.
  ??
    This is displayed on all other platforms.
@ducktype/1.0
@namespace if http://projectmallard.org/if/1.0/
= Conditional Example

[if:choose]
  [if:when test="platform:fedora platform:centos platform:rhel"]
    This is only displayed on Fedora, CentOS, and RHEL.
  [if:when test="platform:ubuntu"]
    This is only displayed on Ubuntu.
  [if:else]
    This is displayed on all other platforms.

Do something:

@ducktype/1.0 if/1.0
= Conditional Example

[steps]
* First step
[item if:test=platform:gnome-classic]
  Extra step only displayed for GNOME Classic.
* Last step
@ducktype/1.0
@namespace if http://projectmallard.org/if/1.0/
= Conditional Example

[steps]
* First step
[item if:test=platform:gnome-classic]
  Extra step only displayed for GNOME Classic.
* Last step

Specification

Ducktype Conditionals 1.0 recognizes the token if/1.0 in the Ducktype declaration.

When Ducktype Conditionals is used, it binds the prefix if to the namespace http://projectmallard.org/if/1.0/, as if it were declared with a namespace directive. This prefix may be overridden by a namespace directive in the document.

Ducktype Conditionals adds special block syntax. It recognizes two special types of lines:

  • A line starting with potentially leading indentation, one question mark (U+003F), and a space.

  • A line starting with potentially leading indentation, then just two question marks.

If an indented line starts with a single question mark and a space, then it is either shorthand for if:if or if:when, as follows:

  • If the current element is an if:choose, then the line is an if:when.

  • Otherwise, the line is an if:if.

In either case, the remainder of the line after the space is taken as a test expression. This test expression is added as a test attribute to either the if:if or if:when element.

If an indented line contains only two question marks, possibly followed by only space characters, then it is either shorthand for if:choose or if:else, as follows:

  • If the current element is an if:choose, then the line is an if:else.

  • Otherwise, the line is an if:choose.

There may be space characters after the two question marks, but there must not be any other content on the line. If there is other content, the line is not special syntax under this extension, and it is parsed as it would be without Ducktype Conditionals.

© 2019 Shaun McCance
Powered by
Mallard