Crate src2md

Crate src2md 

Source
Expand description

§src2md Library

This crate can be used to:

  • Collect all source/text files from a project and compile them into a Markdown file
  • Restore original source files back from a generated Markdown file
  • Clone and process git repositories (with the git feature)

§Features

  • git - Enables git repository cloning support via --git <url>

§Default Exclusions

The following are always excluded by default:

  • Hidden files and directories (starting with .)
  • Lock files (package-lock.json, yarn.lock, Cargo.lock, etc.)
  • Previous src2md output files

§Usage

§To generate a Markdown file:

use src2md::{Config, run_src2md};
use std::collections::HashSet;
use std::path::PathBuf;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let config = Config {
        output_path: PathBuf::from("output.md"),
        ignore_file: None,
        specific_paths: HashSet::new(),
        project_root: std::env::current_dir()?,
        restore_input: None,
        restore_path: None,
        verbosity: 0,
        fail_fast: true,
        extensions: HashSet::new(), // empty = include all
        #[cfg(feature = "git")]
        git_url: None,
        #[cfg(feature = "git")]
        git_branch: None,
    };

    run_src2md(config).await
}

§To restore files from a Markdown file:

use src2md::extract_from_markdown;
use std::path::PathBuf;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    extract_from_markdown(
        &PathBuf::from("generated.md"),
        Some(&PathBuf::from("restored/")),
    ).await
}

Re-exports§

pub use cli::Config;
pub use extractor::extract_from_markdown;
pub use filewalker::collect_files;
pub use writer::MarkdownWriter;
pub use writer::OUTPUT_MAGIC_BYTES;
pub use writer::OUTPUT_MAGIC_HEADER;

Modules§

cli
extractor
filewalker
utils
writer

Functions§

run_src2md
Generate a Markdown file from source/text files
run_src2md_on_path
Generate a Markdown file from a specific directory path.