Skip to content
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

[Common Situation] Want to ignore a Str node that is wrapped by Link, BlockQuote etc #16

Closed
azu opened this issue May 12, 2021 · 5 comments · Fixed by #17
Closed

[Common Situation] Want to ignore a Str node that is wrapped by Link, BlockQuote etc #16

azu opened this issue May 12, 2021 · 5 comments · Fixed by #17

Comments

@azu
Copy link
Member

azu commented May 12, 2021

This is a common pattern. We want to provide this detection as a method.

        [Syntax.Str](node){
            if (helper.isChildNode(node, [Syntax.Link, "LinkReference", Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
                return;
            }
            // logics
        }

https://github.com/search?q=LinkReference+textlint&type=code

@azu
Copy link
Member Author

azu commented May 12, 2021

Context, We want to add a new node type like FootnoteReference, so the helper will support these changes.
textlint/textlint#767

@azu
Copy link
Member Author

azu commented May 12, 2021

What the naming of this helper method?

@azu
Copy link
Member Author

azu commented May 12, 2021

helper.isPlainText(Str): boolean ?
helper.isNotStyledText(Str): boolean ?

@azu
Copy link
Member Author

azu commented May 15, 2021

BlockQuote is an exception.

BlockQuote > Paragaph > Str

@azu
Copy link
Member Author

azu commented May 15, 2021

    isStrUnderParagraph(node: TxtNode): boolean {
        if (node.type !== ASTNodeTypes.Str) {
            return false;
        }
        if (node.parent?.type !== ASTNodeTypes.Paragraph) {
            return false;
        }
        const isInUncontrollableNode = this.isChildNode(node, [ASTNodeTypes.BlockQuote]);
        return !isInUncontrollableNode
    }

This is wanted logics.

@azu azu closed this as completed in #17 May 16, 2021
@azu azu changed the title Want to ignore a Str node in common situation. Want to ignore a Str node that is wrapped by Link, BlockQuote etc... in common situation. May 19, 2021
@azu azu changed the title Want to ignore a Str node that is wrapped by Link, BlockQuote etc... in common situation. [Common Situation] Want to ignore a Str node that is wrapped by Link, BlockQuote etc May 19, 2021
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 a pull request may close this issue.

1 participant