Skip to content

Commit 849d7cb

Browse files
authored
feat: caption cleanup + rust edition/version upgrade (#10)
- get rid of weird nox (no-export) system for handling captions - they're now attributes of links and tables - clippy cleanup (god bless let chains) - upgrade to latest rust stable version (1.91) - upgrade to 2024 edition - proper caption testing - update org-wasm deps -----commits start here: * apply caption cleanup this commit won't work because i've mixed up cargo edition upgrades. whoops! * apply edition upgrade + cargo fmt * comply with edition changes * implement clippy fixes * implement keyword elision suggestions * add caption tests and make table work * update versions * feat(org-wasm): update webpack deps
1 parent 77884a3 commit 849d7cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+786
-642
lines changed

.github/workflows/pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
- name: Install rust toolchain
6060
uses: dtolnay/rust-toolchain@stable
6161
with:
62-
toolchain: 1.81.0
62+
toolchain: 1.91.0
6363

6464
- name: Setup Node.js
6565
uses: actions/setup-node@v4

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install rust toolchain
2121
uses: dtolnay/rust-toolchain@stable
2222
with:
23-
toolchain: 1.81.0
23+
toolchain: 1.91.0
2424

2525
- name: Build
2626
run: cargo build --verbose

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ default-members=["crates/org-cli"]
66

77
[workspace.package]
88
version = "0.1.0"
9-
rust-version = "1.74" # also change in ci.yml
9+
rust-version = "1.91" # also change in ci.yml
1010
authors = ["Laith Bahodi <laithbahodi@gmail.com>"]
11-
edition = "2021"
11+
edition = "2024"
1212
homepage = "https://org-rust.pages.dev"
1313
repository = "https://github.com/hydrobeam/org-rust"
1414
readme = "README.org"

crates/org-cli/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "org-rust"
3-
version = "0.1.17"
3+
version = "0.1.18"
44
description = "CLI tool for converting Org-Mode documents to other formats"
55
keywords = ["org-mode", "parser"]
66
categories = ["command-line-utilities"]
@@ -30,8 +30,8 @@ clap = { version = "4.3.11", features=["derive"]}
3030
clap_complete = "4.3.2"
3131
clap_mangen = "0.2.14"
3232
serde = { version = "1.0.196", features=["derive"]}
33-
org-exporter = { version = "0.1.8", path = "../org-exporter", package = "org-rust-exporter" }
34-
org-parser = { version = "0.1.5", path = "../org-parser", package = "org-rust-parser" }
33+
org-exporter = { version = "0.1.9", path = "../org-exporter", package = "org-rust-exporter" }
34+
org-parser = { version = "0.1.6", path = "../org-parser", package = "org-rust-parser" }
3535

3636

3737
# [[bin]]

crates/org-cli/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::CommandFactory;
2-
use clap_complete::{generate_to, Shell};
2+
use clap_complete::{Shell, generate_to};
33
use std::{env, io};
44
include!("src/cli.rs");
55

crates/org-cli/src/cli.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ pub struct Cli {
3939
pub verbose: bool,
4040
}
4141

42-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Deserialize)]
42+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Deserialize, Default)]
4343
pub enum Backend {
44+
#[default]
4445
Html,
4546
Org,
4647
}
@@ -50,7 +51,7 @@ impl Backend {
5051
self,
5152
parsed: &org_parser::Parser,
5253
buf: &mut String,
53-
conf: ConfigOptions
54+
conf: ConfigOptions,
5455
) -> Result<(), Vec<org_exporter::ExportError>> {
5556
match self {
5657
Backend::Html => org_exporter::Html::export_tree(parsed, buf, conf),
@@ -65,9 +66,3 @@ impl Backend {
6566
}
6667
}
6768
}
68-
69-
impl Default for Backend {
70-
fn default() -> Self {
71-
Backend::Html
72-
}
73-
}

