fix: remove hard-fixed presentation width, resolve reviews

This commit is contained in:
KyleUltimate 2025-04-25 17:47:55 +08:00
parent 76561b1281
commit 6ff8e87924
4 changed files with 14 additions and 13 deletions

View File

@ -2,7 +2,7 @@ use crate::{
MarkdownParser, Resources,
code::execute::SnippetExecutor,
config::{KeyBindingsConfig, PauseExportPolicy},
export::output::{ExportRenderer, OutputType},
export::output::{ExportRenderer, OutputFormat},
markdown::{parse::ParseError, text_style::Color},
presentation::{
Presentation,
@ -102,7 +102,7 @@ impl<'a> Exporter<'a> {
&mut self,
presentation_path: &Path,
output_directory: OutputDirectory,
renderer: OutputType,
renderer: OutputFormat,
) -> Result<ExportRenderer, ExportError> {
let content = fs::read_to_string(presentation_path).map_err(ExportError::ReadPresentation)?;
let elements = self.parser.parse(&content)?;
@ -150,7 +150,7 @@ impl<'a> Exporter<'a> {
Self::validate_weasyprint_exists()?;
Self::log("weasyprint installation found")?;
let render = self.build_renderer(presentation_path, output_directory, OutputType::Pdf)?;
let render = self.build_renderer(presentation_path, output_directory, OutputFormat::Pdf)?;
let pdf_path = match output_path {
Some(path) => path.to_path_buf(),
@ -180,7 +180,7 @@ impl<'a> Exporter<'a> {
self.dimensions.rows, self.dimensions.columns, self.dimensions.width, self.dimensions.height
);
let render = self.build_renderer(presentation_path, output_directory, OutputType::Html)?;
let render = self.build_renderer(presentation_path, output_directory, OutputFormat::Html)?;
let output_path = match output_path {
Some(path) => path.to_path_buf(),

View File

@ -124,21 +124,21 @@ impl ContentManager {
}
}
pub(crate) enum OutputType {
pub(crate) enum OutputFormat {
Pdf,
Html,
}
pub(crate) struct ExportRenderer {
content_manager: ContentManager,
output_type: OutputType,
output_type: OutputFormat,
dimensions: WindowSize,
html_body: String,
background_color: Option<String>,
}
impl ExportRenderer {
pub(crate) fn new(dimensions: WindowSize, output_directory: OutputDirectory, output_type: OutputType) -> Self {
pub(crate) fn new(dimensions: WindowSize, output_directory: OutputDirectory, output_type: OutputFormat) -> Self {
let image_manager = ContentManager::new(output_directory);
Self {
content_manager: image_manager,
@ -218,11 +218,12 @@ impl ExportRenderer {
}}"
);
let html_script = match self.output_type {
OutputType::Pdf => String::new(),
OutputType::Html => {
OutputFormat::Pdf => String::new(),
OutputFormat::Html => {
format!(
"
<script>
let originalWidth = {width};
{script}
</script>"
)
@ -246,7 +247,7 @@ impl ExportRenderer {
let html_path = self.content_manager.persist_file("index.html", html.as_bytes())?;
match self.output_type {
OutputType::Pdf => {
OutputFormat::Pdf => {
ThirdPartyTools::weasyprint(&[
"--presentational-hints",
"-e",
@ -256,7 +257,7 @@ impl ExportRenderer {
])
.run()?;
}
OutputType::Html => {
OutputFormat::Html => {
fs::write(output_path, html.as_bytes())?;
}
}

View File

@ -15,7 +15,7 @@ document.addEventListener('DOMContentLoaded', function() {
function scaler() {
var w = document.documentElement.clientWidth;
let scaledAmount= w/829;
let scaledAmount= w/originalWidth;
document.querySelector("body").style.transform = `scale(${scaledAmount})`;
}

View File

@ -72,7 +72,7 @@ struct Cli {
export_pdf: bool,
/// Export the presentation as a HTML rather than displaying it.
#[clap(short, long, group = "export")]
#[clap(long, group = "export")]
export_html: bool,
/// The path in which to store temporary files used when exporting.