Skip to content

Commit

Permalink
Add [$] shorthand for abstract operations. Fixes #809.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Oct 23, 2017
1 parent 4d60baa commit 0dc246e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
13 changes: 13 additions & 0 deletions bikeshed/shorthands.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def transformText(text):
config.processTextNodes(nodes, propdescRe, propdescReplacer)
if "dfn" in doc.md.markupShorthands:
config.processTextNodes(nodes, dfnRe, dfnReplacer)
config.processTextNodes(nodes, abstractRe, abstractReplacer)
if "idl" in doc.md.markupShorthands:
config.processTextNodes(nodes, idlRe, idlReplacer)
if "markup" in doc.md.markupShorthands:
Expand Down Expand Up @@ -329,6 +330,18 @@ def dfnReplacer(match):
linkText = match.group(2)
return E.a({"data-link-type":"dfn", "for": linkFor, "lt":match.group(2)}, linkText)

abstractRe = re.compile(r"\[\$(?!\s)(?:([^$]*)/)?([^\"$]+?)(\|[^\"$]+)?\$\]")
def abstractReplacer(match):
if match.group(1) == "":
linkFor = "/"
else:
linkFor = match.group(1)
if match.group(3) is not None:
linkText = match.group(3)[1:]
else:
linkText = match.group(2)
return E.a({"data-link-type":"abstract-op", "for": linkFor, "lt":match.group(2)}, linkText)

elementRe = re.compile(r"<{(?P<element>[\w*-]+)(?:/(?P<attr>[\w*-]+)(?:/(?P<value>[^}!|]+))?)?(?:!!(?P<linkType>[\w-]+))?(?:\|(?P<linkText>[^}]+))?}>")
def elementReplacer(match):
groupdict = match.groupdict()
Expand Down
5 changes: 3 additions & 2 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ There are several additional optional keys:
* `algorithm`, covering the special <{var}> shorthand (the `|foo|` shorthand)
* `biblio`, covering the <a>autolink shorthands</a> for biblio links and section links (the `[[foo]]` shorthands)
* `css`, covering the <a>autolink shorthands</a> for CSS types
* `dfn`, covering the <a>autolink shorthand</a> for "dfn" type definitions
* `dfn`, covering the <a>autolink shorthand</a> for "dfn" and "abstract-op" type definitions
* `idl`, covering the <a>autolink shorthands</a> for WebIDL types (the `{{foo}}` shorthand)
* `markdown`, covering the various inline Markdown syntaxes (block-level Markdown is always supported)
* `markup`, covering the <a>autolink shorthands</a> for HTML/etc elements and attributes (the `<{foo}>` shorthand)
Expand Down Expand Up @@ -2026,7 +2026,8 @@ There are several additional <dfn lt="autolink shorthand">autolink shorthands</d

The Dfn variety (controlled by `Markup Shorthands: dfn yes`):

* `[=foo=]` is an autolink to the "dfn" type definition "foo".
* `[=foo=]` is an autolink to the "dfn"-type definition "foo".
* `[$foo$]` is an autolink to the "abstract-op"-type definition "foo".

The CSS varieties (controlled by `Markup Shorthands: css yes`):

Expand Down
10 changes: 6 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1176,9 +1176,9 @@
}
}
</style>
<meta content="Bikeshed version f4e0fcc7a3032c572d2a32517fa9c987d68b9a54" name="generator">
<meta content="Bikeshed version 4d60baa68c980aa9a48f0c7c0cba36bafee1f984" name="generator">
<link href="https://tabatkins.github.io/bikeshed/" rel="canonical">
<meta content="f4e0fcc7a3032c572d2a32517fa9c987d68b9a54" name="document-revision">
<meta content="4d60baa68c980aa9a48f0c7c0cba36bafee1f984" name="document-revision">
<style>/* style-md-lists */

/* This is a weird hack for me not yet following the commonmark spec
Expand Down Expand Up @@ -2432,7 +2432,7 @@ <h2 class="heading settled" data-level="4" id="metadata"><span class="secno">4.
<li data-md="">
<p><code>css</code>, covering the <a data-link-type="dfn" href="#autolink-shorthand" id="ref-for-autolink-shorthand①">autolink shorthands</a> for CSS types</p>
<li data-md="">
<p><code>dfn</code>, covering the <a data-link-type="dfn" href="#autolink-shorthand" id="ref-for-autolink-shorthand②">autolink shorthand</a> for "dfn" type definitions</p>
<p><code>dfn</code>, covering the <a data-link-type="dfn" href="#autolink-shorthand" id="ref-for-autolink-shorthand②">autolink shorthand</a> for "dfn" and "abstract-op" type definitions</p>
<li data-md="">
<p><code>idl</code>, covering the <a data-link-type="dfn" href="#autolink-shorthand" id="ref-for-autolink-shorthand③">autolink shorthands</a> for WebIDL types (the <code>{{foo}}</code> shorthand)</p>
<li data-md="">
Expand Down Expand Up @@ -3405,7 +3405,9 @@ <h2 class="heading settled" data-level="7" id="autolinking"><span class="secno">
<p>The Dfn variety (controlled by <code>Markup Shorthands: dfn yes</code>):</p>
<ul>
<li data-md="">
<p><code>[=foo=]</code> is an autolink to the "dfn" type definition "foo".</p>
<p><code>[=foo=]</code> is an autolink to the "dfn"-type definition "foo".</p>
<li data-md="">
<p><code>[$foo$]</code> is an autolink to the "abstract-op"-type definition "foo".</p>
</ul>
<p>The CSS varieties (controlled by <code>Markup Shorthands: css yes</code>):</p>
<ul>
Expand Down

0 comments on commit 0dc246e

Please sign in to comment.