Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub mod windows_setup;
const SIMPLE_CSS: &str = include_str!("../assets/simple.min.css");
const APP_DISPLAY_NAME: &str = "mdo";
const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const SETUP_SAMPLE_FILE_NAME: &str = "welcome-to-open-as-html-with-mdo.md";
pub const SETUP_SAMPLE_MARKDOWN: &str = "\
const SETUP_SAMPLE_FILE_NAME: &str = "welcome-to-open-as-html-with-mdo.md";
const SETUP_SAMPLE_MARKDOWN: &str = "\
# Welcome to the world of Open as HTML with mdo

If you are reading this in your browser, mdo rendered Markdown as HTML and
Expand Down Expand Up @@ -135,10 +135,6 @@ const THEME_TOGGLE: &str = r#"<style id="mdo-theme-toggle">
"#;
// ─── END THEME TOGGLE ──────────────────────────────────────────────────

pub fn derive_output(input: &Path) -> PathBuf {
input.with_extension("html")
}

/// Stable per-source-path location under a private temp/cache dir, e.g.
/// `%TEMP%\mdo-<uid>\<hash>\<stem>.html`. Re-opening the same source
/// overwrites the same file rather than accumulating new ones.
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use std::time::Duration;

use clap::Parser;
use mdo_cli::{
convert, derive_output, file_manager, launch_browser, open_setup_sample, temp_output_for,
ConvertOutcome, ConvertRequest, RenderError, StageTimings,
convert, file_manager, launch_browser, open_setup_sample, temp_output_for, ConvertOutcome,
ConvertRequest, RenderError, StageTimings,
};
use notify::{recommended_watcher, EventKind, RecursiveMode, Watcher};

Expand Down Expand Up @@ -395,7 +395,7 @@ fn main() -> notify::Result<()> {
std::process::exit(1);
}
},
(None, false) => (derive_output(&input), false),
(None, false) => (input.with_extension("html"), false),
};

// Register the watch BEFORE the initial render so a save that lands
Expand Down
34 changes: 10 additions & 24 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use std::path::PathBuf;
use std::process::Command;
use std::time::{SystemTime, UNIX_EPOCH};

#[cfg(target_os = "linux")]
use mdo_cli::temp_output_for;

#[cfg(unix)]
use std::time::{Duration, Instant};

#[cfg(target_os = "linux")]
use std::hash::{Hash, Hasher};
#[cfg(target_os = "linux")]
use std::os::unix::fs::{symlink, PermissionsExt};

Expand Down Expand Up @@ -570,7 +571,7 @@ fn open_output_refuses_precreated_symlink() {
fs::write(&input, "# Safe\n\nreplacement").expect("failed to write markdown fixture");
fs::write(&target, "do not overwrite").expect("failed to write symlink target");

let output_path = temp_output_for_test(&input);
let output_path = temp_output_for(&input).expect("failed to compute expected temp output path");
fs::create_dir_all(
output_path
.parent()
Expand Down Expand Up @@ -614,24 +615,6 @@ fn open_output_refuses_precreated_symlink() {
fs::remove_dir_all(dir).expect("failed to clean up temp fixture dir");
}

#[cfg(target_os = "linux")]
fn temp_output_for_test(input: &std::path::Path) -> PathBuf {
let canonical = fs::canonicalize(input).unwrap_or_else(|_| input.to_path_buf());
let mut hasher = std::collections::hash_map::DefaultHasher::new();
canonical.hash(&mut hasher);
let hash = hasher.finish();

let stem = input
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("document");

std::env::temp_dir()
.join(format!("mdo-{}", unsafe { libc::geteuid() }))
.join(format!("{hash:016x}"))
.join(format!("{stem}.html"))
}

/// An empty directory suitable for use as `PATH` when a test needs to make
/// sure no desktop opener (xdg-open, gio, ...) can be found on it.
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -671,7 +654,8 @@ fn open_launch_failure_exits_nonzero_and_reports_path() {
"stderr should report the launch failure: {stderr}"
);

let rendered_path = temp_output_for_test(&input);
let rendered_path =
temp_output_for(&input).expect("failed to compute expected temp output path");
assert!(
stderr.contains(
rendered_path
Expand Down Expand Up @@ -721,7 +705,8 @@ fn open_success_exits_zero() {
"mdo --open should exit zero when render and launch both succeed: {output:?}"
);

let rendered_path = temp_output_for_test(&input);
let rendered_path =
temp_output_for(&input).expect("failed to compute expected temp output path");
assert!(rendered_path.exists());

fs::remove_dir_all(rendered_path.parent().expect("rendered path has a parent"))
Expand Down Expand Up @@ -764,7 +749,8 @@ fn open_reports_failure_when_opener_exits_nonzero() {
"stderr should report the launch failure: {stderr}"
);

let rendered_path = temp_output_for_test(&input);
let rendered_path =
temp_output_for(&input).expect("failed to compute expected temp output path");
assert!(
rendered_path.exists(),
"rendered output should survive an opener failure"
Expand Down
Loading