Overview¶
This draft tries to specify CNM content selectors: query strings that identify specific sections in a CNM document.
Syntax¶
The CNM content selector is usually present in the hash fragment of a URL or in the select=cnm:
parameter of CNP selectors.
The syntax of the selector is one of the following:
/{section_path}
#{section_title}
${section_index_path}
!/{section_path}
!#{section_title}
!${section_index_path}
{section_path}
is a slash-separated path of percent-encoded section titles in the document hierarchy from the content
block to the target section. If the parent section of the target has multiple child sections with the same title, the first one is selected.
{section_title}
is a precent-encoded title of an individual section anywhere in the document. This selects the first section with this title.
{section_index_path}
is a dot-separated path of section indexes, with the first section in the given parent section or the content
block having the index 1
.
When any of the three above selectors are empty, the entire content
block is selected.
When selecting content (as with a CNP selector) rather than just the start of a section (like with a page anchor in the hash fragment of the URL), a standard selector selects the section, all its parents without their siblings and the entire content of the section. If the selector is prefixed with !
(shallow selector), all contents of child sections of the selected block are also omitted. The !
selector prefix is only valid when selecting content.
An empty selector selects the entire document, including non-content
top-level blocks (an identity mapping of the document), with the anchor selecting the top of the document. An empty !
shallow selector selects the top-level document and content block, including section name lines, but omits the contents of all sections.
With the following document:
title
Test
content
section Foo
section Bar
section Baz
text
Test 1
section Quux
text
Test 2
section Bar
text
Test 3
text
Test 4
section Quux
text
Test 5
section Bar
text
Test 6
text
Test 7
The following selectors select the section Bar
containing the section Baz
and text
containing Test 4
:
/Foo/Bar
#Bar
$1.1
The following selectors select the section Bar
containing Test 3
:
/Foo/Bar/Baz/Bar
$1.1.1.2
And only the following selector selects the Bar
with Test 6
:
$1.3
The following selector selects the Quux
section containing Test 2
and not the one containing Test 5
:
#Quux
The content selector /Foo/Bar/Baz
selects the following content:
content
section Foo
section Bar
section Baz
text
Test 1
section Quux
text
Test 2
section Bar
text
Test 3
And the shallow content selector !/Foo/Bar/Baz
selects the following:
content
section Foo
section Bar
section Baz
text
Test 1
section Quux
section Bar
An empty selector selects the entire document unchanged. An empty shallow selector !
selects the following:
title
Test
content
section Foo
text
Test 7
An example URL that includes a CNM selector as an anchor is cnp://example.com/file.cnm##Bar
for the section title selector #Bar
.
Content selectors are used in the CNP selector draft.
Functionality¶
CNM selectors can be used for any task where semantically selecting a section is required.
For example, browsers may use CNM selectors to provide anchors within a document and scroll to the appropriate sections when used.
CNM selectors can be used to retrieve only a specific subtree of blocks and their parents without siblings within a document's content
block using CNP cnm
selector.
Possible changes¶
Add the ability to choose N-th section with a specific name in section title path and section title selectors.
Add selectors for non-sections (less semantic?).