Skip to content

Commit

Permalink
Basic support for adding a tracking-vector icon!
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Oct 31, 2019
1 parent 3a83dd4 commit f5a6d58
Show file tree
Hide file tree
Showing 15 changed files with 1,310 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bikeshed/Spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import config
from . import datablocks
from . import extensions
from . import fingerprinting
from . import headings
from . import highlight
from . import HTMLSerializer
Expand Down Expand Up @@ -215,6 +216,7 @@ def processDocument(self):
boilerplate.removeUnwantedBoilerplate(self)
highlight.addSyntaxHighlighting(self)
boilerplate.addBikeshedBoilerplate(self)
fingerprinting.addFingerprinting(self)
fixIntraDocumentReferences(self)
fixInterDocumentReferences(self)
removeMultipleLinks(self)
Expand Down
41 changes: 41 additions & 0 deletions bikeshed/fingerprinting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from __future__ import division, unicode_literals

from .htmlhelpers import *

fingerprintId = "b732b3fe" # hashlib.md5("tracking-vector").hexdigest()[0:8], to minimize chance of collision

def addFingerprinting(doc):
if doc.md.fingerprintClass is None:
return

els = findAll(".{0}".format(doc.md.fingerprintClass), doc)

if len(els) == 0:
return

if doc.md.fingerprintImage is None:
# Generate an SVG and <use> it in all the individual spots
appendChild(doc.body,
E.svg({"viewBox":"0 0 46 64", "style":"display:none"},
E.defs({},
E.path({"id":fingerprintId,
"stroke":"black",
"stroke-linecap":"round",
"stroke-linejoin":"round",
"stroke-dasharray":"3,2,35,2,20,2",
"fill":"none",
"d":"M2 23Q17 -16 40 12M1 35Q17 -20 43 20M2 40Q18 -19 44 25M3 43Q19 -16 45 29M5 46Q20 -12 45 32M5 49Q11 40 15 27T27 16T45 37M5 49Q15 38 19 25T34 27T44 41M6 52Q17 40 21 28T32 29T43 44M6 52Q21 42 23 31T30 32T42 47M7 54Q23 47 24 36T28 34T41 50M8 56Q26 50 26 35Q28 48 40 53M10 58Q24 54 27 45Q30 52 38 55M27 50Q28 53 36 57M25 52Q28 56 31 57M22 55L26 57M10 58L37 57M13 60L32 60M16 62L28 63"}))))

for el in els:
prependChild(el,
fingerprintImage(doc.md.fingerprintImage, doc.md.fingerprintTitle))


def fingerprintImage(url, title):
if url is None:
return E.svg({"width":"46", "height":"64", "role":"img"},
E.title({}, title),
E.use({"href":"#"+fingerprintId}))
else:
return E.img({"title":title, "alt":title, "src":url})
12 changes: 12 additions & 0 deletions bikeshed/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def __init__(self):
self.editors = []
self.editorTerm = {"singular": "Editor", "plural": "Editors"}
self.favicon = None
self.fingerprintClass = "tracking-vector"
self.fingerprintImage = None
self.fingerprintTitle = "There is a potential fingerprinting vector here."
self.forceCrossorigin = False
self.group = None
self.h1 = None
Expand Down Expand Up @@ -933,6 +936,12 @@ def parseLiteral(key, val, lineNum):
return val


def parseLiteralOrNone(key, val, lineNum):
if val.lower() == "none":
return None
return val


def parseLiteralCaseless(key, val, lineNum):
return val.lower()

Expand Down Expand Up @@ -964,6 +973,9 @@ def parseLiteralList(key, val, lineNum):
"Editor": Metadata("Editor", "editors", joinList, parseEditor),
"Editor Term": Metadata("Editor Term", "editorTerm", joinValue, parseEditorTerm),
"Favicon": Metadata("Favicon", "favicon", joinValue, parseLiteral),
"Fingerprint Class": Metadata("Fingerprint Class", "fingerprintClass", joinValue, parseLiteralOrNone),
"Fingerprint Image": Metadata("Fingerprint Image", "fingerprintImage", joinValue, parseLiteralOrNone),
"Fingerprint Title": Metadata("Fingerprint Title", "fingerprintTitle", joinValue, parseLiteral),
"Force Crossorigin": Metadata("Force Crossorigin", "forceCrossorigin", joinValue, parseBoolean),
"Former Editor": Metadata("Former Editor", "previousEditors", joinList, parseEditor),
"Group": Metadata("Group", "group", joinValue, parseLiteral),
Expand Down
17 changes: 17 additions & 0 deletions tests/fingerprint001.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<pre class=metadata>
Title: Foo
Group: test
Shortname: foo
Level: 1
Status: LS
ED: http://example.com/foo
Abstract: Testing basic support for tracking-vector.
Editor: Example Editor
Date: 1970-01-01
</pre>

Here's some text.

<p class=tracking-vector>Some more text that fingerprints!

