"""OneNote sink: create a page from the parsed Markdown via Microsoft Graph.
OneNote pages are created by POSTing an HTML document to a section's ``pages``
endpoint with a pre-obtained Microsoft Graph access token (OAuth). Delivery
converts the Markdown to a full HTML document and creates the page.
Only remote images render — Graph fetches ```` URLs, so local image
paths emitted by MinerU would need to be public URLs.
"""
from __future__ import annotations
import html
import json
from . import _http, _md
from .base import ParsedDoc, Sink, SinkError, SinkResult, register
@register
class OneNoteSink(Sink):
name = "onenote"
aliases = ("msonenote",)
requires = ("ONENOTE_TOKEN", "ONENOTE_SECTION_ID")
label = "OneNote section page (Microsoft Graph)"
def deliver(self, doc: ParsedDoc) -> SinkResult:
token = self.env("ONENOTE_TOKEN")
section = self.env("ONENOTE_SECTION_ID")
body_html = _md.md_to_html(doc.markdown)
page = (
"