In der example wird Code zum Abrufen von RichText bereitgestellt. Es ist in der Lage, die Plain Textinhalt der Seite zu bekommen, aber ich kann es nicht scheinen, um den HTML formatierten Inhalt der Seite zurückzugeben.OneNote Hinzufügen: HTML-Inhalt abrufen
Zum Beispiel:
Header:
- A
- B
sollte sein:
<p>Header:</p>
<ul>
<li>A</li>
<li>B</li>
</ul>
jedoch der Beispielcode verwendet richText/text
und liefert nur Header:
. Ist es möglich, etwas wie richText/HTML
zu tun und den HTML-Code oben zu bekommen? (Hinweis: Ich möchte nur das -Add-In und nicht die OneNote-REST-API verwenden.)
Vielen Dank!
-Code-Schnipsel aus Dokumentation:
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));
}
});
Welche Eigenschaften sind für das Objekt 'richTextParagraph.richText' verfügbar? Gibt es einen HTML-Code unter ihnen? Wenn ja, wie ist der Rückgabetyp? –
Eigenschaften sind nur 'id' und 'text' (beide vom Typ 'String'). Per https://dev.office.com/reference/add-ins/onenote/richtext –