forked from evbacher/gd2md-html
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes evbacher#20
- Loading branch information
Showing
7 changed files
with
1,108 additions
and
743 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
{ | ||
"timeZone": "America/Los_Angeles", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"enabledAdvancedServices": [{ | ||
"userSymbol": "Drive", | ||
"serviceId": "drive", | ||
"version": "v2" | ||
}] | ||
}, | ||
"oauthScopes": [ | ||
"https://www.googleapis.com/auth/documents.currentonly", | ||
"https://www.googleapis.com/auth/script.container.ui" | ||
"https://www.googleapis.com/auth/script.container.ui", | ||
"https://www.googleapis.com/auth/drive.readonly" | ||
], | ||
"exceptionLogging": "STACKDRIVER", | ||
"runtimeVersion": "DEPRECATED_ES5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Functions for handling comments from Drive API | ||
|
||
function processCommentReplies(reply) { | ||
return { | ||
content: reply.content, | ||
author: reply.author.displayName, | ||
created: reply.createdTime, | ||
}; | ||
} | ||
|
||
function getDocumentComments() { | ||
const doc = DocumentApp.getActiveDocument(); | ||
const docId = doc.getId(); | ||
|
||
try { | ||
const commentsResponse = Drive.Comments.list(docId, { | ||
maxResults: 100, | ||
fields: "*", | ||
}); | ||
|
||
if (!commentsResponse.comments) return []; | ||
|
||
return commentsResponse.comments.map((comment) => ({ | ||
id: comment.id, | ||
content: cleanHtmlContent(comment.content), | ||
author: comment.author.displayName, | ||
created: comment.createdTime, | ||
quotedText: comment.quotedFileContent | ||
? cleanHtmlContent(comment.quotedFileContent.value) | ||
: null, | ||
anchor: comment.anchor, | ||
replies: (comment.replies || []).map(processCommentReplies), | ||
})); | ||
} catch (e) { | ||
Logger.log("Error getting comments:", e.toString()); | ||
return []; | ||
} | ||
} | ||
|
||
// This helper formats comments for Markdown output | ||
function formatMarkdownComment(comment, referenceId) { | ||
let output = `[${referenceId}] **${comment.author}** (${new Date( | ||
comment.created | ||
).toLocaleString()}): ${comment.content}\n`; | ||
|
||
if (comment.replies && comment.replies.length > 0) { | ||
comment.replies.forEach((reply) => { | ||
output += ` > **${reply.author}** (${new Date( | ||
reply.created | ||
).toLocaleString()}): ${reply.content}\n`; | ||
}); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
// This helper formats comments for HTML output | ||
function formatHtmlComment(comment, referenceId) { | ||
let output = `<div class="comment" id="comment${referenceId}">\n`; | ||
output += ` <p><strong>${comment.author}</strong> (${new Date( | ||
comment.created | ||
).toLocaleString()}): ${comment.content}</p>\n`; | ||
|
||
if (comment.replies && comment.replies.length > 0) { | ||
comment.replies.forEach((reply) => { | ||
output += ` <blockquote><p><strong>${reply.author}</strong> (${new Date( | ||
reply.created | ||
).toLocaleString()}): ${reply.content}</p></blockquote>\n`; | ||
}); | ||
} | ||
|
||
output += `</div>\n`; | ||
return output; | ||
} | ||
|
||
// Clean HTML content in comment text | ||
function cleanHtmlContent(content) { | ||
if (!content) return ""; | ||
return content | ||
.replace(/<[^>]*>/g, "") // Remove HTML tags | ||
.replace(/"/g, '"') // Fix quotes | ||
.replace(/'/g, "'") // Fix apostrophes | ||
.replace(/&/g, "&") // Fix ampersands | ||
.replace(/\s+/g, " ") // Normalize whitespace | ||
.trim(); | ||
} |
Oops, something went wrong.