Added OneNote sections as a document type (#1161)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-04 17:15:30 +01:00
1 parent 677b650a79
commit ce846e540e
24 files changed
+1142 -23

No files matched your search

@@ -7,6 +7,13 @@ public sealed class ContentStreamDocumentDetails
[JsonPropertyName("page_number")]
public int? PageNumber { get; set; }
/// <summary>
/// Whether the page is one the file itself knows, such as a page of a OneNote section, rather
/// than one the runtime estimated from the page breaks of a Word or OpenDocument file.
/// </summary>
[JsonPropertyName("page_is_exact")]
public bool PageIsExact { get; set; }
[JsonPropertyName("image")]
public ContentStreamPptxImageData? Image { get; set; }
}
@@ -26,12 +26,13 @@ public sealed class DocumentManager
//
// A Word or OpenDocument file carries no fixed page layout, so the runtime derives these
// boundaries from page breaks and heuristics. We note the estimate as a comment rather
// than as a heading: a heading would sit on the same level as the document's own first
// level headings, leaving the AI unable to tell the structure of the document apart from
// our boundaries. The presentation reader marks its slides the same way.
// boundaries from page breaks and heuristics and says so. The pages of a OneNote section,
// on the other hand, are those of the file. We note the page as a comment rather than as
// a heading: a heading would sit on the same level as the document's own first level
// headings, leaving the AI unable to tell the structure of the document apart from our
// boundaries. The presentation reader marks its slides the same way.
//
this.currentPageContent.AppendLine($"<!-- Estimated page {pageNumber} -->");
this.currentPageContent.AppendLine(metadata.Document?.PageIsExact is true ? $"<!-- Page {pageNumber} -->" : $"<!-- Estimated page {pageNumber} -->");
this.currentPageContent.AppendLine();
this.currentPageContent.Append(content);
@@ -95,9 +95,10 @@ internal static class FileExclusions
private static readonly string[] ALWAYS_EXCLUDED_FILES = ["Thumbs.db", "ehthumbs.db", "ehthumbs_vista.db", "desktop.ini", ".DS_Store", "Icon\r", OFFICE_LOCK_FILE_PATTERN];
/// <summary>
/// Folders nobody ever wanted as content: what operating systems and ZIP files on macOS leave behind.
/// Folders nobody ever wanted as content: what operating systems and ZIP files on macOS leave behind,
/// and the recycle bin of a OneNote notebook, which holds the pages the user deleted.
/// </summary>
private static readonly string[] ALWAYS_EXCLUDED_FOLDERS = ["__MACOSX", "$RECYCLE.BIN", "System Volume Information"];
private static readonly string[] ALWAYS_EXCLUDED_FOLDERS = ["__MACOSX", "$RECYCLE.BIN", "System Volume Information", "OneNote_RecycleBin"];
private static readonly char[] SEPARATORS = [';', '\r', '\n'];
@@ -84,7 +84,11 @@ public static class FileTypes
// The legacy binary ".ppt" is missing on purpose: AI Studio has no reader for it, so offering
// it would only let users attach a file which cannot be read.
public static readonly FileTypeFilter POWER_POINT = FileTypeFilter.Leaf("PowerPoint", "pptx", "odp");
public static readonly FileTypeFilter MAIL = FileTypeFilter.Leaf(TB("Mail"), "eml", "msg", "mbox");
// Only the sections of a notebook carry its pages. The table of contents (".onetoc2") holds none,
// and a package (".onepkg") would have to be unpacked into memory as a whole.
public static readonly FileTypeFilter ONENOTE = FileTypeFilter.Leaf("OneNote", "one");
public static readonly FileTypeFilter MAIL = FileTypeFilter.Leaf(TB("Mail"), "eml", "msg", "mbox");
public static readonly FileTypeFilter LATEX = FileTypeFilter.Leaf("LaTeX", "tex", "bib", "sty", "cls", "log");
// Only the LaTeX document itself, without the auxiliary files of the LaTeX family: this is
@@ -96,7 +100,7 @@ public static class FileTypes
public static readonly FileTypeFilter POWER_POINT_PRESENTATION = FileTypeFilter.Leaf("PowerPoint", "pptx");
public static readonly FileTypeFilter OFFICE_FILES = FileTypeFilter.Parent(TB("Office Files"),
WORD, SPREADSHEET, POWER_POINT, PDF);
WORD, SPREADSHEET, POWER_POINT, ONENOTE, PDF);
public static readonly FileTypeFilter DOCUMENT = FileTypeFilter.Parent(TB("Document"),
TEXT, TABULAR, OFFICE_FILES, SOURCE_CODE, LATEX);