I know I ask for much but is it possible to incorporate following code:
const matches = contents.match(new RegExp(regex, 'sg')) || [];
for (const callout of matches) {
const match = callout.match(new RegExp(regex, 's'));
let content = match[1].replace(/>/g, '>'); // Replace > with >
content = content.replace(/^>\s*/gm, ''); // Remove > and spaces at the start of each line
This code is from another snippet I have from ChatGBT. It collets text from a callout and trim it so the result is without >. I have tried to paste it into the code you have written but can’t seem to get it right.
Below is the entire code if anyone is interested It works very well but is very specific and maybe overkill.
code
const {LangCon} = customJS; //My own function which convert english weekdays into danish
const startDate = '<% startDateOfWeek %>'; // Define the start date of the specific week (Monday)
const endDate = '<% endDateOfWeek %>'; // Define the end date of the specific week (Sunday)
const pages = dv.pages('"Pages"');
const regex = /<span class="css-name-here">(.*?)<\/span>/s;
const rows = {
'Mandag': [], // Danish weekday names
'Tirsdag': [],
'Onsdag': [],
'Torsdag': [],
'Fredag': [],
'Lørdag': [],
'Søndag': []
};
for (const page of pages) {
const fileName = page.file.name; // Get the file name (e.g., "2023-12-01")
// Extract the date from the file name
const fileDate = fileName.match(/^(\d{4}-\d{2}-\d{2})/);
if (fileDate) {
const contentDate = fileDate[1];
if (contentDate >= startDate && contentDate <= endDate) {
const file = app.vault.getAbstractFileByPath(page.file.path);
const contents = await app.vault.read(file); // Read file
// Extract the summary via regex
const matches = contents.match(new RegExp(regex, 'sg')) || [];
for (const callout of matches) {
const match = callout.match(new RegExp(regex, 's'));
let content = match[1].replace(/>/g, '>'); // Replace > with >
content = content.replace(/^>\s*/gm, ''); // Remove > and spaces at the start of each line
const day = new Date(contentDate).toLocaleString('en', { weekday: 'long' });
const danishDay = LangCon.DayCon(day); // Convert English to Danish weekday
rows[danishDay].push(content);
}
}
}
}
let text = "";
// Create a list organized by days of the week
for (const [day, content] of Object.entries(rows)) {
if (content.length > 0) {
text += `<span class="css-name-here">\n`;
text += `<h2 class="css-name-here">${day}</h2>\n`;
content.forEach(item => text += `${item}\n`);
text += `</span>\n`;
}
}
dv.span(text);