Obsidian Enhancing Export

repository·main·Indexed 19 days ago

https://github.com/mokeyish/obsidian-enhancing-export

A plugin for Obsidian version 1.11.1 that leverages Pandoc to export notes into formats such as HTML, DOCX, ePub, PDF, LaTeX, and Markdown (including Hugo). It supports custom export commands using dynamic variables for paths and metadata, as well as the ability to execute arbitrary shell commands via custom export settings.

Tokens
6.6K
Snippets
15
Records
26
Agent score
68%

What's inside obsidian-enhancing-export

  1. Install Obsidian Enhancing Export

    main

    To use this plugin, you must have pandoc installed on your system and then install the plugin within Obsidian.

    1. Install Pandoc: Install the latest version of pandoc (3.1.9 or higher). You can find installation instructions at https://pandoc.org/installing.html.
    2. Configure Pandoc Path: Either add the pandoc executable to your system's PATH environment variable, or provide the absolute path to the pandoc executable in the plugin's setting view within Obsidian.
    3. Install Plugin: In Obsidian, search for obsidian-enhancing-export in the Community Plugins gallery and install it.
  2. Available Export Variables

    main

    When defining export templates or commands, you can use several built-in variables to reference file paths and metadata. These variables are resolved at runtime.

    Output Path Variables

    • ${outputDir}: The directory where the output will be saved.
    • ${outputPath}: The full path to the output file.
    • ${outputFileName}: The name of the output file without the extension.
    • ${outputFileFullName}: The name of the output file including the extension.

    Current File Variables

    • ${currentDir}: The directory of the current Obsidian file.
    • ${currentPath}: The full path to the current Obsidian file.
    • ${currentFileName}: The name of the current file without the extension.
    • ${currentFileFullName}: The name of the current file including the extension.

    Other Variables

    • ${attachmentFolderPath}: Path to the attachments folder.
    • ${pluginDir}: The directory where the plugin is installed.
    • ${luaDir}: The directory for Lua scripts.
    • ${vaultDir}: The root directory of the Obsidian vault.
    • ${embedDirs}: Directories used for embedding.
    • ${env}: A record of environment variables.
    • ${options}: A record of custom options.
  3. Variables available during export

    main

    When using custom export commands or Pandoc templates, you can use specific variables to dynamically reference file paths, directories, and metadata. These variables are injected into the command template before execution.

    • ${outputDir}: The directory where the exported file will be saved.
    • ${outputPath}: The full path to the exported file.
    • ${outputFileName}: The filename without the extension.
    • ${outputFileFullName}: The filename including the extension.
    • ${currentDir}: The directory containing the current Obsidian file.
    • ${currentPath}: The full path to the current Obsidian file.
    • ${currentFileName}: The basename of the current file.
    • ${currentFileFullName}: The full name of the current file (including extension).

    Environment and Metadata

    • ${vaultDir}: The root directory of the Obsidian vault.
    • ${attachmentFolderPath}: The path to the folder where attachments are stored.
    • ${embedDirs}: A delimited list of directories containing files embedded in the current note.
    • ${metadata}: The frontmatter object of the current file.
    • ${options}: The options object passed to the export function.
    • ${fromFormat}: The source format (e.g., markdown or markdown+wikilinks_title_after_pipe).
  4. Configure Universal Export Plugin Settings

    main

    The UniversalExportPluginSettings interface defines the global configuration for the plugin. Key settings include:

    • pandocPath: Path to the Pandoc executable (supports platform-specific values).
    • defaultExportDirectoryMode: Determines how the export directory is chosen. Options: 'Auto', 'Same', or 'Custom'.
    • customDefaultExportDirectory: The directory used when mode is set to 'Custom'.
    • env: Environment variables used during export (supports platform-specific values).
    • items: An array of ExportSetting objects defining specific export commands.
    • showOverwriteConfirmation: Whether to prompt before overwriting existing files.
    • showExportProgressBar: Whether to display a progress bar during export.
    • openExportedFile: Whether to open the exported file immediately after completion.
    • openExportedFileLocation: Whether to open the folder containing the exported file after completion.
  5. Use variables in custom export commands

    main

    When defining custom export commands, you can use ${variable} syntax to dynamically inject paths and metadata. This allows you to control output locations and file naming based on the current file or vault context.

    Available Variables

    KeyDescription
    ${outputPath}The full path of the output file after export.
    ${outputDir}The directory containing the exported file.
    ${outputFileName}The filename of the exported file without its extension.
    ${outputFileFullName}The filename of the exported file including its extension.
    ${currentPath}The full path of the currently active file in Obsidian.
    ${currentDir}The directory of the currently active file.
    ${currentFileName}The filename of the currently active file without its extension.
    ${currentFileFullName}The filename of the currently active file including its extension.
    ${vaultDir}The root directory of your current Obsidian vault.
    ${attachmentFolderPath}The configured attachment folder path in Obsidian.
    ${embedDirs}A string containing directories of embedded files (useful for --resource-path= arguments).
    ${metadata.keyword}Any custom key-value pair defined in your file's YAML Front Matter.
  6. Variables Reference for custom commands

    main

    When defining a Custom export command, you can use the following variables to dynamically inject paths and filenames. You can also reference custom variables defined in your file's YAML Front Matter using the ${metadata.keyword} syntax.

    | Variable Name | Value Description |
    | --- | --- |
    | `${outputPath}` | The full export path (e.g., `/User/aaa/Documents/test.pdf`) |
    | `${outputDir}` | The directory of the export (e.g., `/User/aaa/Documents`) |
    | `${outputFileName}` | The filename without extension (e.g., `test`) |
    | `${outputFileFullName}` | The full filename with extension (e.g., `test.pdf`) |
    | `${currentPath}` | The full path of the current file (e.g., `/User/aaa/Documents/readme.md`) |
    | `${currentDir}` | The directory of the current file (e.g., `/User/aaa/Documents`) |
    | `${currentFileName}` | The current filename without extension (e.g., `readme`) |
    | `${currentFileFullName}` | The current filename with extension (e.g., `readme.md`) |
    | `${vaultDir}` | The current Obsidian vault directory |
    | `${attachmentFolderPath}` | The Obsidian attachment directory |
    | `${metadata.keyword}` | A custom variable defined in YAML Front Matter (where `keyword` is the key) |
  7. Use Obsidian Enhancing Export commands

    main

    The plugin provides two primary commands to initiate the export process from Obsidian:

    1. Export to Oo: Opens the ExportDialog for the currently active file, allowing you to choose export settings.
    2. Export with Previous: Attempts to immediately perform an export using the lastExportType and lastExportDirectory stored in your settings. If no previous export configuration exists, it falls back to opening the ExportDialog.

    These commands can be triggered via the Obsidian Command Palette.

    /* Command IDs for programmatic access or reference */
    // obsidian-enhancing-export:export
    // obsidian-enhancing-export:export-with-previous
  8. Manage plugin settings

    main

    The plugin manages settings through the UniversalExportPluginSettings interface. Key capabilities include:

    • Automatic Saving: Settings are debounced (1000ms) to prevent excessive disk writes during configuration changes.
    • Resetting Settings: You can revert settings to their defaults using the resetSettings() method. Note that lastExportDirectory is preserved during a reset.
    • Configuration UI: A dedicated settings tab is provided via ExportSettingTab to manage export items and environment variables.
  9. Define Pandoc Export Settings

    main

    A PandocExportSetting is used to configure exports that rely on Pandoc. It extends common settings with Pandoc-specific parameters.

    Required Fields:

    • name: A unique name for the export command.
    • type: Must be set to 'pandoc'.
    • arguments: The command-line arguments passed to Pandoc.
    • extension: The file extension for the output (e.g., pdf, docx).

    Optional Fields:

    • customArguments: Additional arguments.
    • runCommand: If true, runs a specific command after the export is finished.
    • command: The command to run after export.
    • openExportedFile: Open the file after export.
    • openExportedFileLocation: Open the file's location after export.
    • optionsMeta: Metadata for UI-based option selection.
  10. Implement a custom editor for PropertyGrid

    main

    If the built-in editors (checkbox, textInput, dropdown, fileSelectDialog) do not meet your needs, you can provide a customEditor function via PropertyGridProps.

    The customEditor function receives the control's meta and an onChange callback. If your function returns a valid JSX element, it will be rendered instead of the default editor for that specific key.

    // Example of a custom editor implementation
    const myCustomEditor = (meta: AnyPropertyGridControl, onChange?: (value: unknown) => void) => {
      if (meta.type === 'textInput') {
        return <input type="color" onChange={(e) => onChange?.(e.target.value)} />;
      }
      return undefined;
    };
    
    <PropertyGrid 
      meta={meta} 
      customEditor={myCustomEditor} 
      onChange={(obj, key) => console.log(`Changed ${key}:`, obj)} 
    />