Skip to content

Commit 96c218c

Browse files
committed
Wire up the new spx2html implementation in the main engine
1 parent 2dad0f8 commit 96c218c

4 files changed

Lines changed: 11 additions & 155 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ tectonic_bridge_icu = "2c1ffcd702a662c003bd3d7d0ca4d169784cb6ad"
140140
tectonic_bundles = "207e6e796b1827330ee03a4c395fe6db059bddd9"
141141
tectonic_cfg_support = "thiscommit:aeRoo7oa"
142142
tectonic_dep_support = "5faf4205bdd3d31101b749fc32857dd746f9e5bc"
143-
tectonic_docmodel = "cd77b60d48b1ae3ef80d708e6858ea91cd9fa812"
143+
tectonic_docmodel = "thiscommit:2022-02-20:2SpEl4c"
144144
tectonic_engine_bibtex = "thiscommit:2021-01-17:KuhaeG1e"
145145
tectonic_engine_spx2html = "thiscommit:2021-10-29:96yOlD8"
146146
tectonic_engine_xdvipdfmx = "7dcbc52e58f9774b3d592919a9105377faeac509"
147-
tectonic_engine_xetex = "b7a4085fa67c831d4532da6661bddafd1f9c24ff"
147+
tectonic_engine_xetex = "thiscommit:2022-02-20:J4dXT3x"
148148
tectonic_errors = "317ae79ceaa2593fb56090e37bf1f5cc24213dd9"
149149
tectonic_geturl = "68c5fc525c5fead75913bd90380043761bde9f61"
150150
tectonic_io_base = "thiscommit:2021-06-13:XFjtSsZ"

src/docmodel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl DocumentExt for Document {
136136
})?;
137137

138138
let output_format = match profile.target_type {
139+
BuildTargetType::Html => OutputFormat::Html,
139140
BuildTargetType::Pdf => OutputFormat::Pdf,
140141
};
141142

src/driver.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,10 +1851,15 @@ impl ProcessingSession {
18511851
}
18521852

