-
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 all 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 |
---|---|---|
|
@@ -237,9 +237,16 @@ export const mergeSameElements = (elements) => | |
return acc; | ||
}, []); | ||
|
||
const isQuote = (paragraphStyle) => { | ||
const indentStart = paragraphStyle?.indentStart?.magnitude || 0; | ||
const QUOTE_INDENT_THRESHOLD = 18; // Standard indentation button is 36pt, we test lower | ||
return indentStart >= QUOTE_INDENT_THRESHOLD; | ||
}; | ||
|
||
export const parseParagraph = (documentContext) => (paragraph) => { | ||
const { elements, ...paragraphContext } = paragraph; | ||
const paragraphStyleName = paragraphContext.paragraphStyle?.namedStyleType; | ||
const paragraphStyle = paragraphContext.paragraphStyle || {}; | ||
const paragraphStyleName = paragraphStyle.namedStyleType; | ||
|
||
let md = mergeSameElements(elements).map( | ||
parseElement({ documentContext, paragraphContext }) | ||
|
@@ -250,7 +257,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 +303,16 @@ export const parseParagraph = (documentContext) => (paragraph) => { | |
md.join("").replaceAll("\n", "\n" + leadingSpace + " ") | ||
); | ||
} else { | ||
let quotePrefix = ""; | ||
if (isQuote(paragraphStyle)) { | ||
quotePrefix = "> "; | ||
} | ||
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.