Skip to content

Can't return value from RTF parser  #34

Description

@8483

Maybe I need a break from coding, but I really don't get why I can't retrieve the value from the function...

Can anyone please tell me what I'm doing wrong?

const parseRTF = require("rtf-parser");

let string = `{\\rtf1\\ansi\\deff0\\nouicompat{\\ etc...}`;

function convertRTFtoPlainText(string) {
    parseRTF.string(string, (err, doc) => {
        let result = "";

        doc.content.forEach((item) => {
            if (item.content) {
                item.content.forEach((span) => {
                    result += span.value;
                });
            }
        });

        console.log(result);           // <-------- Shows the converted string

        return result.trim();
    });
}

let value = convertRTFtoPlainText(string);   

console.log(value);                    // <-------- undefined

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions