Skip to content

Instantly share code, notes, and snippets.

@tabatkins
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabatkins/b9b07594dbcde338fd86 to your computer and use it in GitHub Desktop.
Save tabatkins/b9b07594dbcde338fd86 to your computer and use it in GitHub Desktop.
Comparing two linking syntaxes
[
{
"linkingText": "blob",
"url": "http://dev.w3.org/2006/webapi/FileAPI/#blob",
"type": "dfn"
},
{
"linkingText": "blob url store",
"url": "http://dev.w3.org/2006/webapi/FileAPI/#BlobURLStore",
"type": "dfn"
},
{
"linkingText": "baseURI",
"for": ["Node"],
"url": "https://dom.spec.whatwg.org/#dom-node-baseuri",
"type": "attribute"
},
{
"linkingText": "EventSource",
"url": "https://html.spec.whatwg.org/multipage/comms.html#eventsource",
"type": "interface"
},
{
"linkingText": "hashchangeevent",
"url": "https://html.spec.whatwg.org/multipage/comms.html#hashchangeevent",
"type": "interface"
},
{
"linkingText": "structured clone",
"url": "https://html.spec.whatwg.org/multipage/infrastructure.html#structured-clone",
"type": "dfn"
},
{
"linkingText": "toascii",
"url": "http://www.unicode.org/reports/tr46/#ToASCII",
"type": "dfn"
},
{
"linkingText": "tounicode",
"url": "http://www.unicode.org/reports/tr46/#ToUnicode",
"type": "dfn"
},
{
"linkingText": "unicode serialization of an origin",
"url": "https://html.spec.whatwg.org/multipage/browsers.html#unicode-serialisation-of-an-origin",
"type": "dfn"
},
{
"linkingText": {
"attribute value":"#concept-attribute-value",
"document":"#concept-document",
"context object":"#context-object"
},
"url": "https://dom.spec.whatwg.org/",
"type": "dfn"
},
{
"linkingText": ["value pairs to iterate over", "throw"],
"url": "http://heycam.github.io/webidl/#dfn-",
"type": "dfn"
},
{
"linkingText": ["utf-8", "utf-8 decode without bom", "utf-8 encode", "utf-8 decoder", "encoding", "error", "decoder", "concept-encoding-get", "ascii whitespace"],
"url": "https://encoding.spec.whatwg.org/#",
"type": "dfn"
}
]
type: dfn; urlPrefix: http://dev.w3.org/2006/webapi/FileAPI/
text: blob
text: blob url store; url: #BlobURLStore
urlPrefix: https://dom.spec.whatwg.org/
type: attribute; for: Node; text: baseURI; url: #dom-node-baseuri
type: dfn
text: attribute value; url: #concept-attribute-value
text: document; url: #concept-document
text: context object; url: #content-object
type: dfn; urlPrefix: http://heycam.github.io/webidl/#dfn-
text: values pairs to iterate over
text: throw
type: dfn; urlPrefix: https://encoding.spec.whatwg.org/
text: utf-8
text: utf-8 decode without bom
text: utf-8 encode
text: utf-8 decoder
text: encoding
text: error
text: decoder
text: concept-encoding-get
text: ascii whitespace
urlPrefix: https://html.spec.whatwg.org/multipage/
type: interface; urlPrefix: comms.html
text: EventSource
text: HashChangeEvent
type: dfn;
urlPrefix: infrastructure.html; text: structured clone
urlPrefix: browsers.html; text: unicode serialization of an origin
type: dfn; text: toascii; url: http://www.unicode.org/reports/tr46/#ToASCII
type: dfn; text: tounicode; url: http://www.unicode.org/reports/tr46/#ToUnicode

These two syntaxes should express the exact same set of Bikeshed anchors. The first is simple JSON, the second is a custom nesting syntax.

Some notes on the second:

  • Anchors are defined by the leaf nodes, accumulating values from the path down. You can express any anchor purely through nesting, but when the nesting doesn't add anything, you can collapse values into a single line with a semicolon separating them.
  • The urlPrefix key is accumulative; if multiple are encountered as you descend the nesting, they concatenate. The final url key is then concatenated to the accumulated urlPrefix.
  • If there is no url key, one is generated from the text key by doing standard IDification. If the urlPrefix doesn't contain a # character, one is inserted between the prefix and the generated ID.
  • Each anchor must contain a type, a text, and one or both of urlPrefix and url. It may contain a for.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment