在示例中,提供了获取 RichText 的代码。它能够获取页面的纯文本内容,但我似乎无法让它返回页面的HTML格式内容。
例如:
标题:
- 一种
- 乙
应该:
<p>Header:</p>
<ul>
<li>A</li>
<li>B</li>
</ul>
但是,示例代码使用richText/text
并且仅返回Header:
. 是否有可能做类似的事情richText/HTML
并获得上面显示的 HTML?(注意:我只想使用加载项,而不是 OneNote REST API。)
谢谢!
文档中的代码片段:
OneNote.run(function (context) {
// Get the collection of pageContent items from the page.
var pageContents = context.application.getActivePage().contents;
// Get the first PageContent on the page, and then get its outline's paragraphs.
var outlinePageContents = [];
var paragraphs = [];
var richTextParagraphs = [];
// Queue a command to load the id and type of each page content in the outline.
pageContents.load("id,type");
// Run the queued commands, and return a promise to indicate task completion.
return context.sync()
.then(function () {
// Load all page contents of type Outline
$.each(pageContents.items, function(index, pageContent) {
if(pageContent.type == 'Outline')
{
pageContent.load('outline,outline/paragraphs,outline/paragraphs/type');
outlinePageContents.push(pageContent);
}
});
return context.sync();
})
.then(function () {
// Load all rich text paragraphs across outlines
$.each(outlinePageContents, function(index, outlinePageContent) {
var outline = outlinePageContent.outline;
paragraphs = paragraphs.concat(outline.paragraphs.items);
});
$.each(paragraphs, function(index, paragraph) {
if(paragraph.type == 'RichText')
{
richTextParagraphs.push(paragraph);
paragraph.load("id,richText/text");
}
});
return context.sync();
})
.then(function () {
// Display all rich text paragraphs to the console
$.each(richTextParagraphs, function(index, richTextParagraph) {
var richText = richTextParagraph.richText;
console.log("Paragraph found with richtext content : " + richText.text + " and richtext id : " + richText.id);
});
return context.sync();
});
})
.catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});