Namespaces in Ducktype fragments

Shaun McCance <shaunm at gnome.org>
Mon Feb 12 12:47:33 EST 2018

I recently landed a change in the Ducktype parser that allows you to
use it for "fragments", basically pieces of a page that don't start
with a page header. Check out the fragment*.duck test files here:

https://github.com/projectmallard/mallard-ducktype/tree/master/tests

With this, instead of starting with a "= Page", you can start with
either a "== Section" or "[block]". Recall that we can encode any XML
vocabulary in a page in Ducktype. With this feature, we can encode any
XML vocabulary as a standalone file. This is the note icon shipped in
yelp-xsl, in its entirety, in Ducktype, as a standalone file:

@namespace svg http://www.w3.org/2000/svg
[svg:svg height=24 width=24 version=1.1]
  [svg:g]
    [svg:path class=yelp-svg-fill
      d="m4 3h16c0.554 0 1 0.446 1 1v11h-6v6h-11c-0.554
         0-1-0.446-1-1v-16c0-0.554 0.446-1 1-1z"]

    [svg:path class=yelp-svg-fill
      d="m17 16h4l-5 5v-4c0-0.554 0.446-1 1-1z"]

The blank line is necessary to prevent block nesting. Alternatively,
use inline syntax to avoid the blank line:

@namespace svg http://www.w3.org/2000/svg
[svg:svg height=24 width=24 version=1.1]
  [svg:g]
    $svg:path[class=yelp-svg-fill
      d="m4 3h16c0.554 0 1 0.446 1 1v11h-6v6h-11c-0.554
         0-1-0.446-1-1v-16c0-0.554 0.446-1 1-1z"]
    $svg:path[class=yelp-svg-fill
      d="m17 16h4l-5 5v-4c0-0.554 0.446-1 1-1z"]

This works well as long as you use namespace prefixes, because the
default namespace is still the Mallard namespace. But what if we want
to change the default namespace to something else? And what if we want
to make the default namespace blank to allow unnamespaced vocabularies
like DITA? That's currently not possible.

Three proposals:

[-] Proposal #1
[-] Declare a URI as the default namespace
@namespace http://www.w3.org/2000/svg
[-] Declare that the default namespace is blank
@namespace

[-] Proposal #2
[-] Declare a URI as the default namespace
@namespace # http://www.w3.org/2000/svg
[-] Declare that the default namespace is blank
@namespace #

[-] Proposal #3
[-] Declare a URI as the default namespace
@default http://www.w3.org/2000/svg
[-] Declare that the default namespace is blank
@default

Proposal #1 involves less typing and fewer magic characters. Proposal
#2 feels a little more explicit, and might avoid accidental namespace
messups. Proposal #3 is much more explicit, but involves adding a new
directive name. "default" might be too generic of a name.

Thoughts?

--
Shaun