18531853
fn spx2html_pass(&mut self, status: &mut dyn StatusBackend) -> Result<i32> {
1854+
let op = match self.output_path {
1855+
Some(ref p) => p,
1856+
None => return Err(errmsg!("HTML output must be saved directly to disk")),
1857+
};
1858+
18541859
{
1855-
let mut engine = Spx2HtmlEngine::new();
1860+
let mut engine = Spx2HtmlEngine::default();
18561861
status.note_highlighted("Running ", "spx2html", " ...");
1857-
engine.process(&mut self.bs, status, &self.tex_xdv_path)?;
1862+
engine.process_to_filesystem(&mut self.bs, status, &self.tex_xdv_path, op)?;
18581863
}
18591864

18601865
self.bs.mem.files.borrow_mut().remove(&self.tex_xdv_path);

src/engines/spx2html.rs

Lines changed: 1 addition & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,4 @@
11
// Copyright 2018-2021 the Tectonic Project
22
// Licensed under the MIT License.
33

4-
//! Convert Tectonic’s SPX format to HTML
5-
//!
6-
//! Yay, an engine actually written in pure Rust!
7-
8-
use std::io::Write;
9-
use tectonic_bridge_core::DriverHooks;
10-
use tectonic_xdv::{FileType, XdvEvents, XdvParser};
11-
12-
use crate::errors::{Error, Result};
13-
use crate::io::{OpenResult, OutputHandle};
14-
use crate::status::StatusBackend;
15-
use crate::{errmsg, tt_warning};
16-
17-
#[derive(Default)]
18-
pub struct Spx2HtmlEngine {}
19-
20-
impl Spx2HtmlEngine {
21-
pub fn new() -> Spx2HtmlEngine {
22-
Default::default()
23-
}
24-
25-
pub fn process(
26-
&mut self,
27-
hooks: &mut dyn DriverHooks,
28-
status: &mut dyn StatusBackend,
29-
spx: &str,
30-
) -> Result<()> {
31-
let mut input = hooks.io().input_open_name(spx, status).must_exist()?;
32-
33-
// FIXME? The engine should probably be responsible for choosing this.
34-
let outname = {
35-
let mut s = spx.to_owned();
36-
37-
if spx.ends_with(".spx") {
38-
let l = s.len();
39-
s.truncate(l - 4);
40-
}
41-
42-
s.push_str(".html");
43-
s
44-
};
45-
46-
{
47-
let state = State::new(outname, hooks, status);
48-
let (state, _n_bytes) = XdvParser::process(&mut input, state)?;
49-
state.finished();
50-
}
51-
52-
let (name, digest_opt) = input.into_name_digest();
53-
hooks.event_input_closed(name, digest_opt, status);
54-
Ok(())
55-
}
56-
}
57-
58-
struct State<'a> {
59-
outname: String,
60-
hooks: &'a mut dyn DriverHooks,
61-
status: &'a mut dyn StatusBackend,
62-
cur_output: Option<OutputHandle>,
63-
warned_lost_chars: bool,
64-
buf: Vec<u8>,
65-
}
66-
67-
impl<'a> State<'a> {
68-
pub fn new(
69-
outname: String,
70-
hooks: &'a mut dyn DriverHooks,
71-
status: &'a mut dyn StatusBackend,
72-
) -> Self {
73-
Self {
74-
outname,
75-
hooks,
76-
status,
77-
cur_output: None,
78-
warned_lost_chars: false,
79-
buf: Vec::new(),
80-
}
81-
}
82-
}
83-
84-
#[inline(always)]
85-
fn as_printable_ascii(c: i32) -> Option<u8> {
86-
if c > 0x20 && c < 0x7F {
87-
Some(c as u8)
88-
} else {
89-
None
90-
}
91-
}
92-
93-
impl<'a> State<'a> {
94-
pub fn finished(self) {
95-
if let Some(oh) = self.cur_output {
96-
let (name, digest) = oh.into_name_digest();
97-
self.hooks.event_output_closed(name, digest, self.status);
98-
}
99-
}
100-
}
101-
102-
impl<'a> XdvEvents for State<'a> {
103-
type Error = Error;
104-
105-
fn handle_header(&mut self, filetype: FileType, _comment: &[u8]) -> Result<()> {
106-
if filetype != FileType::Spx {
107-
return Err(errmsg!("file should be SPX format but got {}", filetype));
108-
}
109-
110-
self.cur_output = Some(match self.hooks.io().output_open_name(&self.outname) {
111-
OpenResult::Ok(h) => h,
112-
OpenResult::NotAvailable => {
113-
return Err(errmsg!("no way to write output file \"{}\"", self.outname));
114-
}
115-
OpenResult::Err(e) => {
116-
return Err(e.into());
117-
}
118-
});
119-
120-
Ok(())
121-
}
122-
123-
fn handle_char_run(&mut self, chars: &[i32]) -> Result<()> {
124-
let dest = match self.cur_output {
125-
Some(ref mut h) => h,
126-
None => {
127-
if !self.warned_lost_chars {
128-
tt_warning!(
129-
self.status,
130-
"losing characters in SPX file: no current output"
131-
);
132-
self.warned_lost_chars = true;
133-
}
134-
135-
return Ok(());
136-
}
137-
};
138-
139-
self.buf.clear();
140-
141-
for c in chars.iter() {
142-
if let Some(b) = as_printable_ascii(*c) {
143-
self.buf.push(b);
144-
}
145-
}
146-
147-
if !self.buf.is_empty() {
148-
self.buf.push(0x0a); // newline
149-
dest.write_all(&self.buf)?;
150-
}
151-
152-
Ok(())
153-
}
154-
}
4+
pub use tectonic_engine_spx2html::Spx2HtmlEngine;

0 commit comments

Comments
 (0)