Skip to content

Commit

Permalink
Add Tracking Vector Text metadata
Browse files Browse the repository at this point in the history
And align with defaults used in whatwg/wattsi#41.
  • Loading branch information
annevk committed Jan 7, 2020
1 parent 183d4d2 commit a5c92aa
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
9 changes: 4 additions & 5 deletions bikeshed/fingerprinting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ def addTrackingVector(doc):

for el in els:
prependChild(el,
trackingVectorImage(doc.md.trackingVectorImage, doc.md.trackingVectorTitle, doc.md.trackingVectorClass))
trackingVectorImage(doc.md.trackingVectorImage, doc.md.trackingVectorText, doc.md.trackingVectorTitle, doc.md.trackingVectorClass))
removeAttr(el, "tracking-vector")


def trackingVectorImage(url, title, cls):
def trackingVectorImage(url, text, title, cls):
if url is None:
return E.svg({"width":"46", "height":"64", "role":"img", "class": cls},
return E.svg({"width":"46", "height":"64", "role":"img", "aria-label":text, "class":cls},
E.title({}, title),
E.use({"href":"#"+trackingVectorId}))
else:
return E.img({"title":title, "alt":title, "src":url, "class": cls})
return E.img({"title":title, "alt":text, "src":url, "class":cls})
4 changes: 3 additions & 1 deletion bikeshed/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def __init__(self):
self.favicon = None
self.trackingVectorClass = "tracking-vector"
self.trackingVectorImage = None
self.trackingVectorTitle = "There is a potential tracking vector here."
self.trackingVectorText = "(This is a tracking vector.) " # The space is to separate from the following text.
self.trackingVectorTitle = "There is a tracking vector here."
self.forceCrossorigin = False
self.group = None
self.h1 = None
Expand Down Expand Up @@ -1022,6 +1023,7 @@ def parseLiteralList(key, val, lineNum):
"TR": Metadata("TR", "TR", joinValue, parseLiteral),
"Tracking Vector Class": Metadata("Tracking Vector Class", "trackingVectorClass", joinValue, parseLiteralOrNone),
"Tracking Vector Image": Metadata("Tracking Vector Image", "trackingVectorImage", joinValue, parseLiteralOrNone),
"Tracking Vector Text": Metadata("Tracking Vector Text", "trackingVectorText", joinValue, parseLiteral),
"Tracking Vector Title": Metadata("Tracking Vector Title", "trackingVectorTitle", joinValue, parseLiteral),
"Translate Ids": Metadata("Translate Ids", "translateIDs", joinDdList, parseTranslateIDs),
"Translation": Metadata("Translation", "translations", joinList, parseTranslation),
Expand Down
8 changes: 4 additions & 4 deletions tests/fingerprint001.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<main>
<p>Here’s some text.</p>
<p>
<svg class="tracking-vector" height="64" role="img" width="46">
<title>There is a potential tracking vector here.</title>
<svg aria-label="(This is a tracking vector.) " class="tracking-vector" height="64" role="img" width="46">
<title>There is a tracking vector here.</title>
<use href="#b732b3fe"></use>
</svg>
Some more text that fingerprints!
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>
</svg>
4 changes: 2 additions & 2 deletions tests/fingerprint003.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Shortname: foo
Level: 1
Status: LS
ED: http://example.com/foo
Abstract: Testing that 'Fingerprint Class: foo' works.
Abstract: Testing that 'Tracking Vector Class: foo' works.
Tracking Vector Class: foo
Editor: Example Editor
Date: 1970-01-01
</pre>

Here's some text.

<p tracking-vector>Some text that fingerprints.
<p tracking-vector>Some text that tracks.

And then some more after that.
10 changes: 5 additions & 5 deletions tests/fingerprint003.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ <h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="cont
</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 that 'Fingerprint Class: foo' works.</p>
<p>Testing that 'Tracking Vector Class: foo' works.</p>
</div>
<div data-fill-with="at-risk"></div>
<nav data-fill-with="table-of-contents" id="toc">
Expand All @@ -179,16 +179,16 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<main>
<p>Here’s some text.</p>
<p>
<svg class="foo" height="64" role="img" width="46">
<title>There is a potential tracking vector here.</title>
<svg aria-label="(This is a tracking vector.) " class="foo" height="64" role="img" width="46">
<title>There is a tracking vector here.</title>
<use href="#b732b3fe"></use>
</svg>
Some text that fingerprints.
Some text that tracks.
</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>
</svg>
4 changes: 2 additions & 2 deletions tests/fingerprint004.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
</nav>
<main>
<p>Here’s some text.</p>
<p><img alt="There is a potential tracking vector here." class="tracking-vector" src="https://xanthir.com/pony" title="There is a potential tracking vector here.">Some text that fingerprints! </p>
<p><img alt="(This is a tracking vector.) " class="tracking-vector" src="https://xanthir.com/pony" title="There is a tracking vector here.">Some text that fingerprints! </p>
<p>And then some more after that.</p>
</main>
</main>
6 changes: 3 additions & 3 deletions tests/fingerprint005.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<main>
<p>Here’s some text.</p>
<p>
<svg class="tracking-vector" height="64" role="img" width="46">
<svg aria-label="(This is a tracking vector.) " class="tracking-vector" height="64" role="img" width="46">
<title>There is a potential tracking vector here.</title>
<use href="#b732b3fe"></use>
</svg>
Some text that fingerprints!
Some 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>
</svg>
6 changes: 3 additions & 3 deletions tests/fingerprint006.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<main>
<p>Here’s some text.</p>
<p>
<svg class="tracking-vector" height="64" role="img" width="46">
<svg aria-label="(This is a tracking vector.) " class="tracking-vector" height="64" role="img" width="46">
<title>A custom Tracking Vector title, &lt;script>alert("xss")&lt;/script>.</title>
<use href="#b732b3fe"></use>
</svg>
Some text that fingerprints!
Some 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>
</svg>

0 comments on commit a5c92aa

Please sign in to comment.