-
Notifications
You must be signed in to change notification settings - Fork 509
/
DOMxRef.ejs
53 lines (43 loc) · 1.39 KB
/
DOMxRef.ejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<%
/* Used for generating cross-references within the Web API documentation.
* if you specify the API name with parens (ie, "bar()"), the link is to
* lang/Web/API/Foo/bar but the title is displayed as "bar()" to make it clear it's
* a function.
* @param
* The path of the page to link to, relative to the Web/API/ documentation path.
* @param [optional]
* The text to use for the link. If omitted, the value of the first
* parameter will be used
* @param [optional]
* An anchor to link to on the page. Link text will display as $0.$2 or $1.$2
* @param [optional]
* If set, do not put the domxref text in code
*/
/* get a page's language (Don't use page.language!) */
let lang = env.locale;
let api = $0;
let str = $1 || $0;
let rtlLocales = ['ar', 'he', 'fa'];
api = api.replace(/ /g, '_')
.replace(/\(\)/g, '')
.replace(/\.prototype\./g, '.')
.replace(/\./g, '/');
// RTL locales
if (rtlLocales.indexOf(lang) != -1) {
str = '<bdi>' + str +'</bdi>';
}
// Ensure Interfaces are always uppercased in links
// (important for red links to create correct new pages)
api = api.charAt(0).toUpperCase() + api.slice(1);
const basePath = `/${lang}/docs/Web/API/`;
let URL = basePath + api;
let anch = '';
if ($2) {
str = str + '.' + $2;
anch = '#' + $2;
}
if (!$3) {
str = `<code>${str}</code>`;
}
const link = web.smartLink(URL + anch, $1, str, $0, basePath);
%><%- link %>