crates/org-cli/src/main.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use anyhow::bail;
22
use org_exporter::ConfigOptions;
3-
use std::fs::{self, read_to_string, OpenOptions};
4-
use std::io::{stdout, BufWriter, Read, Write};
3+
use std::fs::{self, OpenOptions, read_to_string};
4+
use std::io::{BufWriter, Read, Write, stdout};
55
use std::path::{Path, PathBuf};
66
use template::Template;
77
use types::{CliError, InpType, OutType};
88
use utils::{mkdir_recursively, relative_path_from};
99

1010
use clap::Parser;
1111

12-
mod template;
13-
use crate::cli::Backend;
1412
mod cli;
13+
mod template;
1514
mod types;
1615
mod utils;
1716

@@ -45,12 +44,12 @@ fn run() -> anyhow::Result<()> {
4544
None => config_params.backend,
4645
r => r,
4746
};
48-
let output_path = if cli_params.output == "" {
47+
let output_path = if cli_params.output.is_empty() {
4948
config_params.output
5049
} else {
5150
cli_params.output
5251
};
53-
let input_path = if cli_params.input == "" {
52+
let input_path = if cli_params.input.is_empty() {
5453
config_params.input
5554
} else {
5655
cli_params.input
@@ -62,10 +61,7 @@ fn run() -> anyhow::Result<()> {
6261
config_params.verbose
6362
};
6463

65-
let backend = match backend {
66-
Some(b) => b,
67-
None => Backend::default(),
68-
};
64+
let backend = backend.unwrap_or_default();
6965

7066
let f = Path::new(&input_path);
7167
if !f.exists() {
@@ -129,11 +125,11 @@ fn run() -> anyhow::Result<()> {
129125
// main loop to export files
130126
for file_path in &paths {
131127
if verbose {
132-
writeln!(stdout, "input: {}", file_path.display()).map_err(|e| CliError::from(e))?;
128+
writeln!(stdout, "input: {}", file_path.display()).map_err(CliError::from)?;
133129
}
134130
if file_path.extension().is_some_and(|x| x == "org") {
135131
let mut input_file = std::fs::File::open(file_path)
136-
.map_err(|e| CliError::from(e).with_path(&file_path))?;
132+
.map_err(|e| CliError::from(e).with_path(file_path))?;
137133
let _num_bytes = input_file.read_to_string(&mut file_contents).map_err(|e| {
138134
CliError::from(e)
139135
.with_path(file_path)
@@ -165,7 +161,7 @@ fn run() -> anyhow::Result<()> {
165161
let mut build_str = String::new();
166162
for e in err_vec {
167163
build_str.push_str(&e.to_string());
168-
build_str.push_str("\n");
164+
build_str.push('\n');
169165
}
170166
Err(CliError::new().with_cause(&build_str))?
171167
}
@@ -192,7 +188,7 @@ fn run() -> anyhow::Result<()> {
192188
// the destination we are writing to
193189
let mut full_output_path: PathBuf;
194190
match dest {
195-
OutType::File(ref output_file) => {
191+
OutType::File(output_file) => {
196192
full_output_path = output_file.to_path_buf();
197193
}
198194
OutType::Dir(dest_path) => {
@@ -210,7 +206,7 @@ fn run() -> anyhow::Result<()> {
210206
}
211207
}
212208

213-
mkdir_recursively(&full_output_path.parent().unwrap())?;
209+
mkdir_recursively(full_output_path.parent().unwrap())?;
214210
// truncate is needed to fully overwrite file contents
215211
OpenOptions::new()
216212
.create(true)
@@ -222,7 +218,7 @@ fn run() -> anyhow::Result<()> {
222218
.with_path(&full_output_path)
223219
.with_cause("error in writing to destination file")
224220
})?
225-
.write(exported_content.as_bytes())?;
221+
.write_all(exported_content.as_bytes())?;
226222

227223
if verbose {
228224
writeln!(
@@ -257,12 +253,12 @@ fn run() -> anyhow::Result<()> {
257253
" -- symlinked: {}\n",
258254
&full_output_path.canonicalize()?.display()
259255
)
260-
.map_err(|e| CliError::from(e))?;
256+
.map_err(CliError::from)?;
261257
}
262258
} else {
263259
fs::copy(file_path, &full_output_path).map_err(|e| {
264260
CliError::from(e)
265-
.with_path(&file_path)
261+
.with_path(file_path)
266262
.with_cause("error in copying file to destination")
267263
})?;
268264
if verbose {
@@ -271,7 +267,7 @@ fn run() -> anyhow::Result<()> {
271267
" -- copied: {}\n",
272268
&full_output_path.canonicalize()?.display()
273269
)
274-
.map_err(|e| CliError::from(e))?;
270+
.map_err(CliError::from)?;
275271
}
276272
}
277273
}

crates/org-cli/src/template.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a, 'template> Template<'a, 'template> {
6969
// ? => not greedy
7070
let re = regex::Regex::new(r#"\{\{\{(.*?)\}\}\}"#).unwrap();
7171
// collect all matches to {{{.*}}} regex - things we want to replace with keywords
72-
let mut captures = re.captures_iter(&self.template_contents).map(|capture| {
72+
let mut captures = re.captures_iter(self.template_contents).map(|capture| {
7373
let mtch = capture.get(1).unwrap();
7474
// we expand the range of the capture to include the {{{}}}
7575
(mtch.start() - 3, mtch.end() + 3, mtch.as_str().trim())
@@ -93,11 +93,11 @@ impl<'a, 'template> Template<'a, 'template> {
9393
local_items.push_str(&self.template_contents[begin..start]);
9494

9595
if extract == "content" {
96-
local_items.push_str(&self.exported_content);
96+
local_items.push_str(self.exported_content);
9797
} else if let Some(command) = Command::check(extract) {
9898
match command {
9999
Command::If(cond) => {
100-
if let Some(_) = self.p.keywords.get(&*cond) {
100+
if self.p.keywords.contains_key(cond) {
101101
local_items.push_str(&self.process_captures(
102102
captures,
103103
self.end,
@@ -194,8 +194,7 @@ impl<'a, 'template> Template<'a, 'template> {
194194
}
195195
}
196196
Command::Include(file) => {
197-
let include_path =
198-
relative_path_from(&self.template_path, Path::new(file))?;
197+
let include_path = relative_path_from(self.template_path, Path::new(file))?;
199198
let included_template = read_to_string(&include_path).map_err(|e| {
200199
CliError::from(e)
201200
.with_path(&include_path)

crates/org-cli/src/utils.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ pub fn mkdir_recursively(path: &Path) -> Result<(), CliError> {
4343
})
4444
}
4545

46-
pub fn relative_path_from<'a, 'b>(
47-
src: &'a Path,
48-
added: &'b Path,
49-
) -> Result<Cow<'b, Path>, CliError> {
46+
pub fn relative_path_from<'b>(src: &Path, added: &'b Path) -> Result<Cow<'b, Path>, CliError> {
5047
if added.is_relative() {
5148
Ok(src
5249
.parent()
@@ -60,10 +57,7 @@ pub fn relative_path_from<'a, 'b>(
6057
.map_err(|e| {
6158
CliError::from(e)
6259
.with_path(&src.parent().unwrap().join(added))
63-
.with_cause(&format!(
64-
"Failed to locate path from: {}",
65-
src.display()
66-
))
60+
.with_cause(&format!("Failed to locate path from: {}", src.display()))
6761
})?
6862
.into())
6963
} else {

crates/org-exporter/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "org-rust-exporter"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
description = "exporter for org mode documents parsed with `org-rust-parser`"
55

66
homepage.workspace = true
@@ -14,7 +14,7 @@ rust-version.workspace = true
1414
[dependencies]
1515
latex2mathml = "0.2.3"
1616
memchr = "2.5.0"
17-
org-parser = { version = "0.1.5", path = "../org-parser", package = "org-rust-parser" }
17+
org-parser = { version = "0.1.6", path = "../org-parser", package = "org-rust-parser" }
1818
phf = {version = "0.11.1", features = ["macros"]}
1919
thiserror = "1.0.63"
2020

0 commit comments

Comments
 (0)