1use std::fs;
12use std::io;
13use std::path::PathBuf;
14
15#[cfg(target_os = "android")]
16mod android;
17pub mod file_manager;
18pub mod handler;
19mod highlight;
20pub mod launch;
21pub mod page;
22pub mod render;
23pub mod temp_output;
24pub mod watch;
25#[cfg(target_os = "windows")]
26pub mod windows_setup;
27
28use temp_output::{ensure_private_dir, private_temp_root};
29
30pub use launch::launch_browser;
31pub use render::{
32 convert, render_markdown_document, ConvertOutcome, ConvertRequest, RenderError, StageTimings,
33};
34pub use temp_output::temp_output_for;
35
36const SETUP_SAMPLE_FILE_NAME: &str = "welcome-to-open-as-html-with-mdo.md";
37const SETUP_SAMPLE_MARKDOWN: &str = "\
38# Welcome to the world of Open as HTML with mdo
39
40If you are reading this in your browser, mdo rendered Markdown as HTML and
41opened it successfully.
42
43Next, right-click any `.md` file and choose **Open as HTML** to read it this way.
44If you make mdo your default Markdown app, a double-click does the same.
45";
46
47pub fn open_setup_sample() -> io::Result<()> {
48 let source = setup_sample_input_path()?;
49 fs::write(&source, SETUP_SAMPLE_MARKDOWN)?;
50
51 let output = temp_output_for(&source)?;
52 convert(ConvertRequest {
53 input: &source,
54 output: &output,
55 bare: false,
56 unsafe_html: false,
57 private_output: true,
58 css_override: None,
59 })
60 .map_err(io::Error::other)?;
61
62 launch_browser(&output)?;
63 Ok(())
64}
65
66fn setup_sample_input_path() -> io::Result<PathBuf> {
67 let root = private_temp_root();
68 ensure_private_dir(&root)?;
69
70 let dir = root.join("setup");
71 ensure_private_dir(&dir)?;
72 Ok(dir.join(SETUP_SAMPLE_FILE_NAME))
73}
74#[cfg(test)]
75mod tests {
76 use super::*;
77
78 #[test]
79 fn setup_sample_contains_welcome_copy() {
80 assert!(SETUP_SAMPLE_MARKDOWN.contains("# Welcome to the world of Open as HTML with mdo"));
81 assert!(SETUP_SAMPLE_MARKDOWN.contains("opened it successfully"));
82 assert_eq!(
83 SETUP_SAMPLE_FILE_NAME,
84 "welcome-to-open-as-html-with-mdo.md"
85 );
86 }
87}