Skip to content

Commit

Permalink
Fix charts with schema-url breaking when using links with index, closes
Browse files Browse the repository at this point in the history
  • Loading branch information
timvink authored Aug 26, 2024
1 parent 87789f5 commit 276cd2a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions mkdocs_charts_plugin/js/mkdocs-charts-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function checkNested(obj /*, level1, level2, ... levelN*/) {
}



function classnameInParents(el, classname) {
// check if class name in any parents
while (el.parentNode) {
Expand Down Expand Up @@ -68,7 +67,14 @@ function findProperChartWidth(el) {
}

function updateURL(url) {
// detect if absolute UR:

// Strip anchor from URL if present
let anchorIndex = url.indexOf('#');
if (anchorIndex !== -1) {
url = url.substring(0, anchorIndex);
}

// detect if absolute URL:
// credits https://stackoverflow.com/a/19709846
var r = new RegExp('^(?:[a-z]+:)?//', 'i');
if (r.test(url)) {
Expand All @@ -89,7 +95,14 @@ function updateURL(url) {
// path_to_homepage: ".." (this was detected in plugin on_post_page() event)
// output url: "../assets/data.csv"
if (mkdocs_chart_plugin['use_data_path'] == "True") {
new_url = window.location.href
let new_url = window.location.href

// Strip anchor from URL if present
let anchorIndex = new_url.indexOf('#');
if (anchorIndex !== -1) {
new_url = new_url.substring(0, anchorIndex);
}

new_url = new_url.endsWith('/') ? new_url.slice(0, -1) : new_url;

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




// Save the block and schema
// This way we can re-render the block
// in a different theme
Expand Down

0 comments on commit 276cd2a

Please sign in to comment.