Skip to content

Commit 276cd2a

Browse files
authored
Fix charts with schema-url breaking when using links with index, closes #24
1 parent 87789f5 commit 276cd2a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

mkdocs_charts_plugin/js/mkdocs-charts-plugin.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function checkNested(obj /*, level1, level2, ... levelN*/) {
1818
}
1919

2020

21-
2221
function classnameInParents(el, classname) {
2322
// check if class name in any parents
2423
while (el.parentNode) {
@@ -68,7 +67,14 @@ function findProperChartWidth(el) {
6867
}
6968

7069
function updateURL(url) {
71-
// detect if absolute UR:
70+
71+
// Strip anchor from URL if present
72+
let anchorIndex = url.indexOf('#');
73+
if (anchorIndex !== -1) {
74+
url = url.substring(0, anchorIndex);
75+
}
76+
77+
// detect if absolute URL:
7278
// credits https://stackoverflow.com/a/19709846
7379
var r = new RegExp('^(?:[a-z]+:)?//', 'i');
7480
if (r.test(url)) {
@@ -89,7 +95,14 @@ function updateURL(url) {
8995
// path_to_homepage: ".." (this was detected in plugin on_post_page() event)
9096
// output url: "../assets/data.csv"
9197
if (mkdocs_chart_plugin['use_data_path'] == "True") {
92-
new_url = window.location.href
98+
let new_url = window.location.href
99+
100+
// Strip anchor from URL if present
101+
let anchorIndex = new_url.indexOf('#');
102+
if (anchorIndex !== -1) {
103+
new_url = new_url.substring(0, anchorIndex);
104+
}
105+
93106
new_url = new_url.endsWith('/') ? new_url.slice(0, -1) : new_url;
94107

95108
if (mkdocs_chart_plugin['path_to_homepage'] != "") {
@@ -160,8 +173,6 @@ function embedChart(block, schema) {
160173
}
161174

162175

163-
164-
165176
// Save the block and schema
166177
// This way we can re-render the block
167178
// in a different theme

0 commit comments

Comments
 (0)