mirror of
https://github.com/tommilligan/mdbook-admonish.git
synced 2025-12-28 14:58:48 -05:00
Compare commits
5 Commits
v1.16.0
...
better-err
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c18292401 | ||
|
|
294af2478c | ||
|
|
278d17792b | ||
|
|
9f6c73091a | ||
|
|
9f221abc12 |
10
.github/workflows/check.yml
vendored
10
.github/workflows/check.yml
vendored
@@ -7,6 +7,8 @@ jobs:
|
||||
fast-test:
|
||||
name: Fast test
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
CARGO_TARGET_DIR: "/tmp/cargo-install-target-dir"
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
@@ -17,6 +19,7 @@ jobs:
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
target
|
||||
/tmp/cargo-install-target-dir
|
||||
key: fast-test-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
|
||||
- name: Install toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
@@ -33,6 +36,8 @@ jobs:
|
||||
needs: fast-test
|
||||
name: Test main target
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
CARGO_TARGET_DIR: "/tmp/cargo-install-target-dir"
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
@@ -44,7 +49,7 @@ jobs:
|
||||
~/.cargo/git
|
||||
target
|
||||
~/.cargo/bin
|
||||
cargo_target
|
||||
/tmp/cargo-install-target-dir
|
||||
key: detailed-test-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
|
||||
- name: Install toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
@@ -95,6 +100,8 @@ jobs:
|
||||
experimental: false
|
||||
runs-on: ${{ matrix.os }}
|
||||
continue-on-error: ${{ matrix.experimental }}
|
||||
env:
|
||||
CARGO_TARGET_DIR: "/tmp/cargo-install-target-dir"
|
||||
steps:
|
||||
# This is required, otherwise we get files with CRLF on Windows
|
||||
# Which causes tests relying on data loaded from files to fail
|
||||
@@ -111,6 +118,7 @@ jobs:
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
target
|
||||
/tmp/cargo-install-target-dir
|
||||
key: test-${{ matrix.os }}-${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.toml') }}
|
||||
- name: Install toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
|
||||
7
.github/workflows/deploy.yml
vendored
7
.github/workflows/deploy.yml
vendored
@@ -37,6 +37,8 @@ jobs:
|
||||
os: windows-latest
|
||||
name: x86_64-pc-windows-msvc.zip
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
CARGO_TARGET_DIR: "/tmp/cargo-install-target-dir"
|
||||
steps:
|
||||
- name: Setup | Checkout
|
||||
uses: actions/checkout@v4
|
||||
@@ -48,6 +50,7 @@ jobs:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
/tmp/cargo-install-target-dir
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Setup | Rust
|
||||
@@ -132,6 +135,8 @@ jobs:
|
||||
name: Publish to crates.io
|
||||
needs: github_release
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
CARGO_TARGET_DIR: "/tmp/cargo-install-target-dir"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v3
|
||||
@@ -141,7 +146,7 @@ jobs:
|
||||
~/.cargo/git
|
||||
target
|
||||
~/.cargo/bin
|
||||
cargo_target
|
||||
/tmp/cargo-install-target-dir
|
||||
# We reuse the cache from our detailed test environment, if available
|
||||
key: detailed-test-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
|
||||
- name: Install toolchain
|
||||
|
||||
4
.github/workflows/docs.yml
vendored
4
.github/workflows/docs.yml
vendored
@@ -12,6 +12,8 @@ permissions:
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
CARGO_TARGET_DIR: "/tmp/cargo-install-target-dir"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v3
|
||||
@@ -21,7 +23,7 @@ jobs:
|
||||
~/.cargo/git
|
||||
target
|
||||
~/.cargo/bin
|
||||
cargo_target
|
||||
/tmp/cargo-install-target-dir
|
||||
# We reuse the cache from our detailed test environment, if available
|
||||
key: detailed-test-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
|
||||
- name: Install toolchain
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
## v1.16.0
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@
|
||||
</div>
|
||||
<div>
|
||||
<p>Failed with:</p>
|
||||
<pre><code class="language-log">TOML parsing error: TOML parse error at line 1, column 8
|
||||
<pre><code class="language-log">'title="' is not a valid directive or TOML key-value pair.
|
||||
|
||||
TOML parsing error: TOML parse error at line 1, column 8
|
||||
|
|
||||
1 | title="
|
||||
| ^
|
||||
|
||||
108
src/config/v2.rs
108
src/config/v2.rs
@@ -21,10 +21,8 @@ struct UserInput {
|
||||
fn bare_key_value_pairs_to_toml(pairs: &str) -> String {
|
||||
use regex::Captures;
|
||||
|
||||
static RX_BARE_KEY_ASSIGNMENT: Lazy<Regex> = Lazy::new(|| {
|
||||
let bare_key = r#"[A-Za-z0-9_-]+"#;
|
||||
Regex::new(&format!("(?:{bare_key}) *=")).expect("bare key assignment regex")
|
||||
});
|
||||
static RX_BARE_KEY_ASSIGNMENT: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r#"(?:[A-Za-z0-9_-]+) *="#).expect("bare key assignment regex"));
|
||||
|
||||
fn prefix_with_newline(captures: &Captures) -> String {
|
||||
format!(
|
||||
@@ -52,7 +50,7 @@ pub(crate) fn from_config_string(config_string: &str) -> Result<InstanceConfig,
|
||||
let config: UserInput = match toml::from_str(config_toml) {
|
||||
Ok(config) => config,
|
||||
Err(error) => {
|
||||
let original_error = Err(format!("TOML parsing error: {error}"));
|
||||
let original_error = format!("TOML parsing error: {error}");
|
||||
|
||||
// For ergonomic reasons, we allow users to specify the directive without
|
||||
// a key. So if parsing fails initially, take the first line,
|
||||
@@ -66,12 +64,14 @@ pub(crate) fn from_config_string(config_string: &str) -> Result<InstanceConfig,
|
||||
Lazy::new(|| Regex::new(r#"^[A-Za-z0-9_-]+$"#).expect("directive regex"));
|
||||
|
||||
if !RX_DIRECTIVE.is_match(directive) {
|
||||
return original_error;
|
||||
return Err(format!("'{directive}' is not a valid directive or TOML key-value pair.\n\n{original_error}"));
|
||||
}
|
||||
|
||||
let mut config: UserInput = match toml::from_str(config_toml) {
|
||||
Ok(config) => config,
|
||||
Err(_) => return original_error,
|
||||
Err(error) => {
|
||||
return Err(format!("TOML parsing error: {error}"));
|
||||
}
|
||||
};
|
||||
config.r#type = Some(directive.to_owned());
|
||||
config
|
||||
@@ -102,97 +102,119 @@ mod test {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_from_config_string_v2() {
|
||||
assert_eq!(
|
||||
from_config_string("").unwrap(),
|
||||
fn test_from_config_string_v2() -> Result<(), ()> {
|
||||
fn check(config_string: &str, expected: InstanceConfig) -> Result<(), ()> {
|
||||
let actual = match from_config_string(config_string) {
|
||||
Ok(config) => config,
|
||||
Err(error) => panic!("Expected config to be valid, got error:\n\n{}", error),
|
||||
};
|
||||
assert_eq!(actual, expected);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
check(
|
||||
"",
|
||||
InstanceConfig {
|
||||
directive: "".to_owned(),
|
||||
title: None,
|
||||
id: None,
|
||||
additional_classnames: Vec::new(),
|
||||
collapsible: None,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
from_config_string(" ").unwrap(),
|
||||
},
|
||||
)?;
|
||||
check(
|
||||
" ",
|
||||
InstanceConfig {
|
||||
directive: "".to_owned(),
|
||||
title: None,
|
||||
id: None,
|
||||
additional_classnames: Vec::new(),
|
||||
collapsible: None,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
from_config_string(
|
||||
r#"type="note" class="additional classname" title="Никита" collapsible=true"#
|
||||
)
|
||||
.unwrap(),
|
||||
},
|
||||
)?;
|
||||
check(
|
||||
r#"type="note" class="additional classname" title="Никита" collapsible=true"#,
|
||||
InstanceConfig {
|
||||
directive: "note".to_owned(),
|
||||
title: Some("Никита".to_owned()),
|
||||
id: None,
|
||||
additional_classnames: vec!["additional".to_owned(), "classname".to_owned()],
|
||||
collapsible: Some(true),
|
||||
}
|
||||
);
|
||||
},
|
||||
)?;
|
||||
// Specifying unknown keys is okay, as long as they're valid
|
||||
assert_eq!(
|
||||
from_config_string(r#"unkonwn="but valid toml""#).unwrap(),
|
||||
check(
|
||||
r#"unkonwn="but valid toml""#,
|
||||
InstanceConfig {
|
||||
directive: "".to_owned(),
|
||||
title: None,
|
||||
id: None,
|
||||
additional_classnames: Vec::new(),
|
||||
collapsible: None,
|
||||
}
|
||||
);
|
||||
},
|
||||
)?;
|
||||
// Just directive is fine
|
||||
assert_eq!(
|
||||
from_config_string(r#"info"#).unwrap(),
|
||||
check(
|
||||
r#"info"#,
|
||||
InstanceConfig {
|
||||
directive: "info".to_owned(),
|
||||
title: None,
|
||||
id: None,
|
||||
additional_classnames: Vec::new(),
|
||||
collapsible: None,
|
||||
}
|
||||
);
|
||||
},
|
||||
)?;
|
||||
// Directive plus toml config
|
||||
assert_eq!(
|
||||
from_config_string(r#"info title="Information" collapsible=false"#).unwrap(),
|
||||
check(
|
||||
r#"info title="Information" collapsible=false"#,
|
||||
InstanceConfig {
|
||||
directive: "info".to_owned(),
|
||||
title: Some("Information".to_owned()),
|
||||
id: None,
|
||||
additional_classnames: Vec::new(),
|
||||
collapsible: Some(false),
|
||||
}
|
||||
);
|
||||
},
|
||||
)?;
|
||||
// Test custom id
|
||||
assert_eq!(
|
||||
from_config_string(r#"info title="My Info" id="my-info-custom-id""#).unwrap(),
|
||||
check(
|
||||
r#"info title="My Info" id="my-info-custom-id""#,
|
||||
InstanceConfig {
|
||||
directive: "info".to_owned(),
|
||||
title: Some("My Info".to_owned()),
|
||||
id: Some("my-info-custom-id".to_owned()),
|
||||
additional_classnames: Vec::new(),
|
||||
collapsible: None,
|
||||
}
|
||||
);
|
||||
},
|
||||
)?;
|
||||
// Directive after toml config is an error
|
||||
assert!(from_config_string(r#"title="Information" info"#).is_err());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_config_string_invalid_directive() {
|
||||
assert_eq!(
|
||||
from_config_string(r#"oh!wow titlel=""#).unwrap_err(),
|
||||
r#"'oh!wow' is not a valid directive or TOML key-value pair.
|
||||
|
||||
TOML parsing error: TOML parse error at line 1, column 3
|
||||
|
|
||||
1 | oh!wow
|
||||
| ^
|
||||
expected `.`, `=`
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_config_string_invalid_toml_value() {
|
||||
assert_eq!(
|
||||
from_config_string(r#"note titlel=""#).unwrap_err(),
|
||||
r#"TOML parsing error: TOML parse error at line 1, column 6
|
||||
r#"TOML parsing error: TOML parse error at line 1, column 9
|
||||
|
|
||||
1 | note
|
||||
| ^
|
||||
expected `.`, `=`
|
||||
1 | titlel="
|
||||
| ^
|
||||
invalid basic string
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
@@ -596,6 +596,8 @@ Error rendering admonishment
|
||||
Failed with:
|
||||
|
||||
```log
|
||||
'title="' is not a valid directive or TOML key-value pair.
|
||||
|
||||
TOML parsing error: TOML parse error at line 1, column 8
|
||||
|
|
||||
1 | title="
|
||||
|
||||
Reference in New Issue
Block a user