Problem description
Inside a specific folder named “00.00 Index notes”, I created several (index) notes whose titles follow the pattern “xx.xx rest of title” where x is a number from 0 to 9. I also created a script that filters these index notes and generates an index table from them.
However, I’m encountering a styling issue. Although the script mostly works as intended, the first title is rendered incorrectly when I try to style the markdown output entirely in a monospace font.
Folder of index notes with index numbers
Script Output.
What I’m trying to do
I want the markdown output generated by DataviewJS to be displayed completely in a monospace font. However, I’m experiencing issues with the first title being rendered incorrectly. Below is the script I am using:
// Get all pages in the folder "00-09 System/00 Index/00.01 Index notes"
const folderPath = "00-09 System/00 Index/00.01 Index notes";
const pages = dv.pages(`"${folderPath}"`);
// Function to filter pages by prefix and create links
const filterPagesByPrefix = (prefix) => {
return pages
.filter(p => p.file.name.startsWith(prefix))
.map(p => `[[${p.file.name}]]`);
};
// Mapping for individual titles
const systemTitles = {
"00": "00-09 System",
"10": "10-19 Area",
"20": "20-29 Domain",
// Add more mappings as needed
};
const indexTitles = {
"00": "00 Index",
"01": "01 Next Topic",
"02": "02 More topics",
"10": "10 Topic",
"11": "11 Super topic",
"21": "21 More",
"22": "22 Cool",
"23": "23 Krass"
// Add more mappings as needed
};
// Generate sections dynamically
let content = "";
for (let i = 0; i <= 9; i++) {
const systemKey = `${i}0`;
const systemTitle = systemTitles[systemKey] || "";
if (systemTitle) {
content += `## ${systemTitle}\n`;
}
for (let j = 0; j <= 9; j++) {
const prefix = `${i}${j}`;
const indexTitle = indexTitles[prefix] || "";
const filteredPages = filterPagesByPrefix(prefix);
if (indexTitle && filteredPages.length > 0) {
content += `### ${indexTitle}\n`;
content += dv.markdownList(filteredPages) + '\n';
}
}
}
// HERE IS THE PROBLEMATIC LINE OF CODE
// Wrap the content in a div with inline CSS for monospace font
const wrappedContent = `<span><div style='font-family: monospace;'>${content}</div></span>`;
// Display the content
dv.paragraph(wrappedContent);
Things I have tried
I attempted to wrap the content in various HTML tags for font styling, but the problem persists. The outer span tag in <span><div style='font-family: monospace;'>${content}</div></span>
; yielded some improvement.
The image below shows the output without outer span tags.
Request for Help
I would greatly appreciate any insights or solutions to ensure the markdown output is entirely styled in monospace font without rendering errors, especially for the first title.