mirror of
https://github.com/mfontanini/presenterm.git
synced 2025-05-05 23:42:59 +00:00
fix: remove hard-fixed presentation width, resolve reviews
This commit is contained in:
parent
76561b1281
commit
6ff8e87924
@ -2,7 +2,7 @@ use crate::{
|
|||||||
MarkdownParser, Resources,
|
MarkdownParser, Resources,
|
||||||
code::execute::SnippetExecutor,
|
code::execute::SnippetExecutor,
|
||||||
config::{KeyBindingsConfig, PauseExportPolicy},
|
config::{KeyBindingsConfig, PauseExportPolicy},
|
||||||
export::output::{ExportRenderer, OutputType},
|
export::output::{ExportRenderer, OutputFormat},
|
||||||
markdown::{parse::ParseError, text_style::Color},
|
markdown::{parse::ParseError, text_style::Color},
|
||||||
presentation::{
|
presentation::{
|
||||||
Presentation,
|
Presentation,
|
||||||
@ -102,7 +102,7 @@ impl<'a> Exporter<'a> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
presentation_path: &Path,
|
presentation_path: &Path,
|
||||||
output_directory: OutputDirectory,
|
output_directory: OutputDirectory,
|
||||||
renderer: OutputType,
|
renderer: OutputFormat,
|
||||||
) -> Result<ExportRenderer, ExportError> {
|
) -> Result<ExportRenderer, ExportError> {
|
||||||
let content = fs::read_to_string(presentation_path).map_err(ExportError::ReadPresentation)?;
|
let content = fs::read_to_string(presentation_path).map_err(ExportError::ReadPresentation)?;
|
||||||
let elements = self.parser.parse(&content)?;
|
let elements = self.parser.parse(&content)?;
|
||||||
@ -150,7 +150,7 @@ impl<'a> Exporter<'a> {
|
|||||||
Self::validate_weasyprint_exists()?;
|
Self::validate_weasyprint_exists()?;
|
||||||
Self::log("weasyprint installation found")?;
|
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 {
|
let pdf_path = match output_path {
|
||||||
Some(path) => path.to_path_buf(),
|
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
|
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 {
|
let output_path = match output_path {
|
||||||
Some(path) => path.to_path_buf(),
|
Some(path) => path.to_path_buf(),
|
||||||
|
@ -124,21 +124,21 @@ impl ContentManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum OutputType {
|
pub(crate) enum OutputFormat {
|
||||||
Pdf,
|
Pdf,
|
||||||
Html,
|
Html,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct ExportRenderer {
|
pub(crate) struct ExportRenderer {
|
||||||
content_manager: ContentManager,
|
content_manager: ContentManager,
|
||||||
output_type: OutputType,
|
output_type: OutputFormat,
|
||||||
dimensions: WindowSize,
|
dimensions: WindowSize,
|
||||||
html_body: String,
|
html_body: String,
|
||||||
background_color: Option<String>,
|
background_color: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExportRenderer {
|
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);
|
let image_manager = ContentManager::new(output_directory);
|
||||||
Self {
|
Self {
|
||||||
content_manager: image_manager,
|
content_manager: image_manager,
|
||||||
@ -218,11 +218,12 @@ impl ExportRenderer {
|
|||||||
}}"
|
}}"
|
||||||
);
|
);
|
||||||
let html_script = match self.output_type {
|
let html_script = match self.output_type {
|
||||||
OutputType::Pdf => String::new(),
|
OutputFormat::Pdf => String::new(),
|
||||||
OutputType::Html => {
|
OutputFormat::Html => {
|
||||||
format!(
|
format!(
|
||||||
"
|
"
|
||||||
<script>
|
<script>
|
||||||
|
let originalWidth = {width};
|
||||||
{script}
|
{script}
|
||||||
</script>"
|
</script>"
|
||||||
)
|
)
|
||||||
@ -246,7 +247,7 @@ impl ExportRenderer {
|
|||||||
let html_path = self.content_manager.persist_file("index.html", html.as_bytes())?;
|
let html_path = self.content_manager.persist_file("index.html", html.as_bytes())?;
|
||||||
|
|
||||||
match self.output_type {
|
match self.output_type {
|
||||||
OutputType::Pdf => {
|
OutputFormat::Pdf => {
|
||||||
ThirdPartyTools::weasyprint(&[
|
ThirdPartyTools::weasyprint(&[
|
||||||
"--presentational-hints",
|
"--presentational-hints",
|
||||||
"-e",
|
"-e",
|
||||||
@ -256,7 +257,7 @@ impl ExportRenderer {
|
|||||||
])
|
])
|
||||||
.run()?;
|
.run()?;
|
||||||
}
|
}
|
||||||
OutputType::Html => {
|
OutputFormat::Html => {
|
||||||
fs::write(output_path, html.as_bytes())?;
|
fs::write(output_path, html.as_bytes())?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
function scaler() {
|
function scaler() {
|
||||||
var w = document.documentElement.clientWidth;
|
var w = document.documentElement.clientWidth;
|
||||||
let scaledAmount= w/829;
|
let scaledAmount= w/originalWidth;
|
||||||
document.querySelector("body").style.transform = `scale(${scaledAmount})`;
|
document.querySelector("body").style.transform = `scale(${scaledAmount})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ struct Cli {
|
|||||||
export_pdf: bool,
|
export_pdf: bool,
|
||||||
|
|
||||||
/// Export the presentation as a HTML rather than displaying it.
|
/// Export the presentation as a HTML rather than displaying it.
|
||||||
#[clap(short, long, group = "export")]
|
#[clap(long, group = "export")]
|
||||||
export_html: bool,
|
export_html: bool,
|
||||||
|
|
||||||
/// The path in which to store temporary files used when exporting.
|
/// The path in which to store temporary files used when exporting.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user