And then some more after that.
194 changes: 194 additions & 0 deletions tests/fingerprint001.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<!doctype html><html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<title>Foo</title>
<link href="http://example.com/foo" rel="canonical">
<style>/* style-md-lists */

/* This is a weird hack for me not yet following the commonmark spec
regarding paragraph and lists. */
[data-md] > :first-child {
margin-top: 0;
}
[data-md] > :last-child {
margin-bottom: 0;
}</style>
<style>/* style-counters */

body {
counter-reset: example figure issue;
}
.issue {
counter-increment: issue;
}
.issue:not(.no-marker)::before {
content: "Issue " counter(issue);
}

.example {
counter-increment: example;
}
.example:not(.no-marker)::before {
content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
content: "Invalid Example" counter(example);
}

figcaption {
counter-increment: figure;
}
figcaption:not(.no-marker)::before {
content: "Figure " counter(figure) " ";
}</style>
<style>/* style-selflinks */

.heading, .issue, .note, .example, li, dt {
position: relative;
}
a.self-link {
position: absolute;
top: 0;
left: calc(-1 * (3.5rem - 26px));
width: calc(3.5rem - 26px);
height: 2em;
text-align: center;
border: none;
transition: opacity .2s;
opacity: .5;
}
a.self-link:hover {
opacity: 1;
}
.heading > a.self-link {
font-size: 83%;
}
li > a.self-link {
left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
top: auto;
left: auto;
opacity: 0;
width: 1.5em;
height: 1.5em;
background: gray;
color: white;
font-style: normal;
transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
opacity: 1;
}
dfn > a.self-link:hover {
color: black;
}

a.self-link::before { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before { content: "#"; }</style>
<style>/* style-autolinks */

.css.css, .property.property, .descriptor.descriptor {
color: #005a9c;
font-size: inherit;
font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
content: "‘";
}
.css::after, .property::after, .descriptor::after {
content: "’";
}
.property, .descriptor {
/* Don't wrap property and descriptor names */
white-space: nowrap;
}
.type { /* CSS value <type> */
font-style: italic;
}
pre .property::before, pre .property::after {
content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
content: "’";
}

[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
content: "";
}

[data-link-type=element],
[data-link-type=element-attr] {
font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after { content: ">" }

[data-link-type=biblio] {
white-space: pre;
}</style>
<body class="h-entry">
<div class="head">
<p data-fill-with="logo"></p>
<h1 class="p-name no-ref" id="title">Foo</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard, <time class="dt-updated" datetime="1970-01-01">1 January 1970</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
<dd><a class="u-url" href="http://example.com/foo">http://example.com/foo</a>
<dt class="editor">Editor:
<dd class="editor p-author h-card vcard"><span class="p-name fn">Example Editor</span>
</dl>
</div>
<div data-fill-with="warning"></div>
<p class="copyright" data-fill-with="copyright">COPYRIGHT GOES HERE </p>
<hr title="Separator for header">
</div>
<div class="p-summary" data-fill-with="abstract">
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
<p>Testing basic support for tracking-vector.</p>
</div>
<div data-fill-with="at-risk"></div>
<nav data-fill-with="table-of-contents" id="toc">
<h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
</nav>
<main>
<p>Here’s some text.</p>
<p class="tracking-vector">
<svg height="64" role="img" width="46">
<title>There is a potential fingerprinting vector here.</title>
<use href="#b732b3fe"></use>
</svg>
Some more text that fingerprints!
</p>
<p>And then some more after that.</p>
</main>
<svg style="display:none" viewBox="0 0 46 64">
<defs>
<path d="M2 23Q17 -16 40 12M1 35Q17 -20 43 20M2 40Q18 -19 44 25M3 43Q19 -16 45 29M5 46Q20 -12 45 32M5 49Q11 40 15 27T27 16T45 37M5 49Q15 38 19 25T34 27T44 41M6 52Q17 40 21 28T32 29T43 44M6 52Q21 42 23 31T30 32T42 47M7 54Q23 47 24 36T28 34T41 50M8 56Q26 50 26 35Q28 48 40 53M10 58Q24 54 27 45Q30 52 38 55M27 50Q28 53 36 57M25 52Q28 56 31 57M22 55L26 57M10 58L37 57M13 60L32 60M16 62L28 63" fill="none" id="b732b3fe" stroke="black" stroke-dasharray="3,2,35,2,20,2" stroke-linecap="round" stroke-linejoin="round"></path>
</defs>
</svg>
20 changes: 20 additions & 0 deletions tests/fingerprint002.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<pre class=metadata>
Title: Foo
Group: test
Shortname: foo
Level: 1
Status: LS
ED: http://example.com/foo
Abstract: Testing that 'Fingerprint Class: None' turns it off.
Fingerprint Class: none
Editor: Example Editor
Date: 1970-01-01
</pre>

Here's some text.

<p class=tracking-vector>Some more text that shouldn't show anything!

<p class=none>Even more text that shouldn't show anything.

And then some more after that.
Loading

0 comments on commit f5a6d58

Please sign in to comment.