<%
/* Used for generating cross-references within the Web Extensions API
 * documentation.
 * if you specify the API name with parens (ie, "bar()"), the link is to
 * lang//en-US/docs/Mozilla/Add-ons/WebExtensions/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
 * /en-US/docs/Mozilla/Add-ons/WebExtensions/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 wexref 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(' ', '_').replace('()', '').replace(/\./g, '/');

// RTL locales
if (rtlLocales.indexOf(lang) != -1) {
    str = '<bdi>' + str +'</bdi>';
}

let URL = "/" + lang + '/docs/Mozilla/Add-ons/WebExtensions/API/' + api;

let anch = '';

if ($2) {
  str = str + '.' + $2;
  anch = '#' + $2;
}

let code = '';
let endcode = '';
if (!$3) { code = '<code>'; endcode = '</code>' }

%><a href="<%- URL+anch %>"><%- code %><%- str %><%- endcode %></a>
