dillionmegida / gatsby-remark-liquid-tags

📍 A template plugin used for custom embeds in markdowns.
MIT License
10 stars 5 forks source link

return nothing #6

Closed muescha closed 4 years ago

muescha commented 4 years ago

https://github.com/dillionmegida/gatsby-remark-liquid-tags/blob/f1c4b5fa4d7217a670298f7a73209bb013354a11/src/index.js#L58

should this be:

- if (embed === undefined) return text; 
+ if (embed === undefined) return; 

because the visitor expect to return void or other values, but not string:

https://github.com/syntax-tree/unist-util-visit/blob/main/types/index.d.ts#L38-L42

  type Visitor<V extends Node> = (
    node: V,
    index: number,
    parent: Parent | undefined
  ) => void | Action | Index | ActionTuple
dillionmegida commented 4 years ago

Thank you so much for your contributions. (This and the others)

The idea here for returning the text was that if the embed option does not exist, return the text as-is

For example, the twitter option doesn't exist, so any liquid tag in this form:

{% twitter...

Would return the text.

I would appreciate your suggestions on the workarounds for this.

muescha commented 4 years ago

a return a text value does not change the visited node.

you change nodes only with manipulating the node or the AST

you can test this by changing it to:

if (embed === undefined) return "not found";

but it not display the not found in text

muescha commented 4 years ago

see:

muescha commented 4 years ago

FYI: docs are here: https://github.com/syntax-tree/unist-util-visit-parents#next--visitornode-ancestors

dillionmegida commented 4 years ago

see:

  • 9 refactor index.js

yes, seen. Thank you