Dataviewjs is break with pipe for url

function devanagariToNumber(str) {
  if (typeof str === "number") return str;
  const map = { "०": 0, "१": 1, "२": 2, "३": 3, "४": 4, "५": 5, "६": 6, "७": 7, "८": 8, "९": 9 };
  const converted = str.split('').map(c => map[c] ?? c).join('');
  return Number(converted) || 0; // Fallback to 0 if conversion fails
}

const maxAdhyaya = 8;
const maxPada = 4;
const counts = {};

// Initialize counts object
for (let a = 1; a <= maxAdhyaya; a++) {
  counts[a] = {};
  for (let p = 1; p <= maxPada; p++) {
    counts[a][p] = 0;
  }
}

// Count pages by adhyaya and pada
for (let page of dv.pages()) {
  if (page.adhyaya && page.pada) {
    const a = devanagariToNumber(page.adhyaya);
    const p = devanagariToNumber(page.pada);
    if (counts[a] && counts[a][p] !== undefined) {
      counts[a][p]++;
    }
  }
}

// Define Devanagari labels for adhyaya
const adhyayaLabels = {
  1: "प्रथमोऽध्याय:",
  2: "द्वितीयोऽध्याय:",
  3: "तृतीयोऽध्याय:",
  4: "चतुर्थोऽध्याय:",
  5: "पञ्चमोऽध्याय:",
  6: "षष्ठोऽध्याय:",
  7: "सप्तमोऽध्याय:",
  8: "अष्टमोऽध्याय:"
};

// Build Markdown table
let md = "";
md += "|  | प्रथम: पाद: | द्वितीय: पाद: | तृतीय: पाद: | चतुर्थ: पाद: | TOTAL |\n";
md += "|---|---|---|---|---|---|\n";

for (let a = 1; a <= maxAdhyaya; a++) {
  let row = `| ${adhyayaLabels[a]} `;
  let total = 0;
  for (let p = 1; p <= maxPada; p++) {
    total += counts[a][p];
    const filePath = `media/adhyaya_${a}/pada_${p}/index`; // Removed .md
    // Use link without pipe, display count as text
    row += `| [[${filePath}]]<span style="color: transparent;">${counts[a][p]}</span> `;
  }
  const totalPath = `media/adhyaya_${a}/index`; // Removed .md
  row += `| [[${totalPath}]]<span style="color: transparent;">${total}</span> |`;
  md += row + "\n";
}

// Render the table
dv.paragraph(md);

I wanted it to render like this


but as soon as I add hyperlink syntax like this [[path to the note | displayname ]] it breaks the url into two columns and messes everything up. I would appreciate your help

You’re essentially trying to insert a pipe character within a table which uses the pipe character to delimit cells. This would also break a manually written table, and the solution is to escape the pipe character in the link.

So your links need to look like [[ path \| alias ]]. Depending on which string type you’re using you might need to use more than one backslash character. So try first with one, then two, three or four…

You can try using a tool like LongPathTool. It helps manage and delete files or folders with long path issues easily.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.