1

我试图弄清楚如何更新我的页面 - 我需要<body>始终替换标签内的所有内容。

OneNote API 说:

以下元素不支持任何 PATCH 动作: - img 或 object(绝对定位) - meta、head - tr、tda、span、任何样式标签

注意:绝对定位的 div、img 或 object 元素是定义 style=position:absolute 的页面主体的直接子元素。

好的,这很清楚。所以我不能替换<object>没有 ID 的,因为如果没有,它要么应该是<div>id 的一部分,要么属于最顶层的 div。

这是我的页面内容:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
    <title>image and PDF 2</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
    <div id="div:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{32}" data-id="_default" style="position:absolute;left:48px;top:120px;width:624px">
        <p id="p:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{38}" style="margin-top:2.8pt;margin-bottom:2.8pt"> SOME TEXT HERE <br />
        </p>
        <object data-attachment="pdf-sample.pdf" type="application/pdf" data="https://www.onenote.com/api/v1.0/me/notes/resources/0-3329938c15524891836ef46f570c17ce!1-6481EB8A1188E91C!389/$value" />
        <img id="img:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{42}" alt="Image" src="https://www.onenote.com/api/v1.0/me/notes/resources/0-dfd3e39146d4425b974a71479787845f!1-6481EB8A1188E91C!389/$value" data-src-type="image/jpeg" data-fullres-src="https://www.onenote.com/api/v1.0/me/notes/resources/0-dfd3e39146d4425b974a71479787845f!1-6481EB8A1188E91C!389/$value" data-fullres-src-type="image/jpeg" />
        <object data-attachment="_SaferoomTestDOC.doc" type="application/msword" data="https://www.onenote.com/api/v1.0/me/notes/resources/0-07e77c13690247e88afcd20af3b45a12!1-6481EB8A1188E91C!389/$value" />
    </div>
  </body>
</html>

现在,如果我想替换上面的图像(<img>),我会这样做:

 {
'target':'img:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{42}',
'action':'replace',
'content':'<img src="NEW IMAGE" alt="NEW IMAGE" />'

},

但是如何替换在我的情况下是 PDF 或 Word 文档的对象?我该如何更换整个<body>

PS我尝试将<object>对象标签包装到div中,<div>标签在上传时被剥离。

PPS 我总是需要替换正文中的全部内容以及所有对象和图像。

4

2 回答 2

1

但是如何替换在我的情况下是 PDF 或 Word 文档的对象?我该如何更换整个?

在这种情况下,我们可以删除旧页面并创建一个新页面。这是一个创建页面的示例,该页面中嵌入了单词和图像:

POST https://www.onenote.com/api/v1.0/me/notes/pages
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
Authorization: Bearer {token}

---------------------------acebdf13572468
Content-Disposition:form-data; name="Presentation"
Content-Type:text/html

<!DOCTYPE html>
<html>
  <head>
    <title>A page with rendered images and an attached file</title>
    <meta name="created" content="2016-05-30T07:30:00-08:00" />
  </head>
  <body>
    <p>Here's an image from an <i>online source</i>:</p>
    <img src="http://png-4.findicons.com/files/icons/2795/office_2013_hd/2000/onenote.png" alt="an image on the page" width="500" />
    <p>Here's an image uploaded as <b>binary data</b>:</p>
    <img src="name:imageBlock1" alt="an image on the page" width="300" />
    <p>Here's a file attachment:</p>
    <object data-attachment="doc1.docx" data="name:fileBlock1" type="application/docx" />
  </body>
</html>

---------------------------acebdf13572468
Content-Disposition: form-data; name="imageBlock1"; filename="wdIcon.jpg"
Content-Type: image/jpeg

<@INCLUDE *C:\users\username\desktop\wdIcon.jpg*@>
---------------------------acebdf13572468
Content-Disposition: form-data; name="fileBlock1"; filename="doc1.docx"
Content-Type: application/msword

<@INCLUDE *C:\users\username\desktop\doc1.docx*@>
---------------------------acebdf13572468—
于 2016-05-30T08:12:40.230 回答
0

要替换整个身体(技术上只有 body 标签的第一个直接子 div),请使用:

{
 'target':'body',
 'action':'replace',
 'content':'your new page content'
}
于 2016-06-03T17:29:59.430 回答