Skip to content

Commit

Permalink
Fix anchor links in API docs to inline class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Oct 31, 2024
1 parent 8b17877 commit ef0f026
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 8 additions & 2 deletions scripts/js/lib/api/updateLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ test.describe("updateLinks", () => {
[link8](#qiskit_ibm_runtime.RuntimeJob.job)
[link9](https://qiskit.org/documentation/apidoc/algorithms.html)
[link10](https://qiskit.org/documentation/stubs/qiskit.circuit.BreakLoopOp.html#assemble)
[link11](qiskit_ibm_runtime.RuntimeJob#qiskit_ibm_runtime.RuntimeJob.a_method)
[link12](qiskit_ibm_runtime.RuntimeJob#qiskit_ibm_runtime.RuntimeJob.InlineClass.another_method)
`,
meta: {
apiType: "class",
Expand Down Expand Up @@ -97,7 +99,9 @@ test.describe("updateLinks", () => {
[link7](qiskit_ibm_runtime.RuntimeJob)
[link8](#qiskit_ibm_runtime.RuntimeJob.job)
[link9](/api/qiskit/algorithms)
[link10](/api/qiskit/qiskit.circuit.BreakLoopOp#assemble)\n`,
[link10](/api/qiskit/qiskit.circuit.BreakLoopOp#assemble)
[link11](qiskit_ibm_runtime.RuntimeJob#a_method)
[link12](qiskit_ibm_runtime.RuntimeJob#another_method)\n`,
meta: {
apiName: "qiskit_ibm_runtime.RuntimeJob",
apiType: "class",
Expand Down Expand Up @@ -149,7 +153,9 @@ test.describe("updateLinks", () => {
[link7](runtime-job)
[link8](#qiskit_ibm_runtime.RuntimeJob.job)
[link9](/api/qiskit/algorithms)
[link10](/api/qiskit/qiskit.circuit.BreakLoopOp#assemble)\n`,
[link10](/api/qiskit/qiskit.circuit.BreakLoopOp#assemble)
[link11](runtime-job#a_method)
[link12](runtime-job#another_method)\n`,
meta: {
apiName: "qiskit_ibm_runtime.RuntimeJob",
apiType: "class",
Expand Down
14 changes: 13 additions & 1 deletion scripts/js/lib/api/updateLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,21 @@ export function normalizeUrl(
url = normalizedUrlWithoutHash;
}

// Rather than linking to the component like `Function` or `Attribute`, we link to the header.
// This is necessary because until we implement https://github.com/Qiskit/documentation/issues/1395, the
// anchor for the component would take you too low in the page, given that the header is above the component.
// qiskit_ibm_runtime.RuntimeJob#qiskit_ibm_runtime.RuntimeJob.job -> qiskit_ibm_runtime.RuntimeJob#job
//
// TODO(#2217): Remove this special case and use the full ID instead.
if (hash?.startsWith(`${page}.`)) {
const member = removePrefix(hash, `${page}.`);
let member = removePrefix(hash, `${page}.`);
// Also check for inline classes, which often show up on module pages.
// qiskit_addon_obp.utils.truncating#qiskit_addon_obp.utils.truncating.TruncationErrorBudget.p_norm
// -> qiskit_addon_obp.utils.truncating#p_norm, whereas without this check
// it would be qiskit_addon_obp.utils.truncating#TruncationErrorBudget.p_norm.
if (member.includes(".")) {
member = member.split(".", 2)[1];
}
url = `${normalizedUrlWithoutHash}#${member}`;
}
}
Expand Down

0 comments on commit ef0f026

Please sign in to comment.