-
Notifications
You must be signed in to change notification settings - Fork 4
feature: create SerializeSlateToText #68
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
Conversation
fa85990 to
aa6280b
Compare
aa6280b to
54fc93a
Compare
text_converter.go
Outdated
| return strings.TrimSpace(text), nil | ||
| } | ||
|
|
||
| // serializeNodes recursively processes nodes and their content into a plain-text format. |
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.
processes nodes and its content
text_converter.go
Outdated
| } | ||
|
|
||
| // Recursively process child nodes. | ||
| if len(node.Nodes) > 0 && node.Type != "heading-large" && node.Type != "caption" && node.Type != "figure" { |
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.
semua node type ini dibikin const aja yak
text_converter.go
Outdated
| } | ||
|
|
||
| // SerializeSlateToText processes and formats a Slate document JSON string. | ||
| func SerializeSlateToText(documentJSON string) (string, error) { |
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.
SerializeSlateToPlainText
text_converter.go
Outdated
|
|
||
| // cleans up the serialized list by removing excessive punctuation. | ||
| func cleanUpList(text string) string { | ||
| cleaned := regexp.MustCompile(`\.+`).ReplaceAllString(text, _sentenceSeparator) |
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.
yg regexp.MustCompile bisa di global var karena reuse
text_converter.go
Outdated
| } | ||
|
|
||
| // Recursively process child nodes. | ||
| if len(node.Nodes) > 0 && node.Type != "heading-large" && node.Type != "caption" && node.Type != "figure" { |
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.
if len(node.Nodes) doang bisa kyknya, yg filter type udh kehandle switch yg di bawahnya. CMIIW
text_converter.go
Outdated
|
|
||
| // Recursively process child nodes. | ||
| if len(node.Nodes) > 0 && node.Type != "heading-large" && node.Type != "caption" && node.Type != "figure" { | ||
| // modifiedNodeSeparator = getModifiedNodeSeparator(node.Type, nodeSeparator) |
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.
bisa dihapus?
text_converter.go
Outdated
| // modifiedNodeSeparator = getModifiedNodeSeparator(node.Type, nodeSeparator) | ||
| switch node.Type { | ||
| case "heading-medium": | ||
| return _sentenceSeparator |
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.
ini knp return mba? bukan continue
text_converter.go
Outdated
| if len(node.Leaves) > 0 { | ||
| lastLeaf := node.Leaves[len(node.Leaves)-1] | ||
| if text := lastLeaf.Text; text != "" { | ||
| if !endsWithPunctuation(text) { |
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.
ini ngga kebalik ya? if endsWithPunctuation { baru tambah punctuation nya}
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.
ini emang nyari yang ga berakhir dengan punctuation coco
text_converter.go
Outdated
| @@ -0,0 +1,160 @@ | |||
| package utils | |||
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.
nama file nya slate converter gasi?
text_converter.go
Outdated
| ) | ||
|
|
||
| // Leaf represents a text element with optional formatting. | ||
| type Leaf struct { |
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.
nama nya diperjelas SlateLeaf, SlateNode gmn? soalnya kalo ada yang baru lebih mudeh dan ini leaf node terlalu generic
text_converter.go
Outdated
| return "", err | ||
| } | ||
|
|
||
| text := serializeNodes(wrappedDocument.Document.Nodes, _newline, _spaceSeparator) |
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.
gimana kalo misal fungsi ini jadi Parse aja, trus WrappedDocument jadi SlateDocument. Trus ada method nya namanya ToPlainText()? jadi kalo ada implementasi bikin ke html juga bisa lebih enak
slate_converter.go
Outdated
| type SlateNode struct { | ||
| Object string `json:"object"` | ||
| Type string `json:"type"` | ||
| SlateNodes []SlateNode `json:"nodes,omitempty"` |
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.
ini nodes aja gasi?
slate_converter.go
Outdated
| SlateNodes []SlateNode `json:"nodes,omitempty"` | ||
| Leaves []SlateLeaf `json:"leaves,omitempty"` | ||
|
|
||
| isLastListElement bool |
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.
isLastInList aja
slate_converter.go
Outdated
| } | ||
|
|
||
| // ToPlainText converts a Slate document into a plain-text format. | ||
| func (slateDocument *SlateDocument) ToPlainText() (string, error) { |
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.
receivernya bisa ga perlu pointer
slate_converter.go
Outdated
| } | ||
|
|
||
| // serializeLeaves joins leaf texts with the specified separator. | ||
| func serializeLeaves(leaves []SlateLeaf, separator string) string { |
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.
Slate nya kurang di naming fungsi
slate_converter.go
Outdated
| } | ||
|
|
||
| // ensureEndsWithPunctuation ensures that the last leaf of a paragraph node ends with punctuation. | ||
| func ensureEndsWithPunctuation(node *SlateNode) { |
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.
ini slate node bisa dibikin jadi method yang receivernya slateNode
No description provided.