-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add blockquote functionality #73
Changes from 4 commits
7c96501
00bafd8
37126a9
f07f26d
b129138
a694c46
18dd9dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -239,7 +239,12 @@ export const mergeSameElements = (elements) => | |||||||||||||
|
||||||||||||||
export const parseParagraph = (documentContext) => (paragraph) => { | ||||||||||||||
const { elements, ...paragraphContext } = paragraph; | ||||||||||||||
const paragraphStyleName = paragraphContext.paragraphStyle?.namedStyleType; | ||||||||||||||
const paragraphStyle = paragraphContext.paragraphStyle || {}; | ||||||||||||||
const paragraphStyleName = paragraphStyle.namedStyleType; | ||||||||||||||
|
||||||||||||||
// Check indentation - Google Docs API provides this in PT units | ||||||||||||||
const indentStart = paragraphStyle.indentStart?.magnitude || 0; | ||||||||||||||
const QUOTE_INDENT_THRESHOLD = 18; // Standard indentation button is 36pt, we test lower | ||||||||||||||
|
||||||||||||||
let md = mergeSameElements(elements).map( | ||||||||||||||
parseElement({ documentContext, paragraphContext }) | ||||||||||||||
|
@@ -250,7 +255,7 @@ export const parseParagraph = (documentContext) => (paragraph) => { | |||||||||||||
let leadingSpace = ""; | ||||||||||||||
|
||||||||||||||
// First we check if the "paragraph" is a heading, because the markdown for a heading is the first thing we need to output | ||||||||||||||
if (paragraphStyleName.indexOf("HEADING_") === 0) { | ||||||||||||||
if (paragraphStyleName?.indexOf("HEADING_") === 0) { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is separate bug fix or does it relate to the blockquote functionality? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the previous version, the |
||||||||||||||
const headingLevel = parseInt(paragraphStyleName[8]); | ||||||||||||||
const headingPrefix = new Array(headingLevel).fill("#").join("") + " "; | ||||||||||||||
prefix = headingPrefix; | ||||||||||||||
|
@@ -296,11 +301,15 @@ export const parseParagraph = (documentContext) => (paragraph) => { | |||||||||||||
md.join("").replaceAll("\n", "\n" + leadingSpace + " ") | ||||||||||||||
); | ||||||||||||||
} else { | ||||||||||||||
// Add quote marker if the paragraph is indented beyond our threshold | ||||||||||||||
const isQuote = indentStart >= QUOTE_INDENT_THRESHOLD; | ||||||||||||||
const quotePrefix = isQuote ? "> " : ""; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit of a nit so no problem if you want to keep it as is, but a consideration could be that this is introducing a nested conditional (the ternary in the To lift the conditional, the
Then the conditional would just be
Suggested change
Note an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up defining quotePrefix everywhere as an empty string, and updating it if needed. LMK what you think of this type of logic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, current logic looks good to me 👍 |
||||||||||||||
return ( | ||||||||||||||
leadingSpace + | ||||||||||||||
itemMarker + | ||||||||||||||
quotePrefix + | ||||||||||||||
prefix + | ||||||||||||||
md.join("").replaceAll("\n", "\n" + leadingSpace) | ||||||||||||||
md.join("").replaceAll("\n", "\n" + leadingSpace + quotePrefix) | ||||||||||||||
); | ||||||||||||||
} | ||||||||||||||
}; | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this part, it was recommended by Claude
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ok. In both the previous and the new code, if
paragraphContext.paragraphStyle
thenparagraphStyleName
willundefined
. I think this change is just to haveparagraphStyle
as a separate variable to be able to use it below.