Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/formats/onenote.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OnenotePage, SectionGroup, User, PublicError, Notebook, OnenoteSection } from '@microsoft/microsoft-graph-types';
import { DataWriteOptions, Notice, Setting, TFolder, htmlToMarkdown, ObsidianProtocolData, requestUrl, moment } from 'obsidian';
import { genUid, extractErrorMessage, parseHTML } from '../util';
import { genUid, extractErrorMessage, parseHTML, sanitizeFileName } from '../util';
import { FormatImporter } from '../format-importer';
import { ATTACHMENT_EXTS, AUTH_REDIRECT_URI, ImportContext } from '../main';
import { AccessTokenResponse } from './onenote/models';
Expand Down Expand Up @@ -727,7 +727,8 @@ export class OneNoteImporter extends FormatImporter {

getEntityPathNoParent(entityID: string, currentPath: string): string | null {
for (const notebook of this.notebooks) {
const path = this.getEntityPath(entityID, `${currentPath}/${notebook.displayName}`, notebook);
const sanitizedName = sanitizeFileName(notebook.displayName || 'Untitled Notebook');
const path = this.getEntityPath(entityID, `${currentPath}/${sanitizedName}`, notebook);
if (path) return path;
}
return null;
Expand Down Expand Up @@ -779,7 +780,8 @@ export class OneNoteImporter extends FormatImporter {
* ...Section/Example/Page.md and ...Section/Example/Lower level.md
*/
if (section.pages![i + 1] && section.pages![i + 1].level !== 0) {
returnPath = `${currentPath}/${page.title}`;
const sanitizedName = sanitizeFileName(page.title || 'Untitled');
returnPath = `${currentPath}/${sanitizedName}`;
}
else returnPath = currentPath;
}
Expand All @@ -789,7 +791,8 @@ export class OneNoteImporter extends FormatImporter {
// Iterate backward to find the parent page
for (let i = section.pages!.indexOf(page) - 1; i >= 0; i--) {
if (section.pages![i].level === page.level! - 1) {
returnPath += '/' + section.pages![i].title;
const sanitizedName = sanitizeFileName(section.pages![i].title || 'Untitled');
returnPath += '/' + sanitizedName;
break;
}
}
Expand All @@ -804,9 +807,10 @@ export class OneNoteImporter extends FormatImporter {
// Recursively search in section groups
let returnPath: string | null = null;
for (const sectionGroup of sectionGroups) {
if (sectionGroup.id === entityID) returnPath = `${currentPath}/${sectionGroup.displayName}`;
const sanitizedName = sanitizeFileName(sectionGroup.displayName || 'Untitled');
if (sectionGroup.id === entityID) returnPath = `${currentPath}/${sanitizedName}`;
else {
const foundPath = this.getEntityPath(entityID, `${currentPath}/${sectionGroup.displayName}`, sectionGroup);
const foundPath = this.getEntityPath(entityID, `${currentPath}/${sanitizedName}`, sectionGroup);
if (foundPath) {
returnPath = foundPath;
break;
Expand Down