Skip to content

Conversation

@naluthfi
Copy link
Contributor

No description provided.

@naluthfi naluthfi force-pushed the feature/create-SerializeSlateToText branch from fa85990 to aa6280b Compare March 17, 2025 09:37
@naluthfi naluthfi force-pushed the feature/create-SerializeSlateToText branch from aa6280b to 54fc93a Compare March 17, 2025 09:45
return strings.TrimSpace(text), nil
}

// serializeNodes recursively processes nodes and their content into a plain-text format.
Copy link
Contributor

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

}

// Recursively process child nodes.
if len(node.Nodes) > 0 && node.Type != "heading-large" && node.Type != "caption" && node.Type != "figure" {
Copy link
Contributor

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

}

// SerializeSlateToText processes and formats a Slate document JSON string.
func SerializeSlateToText(documentJSON string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SerializeSlateToPlainText


// cleans up the serialized list by removing excessive punctuation.
func cleanUpList(text string) string {
cleaned := regexp.MustCompile(`\.+`).ReplaceAllString(text, _sentenceSeparator)
Copy link
Contributor

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

}

// Recursively process child nodes.
if len(node.Nodes) > 0 && node.Type != "heading-large" && node.Type != "caption" && node.Type != "figure" {
Copy link
Contributor

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


// Recursively process child nodes.
if len(node.Nodes) > 0 && node.Type != "heading-large" && node.Type != "caption" && node.Type != "figure" {
// modifiedNodeSeparator = getModifiedNodeSeparator(node.Type, nodeSeparator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bisa dihapus?

// modifiedNodeSeparator = getModifiedNodeSeparator(node.Type, nodeSeparator)
switch node.Type {
case "heading-medium":
return _sentenceSeparator
Copy link
Contributor

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

if len(node.Leaves) > 0 {
lastLeaf := node.Leaves[len(node.Leaves)-1]
if text := lastLeaf.Text; text != "" {
if !endsWithPunctuation(text) {
Copy link
Contributor

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}

Copy link
Contributor Author

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

@@ -0,0 +1,160 @@
package utils
Copy link
Collaborator

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?

)

// Leaf represents a text element with optional formatting.
type Leaf struct {
Copy link
Collaborator

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

return "", err
}

text := serializeNodes(wrappedDocument.Document.Nodes, _newline, _spaceSeparator)
Copy link
Collaborator

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

type SlateNode struct {
Object string `json:"object"`
Type string `json:"type"`
SlateNodes []SlateNode `json:"nodes,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ini nodes aja gasi?

SlateNodes []SlateNode `json:"nodes,omitempty"`
Leaves []SlateLeaf `json:"leaves,omitempty"`

isLastListElement bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isLastInList aja

}

// ToPlainText converts a Slate document into a plain-text format.
func (slateDocument *SlateDocument) ToPlainText() (string, error) {
Copy link
Collaborator

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

}

// serializeLeaves joins leaf texts with the specified separator.
func serializeLeaves(leaves []SlateLeaf, separator string) string {
Copy link
Collaborator

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

}

// ensureEndsWithPunctuation ensures that the last leaf of a paragraph node ends with punctuation.
func ensureEndsWithPunctuation(node *SlateNode) {
Copy link
Collaborator

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

@naluthfi naluthfi merged commit ee38cfe into master Apr 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants