Is there any documentation on Outline.getOutlines?

Hello all!

Is there any documentation on Outline.getOutlines?

My searches have turned up nothing.

Any example scripts showing Outline.getOutlines in action?

Thanks!

Jim

I don’t know if this sheds light on reading the contents of another open outline (from the evaluation space of the front outline document):

(As in the Finding Outlines section of: Outline · GitBook)

(A possibly unfamiliar element is that we access the getOutlines() method from the Outline class (hence initial CAP) rather than from the outline instance of the editor object.)

(() => {
    "use strict";

    // Assuming that more than one TaskPaper 3 document
    // is open ...


    // ---------------- TASKPAPER CONTEXT ----------------

    const TaskPaperContext = editor => {
        const
            // outline = editor.outline,
            // idOfActiveDocOutline = outline.id,

            // Method of Outline class rather than an
            // outline instance, hence the upper case.
            allOutlines = Outline.getOutlines(),

            allIDs = allOutlines.map(o => o.id),
            secondOutline = Outline.getOutlineForID(
                allIDs[1]
            );

        // Rough peek at contents of another open outline ...
        return secondOutline.toString();
    };


    // ------------------- JXA CONTEXT -------------------
    const main = () => {
        // We evaluate the script in the front document,
        // while also referencing other documents (outlines)
        const
            taskpaper = Application("TaskPaper"),
            documents = taskpaper.documents,
            intDocs = documents.length;

        return 1 > intDocs ? (
            "No documents open in TaskPaper"
        ) : 2 > intDocs ? (
            "Demo needs more than one document open in TaskPaper"
        ) : (() => {
            const frontDoc = documents.at(0);

            return frontDoc.evaluate({
                script: `${TaskPaperContext}`
            });
        })();
    };

    return main();
})();
2 Likes

or, to recover the full text (bar tags) of another outline, if two or more are open, perhaps something like:

(() => {
    "use strict";

    const TaskPaperContext = () => {
        const main = () => {
            // eslint-disable-next-line no-undef
            const allOutlines = Outline.getOutlines();

            return 1 < allOutlines.length ? (
                allOutlines[1].root.children
                .flatMap(tpLinesForNode)
                .join("\n")
            ) : "Only one outline open in TP.";
        };

        // ------- GENERICS FOR TASKPAPER CONTEXT -------

        // tpLinesForNode :: TPNode -> [String]
        const tpLinesForNode = node =>
            foldTreeTP(
                x => xs => [
                    x.bodyString,
                    ...xs.flat().map(
                        s => `\t${s}`
                    )
                ]
            )(node);


        // foldTreeTP :: (TPNode -> [a] -> a) -> TPNode -> a
        const foldTreeTP = f => {
            // The catamorphism on TP3 trees. A summary
            // value obtained by a depth-first fold.
            const go = node => f(node)(
                node.children.map(go)
            );

            return go;
        };

        return main();
    };


    // ----------------------- JXA -----------------------
    const main = () => {
        const ws = Application("TaskPaper").windows;

        return ws.at(0).document.evaluate({
            script: `${TaskPaperContext}`
        });
    };

    return main();
})();
1 Like

Thank you @complexpoint ! I will start digging into these examples this weekend!