Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use monospace font for <a>s that link back to IDL #1095

Merged
merged 4 commits into from Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion js/core/link-to-dfn.js
Expand Up @@ -66,7 +66,10 @@ define(
if (dfn.closest('code,pre').length ||
(dfn.contents().length === 1 && dfn.children('code').length === 1)) {
// only add code to IDL when the definition matches
if (dfn[0].dataset.hasOwnProperty("idl") && dfn[0].dataset.title !== $ant[0].textContent.trim()) {
const term = $ant[0].textContent.trim();
const isIDL = dfn[0].dataset.hasOwnProperty("idl");
const isSameText = (isIDL) ? dfn[0].dataset.title === term : dfn[0].textContent.trim() === term;
if (isIDL && !isSameText) {
return true;
}
$ant.wrapInner('<code></code>');
Expand Down
2 changes: 2 additions & 0 deletions js/core/webidl-contiguous.js
Expand Up @@ -945,6 +945,8 @@ define(
// Mark the definition as code.
dfn.attr("id", "dom-" + (parent ? parent + "-" : "") + name);
dfn.attr("data-idl", "");
dfn.attr("data-title", dfn[0].textContent);

dfn.attr("data-dfn-for", parent);
if (dfn.children("code").length === 0 && dfn.parents("code").length === 0)
dfn.wrapInner("<code></code>");
Expand Down
32 changes: 32 additions & 0 deletions tests/spec/core/link-to-dfn-spec.js
@@ -0,0 +1,32 @@
"use strict";
describe("Core — Link to definitions", function() {
afterAll(function(done) {
flushIframes();
done();
});
it("links to IDL definitions and wraps in code if needed", function(done) {
const bodyText = `
<section data-link-for="Request">
<h2><dfn>Request</dfn> interface</h2>
<pre class="idl">
interface Request {};
</pre>
<p id="codeWrap">A <a>Request</a> object.</p>
<p id="noCodeWrap">An instance of <a lt="Request">the request interface</a>.</p>
</section>`;
var ops = {
config: makeBasicConfig(),
body: makeDefaultBody() + bodyText,
};
makeRSDoc(ops, doc => {
const hasCode = doc.body.querySelector("#codeWrap a");
expect(hasCode).toBeTruthy();
expect(hasCode.firstElementChild.localName).toEqual("code");
expect(hasCode.textContent).toEqual("Request");
const noCodeWrap = doc.body.querySelector("#noCodeWrap a");
expect(noCodeWrap).toBeTruthy();
expect(noCodeWrap.querySelector("code")).toBeFalsy();
expect(noCodeWrap.textContent).toEqual("the request interface");
}).then(done);
});
});
1 change: 1 addition & 0 deletions tests/testFiles.json
Expand Up @@ -17,6 +17,7 @@
"spec/core/inlines-spec.js",
"spec/core/issues-notes-spec.js",
"spec/core/jquery-enhanced-spec.js",
"spec/core/link-to-dfn-spec.js",
"spec/core/markdown-spec.js",
"spec/core/override-configuration-spec.js",
"spec/core/pre-process-spec.js",
Expand Down