Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%*
- const content = tp.file.content;
- const sections = content.matchAll(/(?<=---|^)\s*([\S\s]+?)\s*(?=---|$)/g);
- const tfile = this.app.workspace.getActiveFile();
- const my_folder = tfile.parent;
- let number = 0;
- function padToTwo(number) {
- if (number <= 99)
- {
- number = ("0"+number).slice(-2);
- }
- return number;
- }
- function get_title(section) {
- title_match = section.match(/^#+ (.*)/m);
- if (title_match == null)
- return "";
- return title_match[1];
- }
- for (const section of sections)
- {
- number += 1;
- note_content = section[1];
- title = get_title(note_content);
- // remove disallowed characters
- title = title.replace(/[*"\\/<>:|?]/g, "");
- if (title == "")
- title = padToTwo(number);
- else
- // replace first header with header one
- note_content = note_content.replace(/^#+ (.*)/m, "# $1");
- // replace two-line dash with three-line dash
- note_content = note_content.replace(/(?<=\n|^)(--)(?=\n|$)/g, "---");
- await tp.file.create_new(
- template = note_content,
- filename = tp.user.get_note_ID() + " " + title,
- open_new = false,
- folder = my_folder
- );
- }
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement