kevboh / longform

A plugin for Obsidian that helps you write and edit novels, screenplays, and other long projects.
Other
610 stars 30 forks source link

Compile Step: Concatenate Headings only #236

Closed mac-obs closed 5 months ago

mac-obs commented 5 months ago

I'd like a step that combines all scenes together in one manuscript, but only uses the title of the scene (so the name of the .md files) and not the body. It would work just like the standard "Concatenate Text" but instead of the whole note it uses only the title of the scenes. (Maybe one could/should use the "preprend title" step before).

That would be useful for creating outline of the project you are currently working on (I use Longform for academic writing).

Maybe there is a smart workaround, that I didn't see yet. One way is to just use "Concatenate Text" and then use the native Obsidian outline function to see the outline of the manuscript.md. However, I would like to export the outline to PDF/.docx, which is not possible if the manuscript.md has not only the headings, but also all the text of the scenes.

This should effect join scenes.

kevboh commented 5 months ago

Interesting! Makes sense. FWIW, this should be a very simple user script step if you want to try yourself before I get to it.

kevboh commented 5 months ago

Here's a simple example. See the docs for more on how to use it.

module.exports = {
  description: {
    name: "Concatenate Headings",
    description:
      "Joins all scene titles together. Convenient for quickly making outlines.",
    availableKinds: ["Join"],
    options: [],
  },
  compile(scenes) {
    return {
      contents: scenes.map((s) => s.name).join("\n\n"),
    };
  },
};
mac-obs commented 5 months ago

Wow, thanks for putting this together so quickly. Works great! There is only one downside: You lose the hierarchy of the scenes, which is indicated by the scene’s indentation level. Normally I preserve this using prepend title, but that doesn't work (I guess because prepend title includes the title in the scene text and the text isn't using for compiling when we only concatenate headings). Would it be possible to preserve the outline leven?

Result atm: grafik

Would love to have: grafik

kevboh commented 5 months ago

Quick and dirty:

module.exports = {
  description: {
    name: "Concatenate Headings",
    description:
      "Joins all scene titles together. Convenient for quickly making outlines.",
    availableKinds: ["Join"],
    options: [],
  },
  compile(scenes) {
    return {
      contents: scenes
        .map((s) => {
          let n = "# " + s.name;
          for (let i = 0; i < s.indentationLevel; i++) {
            n = "#" + n;
          }
          return n;
        })
        .join("\n\n"),
    };
  },
};

I don't have time to make more tweaks, but I hope this is sufficient. If others comment here for this step I can add it to Longform proper. If you need more help tweaking it perhaps someone in the Obsidian Discord could help?

mac-obs commented 5 months ago

Works like a charm! Thank you so much!