mirror of
https://github.com/tommilligan/mdbook-admonish.git
synced 2025-12-27 14:41:25 -05:00
Compare commits
19 Commits
v1.18.0
...
pandoc-par
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1707e8ba6 | ||
|
|
5714548254 | ||
|
|
11aed56c23 | ||
|
|
ea6c0a687a | ||
|
|
50b9187ee5 | ||
|
|
fbd07ecaf0 | ||
|
|
37d03b872e | ||
|
|
fa91fe3778 | ||
|
|
d59dce3533 | ||
|
|
21d86546ff | ||
|
|
79ee592f56 | ||
|
|
0d3eb11a2c | ||
|
|
43579f902b | ||
|
|
7ee3643dc3 | ||
|
|
c4bf2608e7 | ||
|
|
d4667a5f55 | ||
|
|
8751b3cd24 | ||
|
|
516bbc6e7e | ||
|
|
fc5c5eae39 |
16
.github/workflows/check.yml
vendored
16
.github/workflows/check.yml
vendored
@@ -6,7 +6,7 @@ jobs:
|
||||
# Fast test before we kick off all the other jobs
|
||||
fast-test:
|
||||
name: Fast test
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
@@ -31,7 +31,7 @@ jobs:
|
||||
detailed-test:
|
||||
needs: fast-test
|
||||
name: Test main target
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
@@ -50,8 +50,10 @@ jobs:
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rustfmt, clippy
|
||||
- name: Enable Corepack
|
||||
run: corepack enable
|
||||
- name: Install node toolchain
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
cache: "yarn"
|
||||
@@ -70,16 +72,16 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-20.04
|
||||
- ubuntu-24.04
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- 1.74.0
|
||||
- 1.82.0
|
||||
experimental:
|
||||
- false
|
||||
include:
|
||||
# Run a canary test on nightly that's allowed to fail
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-24.04
|
||||
rust: nightly
|
||||
experimental: true
|
||||
# Test only stable on Windows, presume we'd get same result on other
|
||||
@@ -89,7 +91,7 @@ jobs:
|
||||
experimental: false
|
||||
exclude:
|
||||
# Don't bother retesting stable linux, we did it in the comprehensive test
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-24.04
|
||||
rust: stable
|
||||
experimental: false
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
12
.github/workflows/deploy.yml
vendored
12
.github/workflows/deploy.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
||||
# binaries, so we use the same glibc version
|
||||
#
|
||||
# ref: https://github.com/rust-lang/mdBook/pull/1955
|
||||
os: ubuntu-20.04
|
||||
os: ubuntu-24.04
|
||||
name: x86_64-unknown-linux-gnu.tar.gz
|
||||
- target: x86_64-unknown-linux-musl
|
||||
os: ubuntu-latest
|
||||
@@ -92,10 +92,12 @@ jobs:
|
||||
tar czvf ../../stage/${{ env.CRATE_NAME }}-${{ steps.extract_tag.outputs.tag }}-${{ matrix.name }} ${{ env.CRATE_NAME }}
|
||||
cd -
|
||||
- name: Post Setup | Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.CRATE_NAME }}-${{ steps.extract_tag.outputs.tag }}-${{ matrix.name }}
|
||||
path: target/stage/*
|
||||
# Idempotency: overwrite artefact by name if we're rerunning the deployment
|
||||
overwrite: true
|
||||
|
||||
# Create GitHub release with Rust build targets and release notes
|
||||
github_release:
|
||||
@@ -109,7 +111,7 @@ jobs:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup | Artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
uses: actions/download-artifact@v4
|
||||
|
||||
- name: Setup | Extract version
|
||||
shell: bash
|
||||
@@ -120,7 +122,7 @@ jobs:
|
||||
run: |
|
||||
cat CHANGELOG.md | sed -n '/^## ${{ steps.extract_version.outputs.version }}$/,/^## /p' | sed '$d' > RELEASE.md
|
||||
- name: Build | Publish
|
||||
uses: softprops/action-gh-release@v1
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: ${{ env.CRATE_NAME }}-*/${{ env.CRATE_NAME }}-*
|
||||
body_path: RELEASE.md
|
||||
@@ -131,7 +133,7 @@ jobs:
|
||||
publish:
|
||||
name: Publish to crates.io
|
||||
needs: github_release
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v4
|
||||
|
||||
4
.github/workflows/docs.yml
vendored
4
.github/workflows/docs.yml
vendored
@@ -11,7 +11,7 @@ permissions:
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v4
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
- name: Build book
|
||||
run: ./scripts/build-book
|
||||
- name: Push docs
|
||||
uses: JamesIves/github-pages-deploy-action@v4.4.3
|
||||
uses: JamesIves/github-pages-deploy-action@v4
|
||||
with:
|
||||
branch: gh-pages
|
||||
folder: book/book
|
||||
|
||||
17
CHANGELOG.md
17
CHANGELOG.md
@@ -1,5 +1,22 @@
|
||||
# Changelog
|
||||
|
||||
## v1.20.0
|
||||
|
||||
### Changed
|
||||
|
||||
- MSRV (minimum supported rust version) is now 1.82.0 ([#227](https://github.com/tommilligan/mdbook-admonish/pull/227))
|
||||
- Collapsible blocks now show content in print view ([#228](https://github.com/tommilligan/mdbook-admonish/pull/228)). Thanks to [@igor-petruk](https://github.com/igor-petruk) for raising this issue.
|
||||
|
||||
## v1.19.0
|
||||
|
||||
### Changed
|
||||
|
||||
- MSRV (minimum supported rust version) is now 1.76.0 ([#208](https://github.com/tommilligan/mdbook-admonish/pull/208))
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed blocks not rendering correctly in indented list items. Thanks to [@JorelAli](https://github.com/JorelAli) for the bug report! ([#224](https://github.com/tommilligan/mdbook-admonish/pull/224))
|
||||
|
||||
## v1.18.0
|
||||
|
||||
### Changed
|
||||
|
||||
1549
Cargo.lock
generated
1549
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
12
Cargo.toml
@@ -1,8 +1,8 @@
|
||||
[package]
|
||||
name = "mdbook-admonish"
|
||||
version = "1.18.0"
|
||||
version = "1.20.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.74.0"
|
||||
rust-version = "1.76.0"
|
||||
|
||||
authors = ["Tom Milligan <code@tommilligan.net>"]
|
||||
description = "A preprocessor for mdbook to add Material Design admonishments."
|
||||
@@ -35,8 +35,10 @@ env_logger = { version = "0.11", default-features = false, optional = true }
|
||||
log = "0.4.21"
|
||||
mdbook = "0.4.40"
|
||||
once_cell = "1.19.0"
|
||||
pandoc = { version = "0.8", optional = true }
|
||||
pandoc_ast = { version = "0.8", optional = true }
|
||||
path-slash = "0.2.1"
|
||||
pulldown-cmark = "0.11"
|
||||
pulldown-cmark = { version = "0.13", optional = true }
|
||||
regex = "1.10.5"
|
||||
semver = "1.0.23"
|
||||
serde = { version = "1.0.203", features = ["derive"] }
|
||||
@@ -49,7 +51,9 @@ hex_color = { version = "3.0.0", features = ["serde"] }
|
||||
pretty_assertions = "1.4.0"
|
||||
|
||||
[features]
|
||||
default = ["cli", "cli-install"]
|
||||
default = ["cli", "cli-install", "parser-markdown"]
|
||||
parser-markdown = ["pulldown-cmark"]
|
||||
parser-pandoc = ["pandoc", "pandoc_ast"]
|
||||
|
||||
# Enable the command line binary
|
||||
cli = ["clap", "env_logger"]
|
||||
|
||||
@@ -10,7 +10,7 @@ git-repository-url = "https://github.com/tommilligan/mdbook-admonish"
|
||||
|
||||
[preprocessor.admonish]
|
||||
command = "mdbook-admonish"
|
||||
assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`
|
||||
assets_version = "3.1.0" # do not edit: managed by `mdbook-admonish install`
|
||||
|
||||
[preprocessor.admonish.directive.custom]
|
||||
expensive = { icon = "./money-bag.svg", color = "#24ab38" }
|
||||
|
||||
2
compile_assets/.gitignore
vendored
2
compile_assets/.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
/node_modules
|
||||
*.css
|
||||
*.css.map
|
||||
.yarn/
|
||||
.pnp*
|
||||
|
||||
@@ -15,5 +15,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^3.0.3"
|
||||
}
|
||||
},
|
||||
"packageManager": "yarn@4.8.1+sha512.bc946f2a022d7a1a38adfc15b36a66a3807a67629789496c3714dd1703d2e6c6b1c69ff9ec3b43141ac7a1dd853b7685638eb0074300386a59c18df351ef8ff6"
|
||||
}
|
||||
|
||||
@@ -92,8 +92,9 @@ $admonitions: (
|
||||
0 0.2rem 1rem rgba(0, 0, 0, 0.05),
|
||||
0 0 0.1rem rgba(0, 0, 0, 0.1);
|
||||
|
||||
// [print]: Omit shadow as it may lead to rendering errors
|
||||
// During print mode in browser, pdf renderer
|
||||
@media print {
|
||||
// Omit shadow as it may lead to rendering errors
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
@@ -200,6 +201,14 @@ a.admonition-anchor-link {
|
||||
}
|
||||
}
|
||||
|
||||
// During print mode in browser, pdf renderer
|
||||
@media print {
|
||||
// Expand collapsed sections to show details
|
||||
details.admonition::details-content {
|
||||
display: contents;
|
||||
}
|
||||
}
|
||||
|
||||
summary.admonition-title {
|
||||
details.admonition > &::after {
|
||||
position: absolute;
|
||||
@@ -222,6 +231,12 @@ summary.admonition-title {
|
||||
details[open].admonition > &::after {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
// Hide details marker for Safari that loves to show it anyway
|
||||
// ref: https://github.com/tommilligan/mdbook-admonish/pull/185
|
||||
&::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
:root {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ title = "mdbook-admonish-integration"
|
||||
|
||||
[preprocessor.admonish]
|
||||
command = "mdbook-admonish"
|
||||
assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`
|
||||
assets_version = "3.1.0" # do not edit: managed by `mdbook-admonish install`
|
||||
after = ["links"]
|
||||
|
||||
[[preprocessor.admonish.custom]]
|
||||
|
||||
@@ -9,7 +9,7 @@ title = "mdbook-admonish-integration"
|
||||
|
||||
[preprocessor.admonish]
|
||||
command = "mdbook-admonish"
|
||||
assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`
|
||||
assets_version = "3.1.0" # do not edit: managed by `mdbook-admonish install`
|
||||
after = ["links"]
|
||||
|
||||
[[preprocessor.admonish.custom]]
|
||||
|
||||
@@ -47,17 +47,17 @@
|
||||
</div>
|
||||
<div>
|
||||
<p>Failed with:</p>
|
||||
<pre><code class="language-log">'title="' is not a valid directive or TOML key-value pair.
|
||||
<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 21
|
||||
|
|
||||
1 | config = { title=" }
|
||||
1 | config = { title=" }
|
||||
| ^
|
||||
invalid basic string
|
||||
|
||||
</code></pre>
|
||||
<p>Original markdown input:</p>
|
||||
<pre><code class="language-markdown">```admonish title="
|
||||
<pre><code class="language-markdown">```admonish title="
|
||||
No title, only body
|
||||
```
|
||||
</code></pre>
|
||||
@@ -137,6 +137,23 @@ let x = 20;
|
||||
<p>Thing two</p>
|
||||
</div>
|
||||
</div>
|
||||
<ol>
|
||||
<li>
|
||||
<p>Thing two nested</p>
|
||||
<div id="admonition-note-5" class="admonition admonish-note" role="note" aria-labelledby="admonition-note-5-title">
|
||||
<div class="admonition-title">
|
||||
<div id="admonition-note-5-title">
|
||||
<p>Note</p>
|
||||
</div>
|
||||
<a class="admonition-anchor-link" href="#admonition-note-5"></a>
|
||||
</div>
|
||||
<div>
|
||||
<p>Thing two nested (should not be a code block)
|
||||
Regression tests for https://github.com/tommilligan/mdbook-admonish/issues/223</p>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>
|
||||
<p>Thing three</p>
|
||||
|
||||
@@ -60,6 +60,13 @@ In a list:
|
||||
Thing two
|
||||
```
|
||||
|
||||
1. Thing two nested
|
||||
|
||||
```admonish
|
||||
Thing two nested (should not be a code block)
|
||||
Regression tests for https://github.com/tommilligan/mdbook-admonish/issues/223
|
||||
```
|
||||
|
||||
1. Thing three
|
||||
|
||||
```sh
|
||||
|
||||
@@ -8,7 +8,7 @@ function eprintln() {
|
||||
>&2 echo "$1"
|
||||
}
|
||||
|
||||
VERSION="0.4.35"
|
||||
VERSION="0.4.51"
|
||||
|
||||
eprintln "Checking if mdbook $VERSION is installed"
|
||||
if [[ "$(mdbook --version)" != "mdbook v$VERSION" ]]; then
|
||||
|
||||
@@ -1 +1 @@
|
||||
3.0.2
|
||||
3.1.0
|
||||
|
||||
@@ -86,6 +86,11 @@ html :is(.admonition-title, summary.admonition-title):last-child {
|
||||
display: initial;
|
||||
}
|
||||
|
||||
@media print {
|
||||
details.admonition::details-content {
|
||||
display: contents;
|
||||
}
|
||||
}
|
||||
details.admonition > summary.admonition-title::after {
|
||||
position: absolute;
|
||||
top: 0.625em;
|
||||
@@ -106,6 +111,9 @@ details.admonition > summary.admonition-title::after {
|
||||
details[open].admonition > summary.admonition-title::after {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
summary.admonition-title::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:root {
|
||||
--md-details-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42Z'/></svg>");
|
||||
|
||||
@@ -6,7 +6,10 @@ mod book_config;
|
||||
mod config;
|
||||
#[doc(hidden)]
|
||||
pub mod custom;
|
||||
#[cfg(feature = "parser-markdown")]
|
||||
mod markdown;
|
||||
#[cfg(feature = "parser-pandoc")]
|
||||
mod pandoc;
|
||||
mod parse;
|
||||
mod preprocessor;
|
||||
mod render;
|
||||
|
||||
@@ -1153,9 +1153,9 @@ Text
|
||||
<a class="admonition-anchor-link" href="#admonition-note"></a>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
Thing two
|
||||
|
||||
|
||||
Thing two
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1168,4 +1168,97 @@ Text
|
||||
|
||||
assert_eq!(expected, prep(content));
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/tommilligan/mdbook-admonish/issues/223
|
||||
#[test]
|
||||
fn nested_list_should_not_render_indented_code_block() {
|
||||
let content = r#"# Chapter
|
||||
|
||||
- Level one
|
||||
|
||||
```admonish
|
||||
Thing one
|
||||
line two
|
||||
```
|
||||
|
||||
- Level two
|
||||
|
||||
```admonish
|
||||
Thing two
|
||||
line two
|
||||
```
|
||||
|
||||
- Level three
|
||||
|
||||
```admonish
|
||||
Thing three
|
||||
line two
|
||||
```
|
||||
"#;
|
||||
|
||||
let expected = r##"# Chapter
|
||||
|
||||
- Level one
|
||||
|
||||
|
||||
<div id="admonition-note" class="admonition admonish-note" role="note" aria-labelledby="admonition-note-title">
|
||||
<div class="admonition-title">
|
||||
<div id="admonition-note-title">
|
||||
|
||||
Note
|
||||
|
||||
</div>
|
||||
<a class="admonition-anchor-link" href="#admonition-note"></a>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
Thing one
|
||||
line two
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
- Level two
|
||||
|
||||
|
||||
<div id="admonition-note-1" class="admonition admonish-note" role="note" aria-labelledby="admonition-note-1-title">
|
||||
<div class="admonition-title">
|
||||
<div id="admonition-note-1-title">
|
||||
|
||||
Note
|
||||
|
||||
</div>
|
||||
<a class="admonition-anchor-link" href="#admonition-note-1"></a>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
Thing two
|
||||
line two
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
- Level three
|
||||
|
||||
|
||||
<div id="admonition-note-2" class="admonition admonish-note" role="note" aria-labelledby="admonition-note-2-title">
|
||||
<div class="admonition-title">
|
||||
<div id="admonition-note-2-title">
|
||||
|
||||
Note
|
||||
|
||||
</div>
|
||||
<a class="admonition-anchor-link" href="#admonition-note-2"></a>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
Thing three
|
||||
line two
|
||||
|
||||
</div>
|
||||
</div>
|
||||
"##;
|
||||
|
||||
assert_eq!(expected, prep(content));
|
||||
}
|
||||
}
|
||||
|
||||
78
src/pandoc.rs
Normal file
78
src/pandoc.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
use mdbook::errors::Result as MdbookResult;
|
||||
|
||||
use crate::{
|
||||
book_config::OnFailure,
|
||||
types::{Overrides, RenderTextMode},
|
||||
};
|
||||
|
||||
pub(crate) fn preprocess(
|
||||
content: &str,
|
||||
on_failure: OnFailure,
|
||||
overrides: &Overrides,
|
||||
render_text_mode: RenderTextMode,
|
||||
) -> MdbookResult<String> {
|
||||
if render_text_mode == RenderTextMode::Strip {
|
||||
// We don't support stripping in pandoc - they just show up as divs.
|
||||
return Ok(content.to_owned());
|
||||
}
|
||||
|
||||
let ADMONISH_KIND = "note".to_owned();
|
||||
|
||||
let mut pandoc = pandoc::new();
|
||||
pandoc.set_input(pandoc::InputKind::Pipe(content.into()));
|
||||
pandoc.set_input_format(pandoc::InputFormat::CommonmarkX, Vec::new());
|
||||
pandoc.set_output_format(pandoc::OutputFormat::CommonmarkX, Vec::new());
|
||||
pandoc.set_output(pandoc::OutputKind::Pipe);
|
||||
pandoc.add_filter(|json| {
|
||||
pandoc_ast::filter(json, |mut pandoc| {
|
||||
for block in &mut pandoc.blocks {
|
||||
println!("{:?}", &block);
|
||||
use pandoc_ast::Block;
|
||||
use pandoc_ast::Inline;
|
||||
match block {
|
||||
Block::Div((identifier, classes, kv), content) => {
|
||||
if let Some(ADMONISH_KIND) = classes.first() {
|
||||
// TODO: generate values for below by reading the pandoc input
|
||||
// decide on a syntax for kv and classes, admonition type, and plug
|
||||
// that in to our existing structs which deal with links and overrides
|
||||
// etc.
|
||||
|
||||
*block = Block::Div(
|
||||
(
|
||||
// TODO: get from kv
|
||||
"admonition-title".to_owned(),
|
||||
// TODO: compute from input above
|
||||
vec!["admonition".to_owned(), "admonish-note".to_owned()],
|
||||
vec![
|
||||
("role".to_owned(), "note".to_owned()),
|
||||
(
|
||||
"aria-labelledby".to_owned(),
|
||||
"admonition-title-title".to_owned(),
|
||||
),
|
||||
],
|
||||
),
|
||||
vec![
|
||||
Block::Div(
|
||||
// TODO: add anchor link elements (a, href, etc)
|
||||
("admonition-title-title".to_owned(), vec![], vec![]),
|
||||
vec![Block::Plain(vec![Inline::Str("Title".to_owned())])],
|
||||
),
|
||||
Block::Div(("".to_owned(), vec![], vec![]), content.clone()),
|
||||
],
|
||||
)
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
pandoc
|
||||
})
|
||||
});
|
||||
let result = pandoc.execute().unwrap();
|
||||
use pandoc::PandocOutput::*;
|
||||
let output = match result {
|
||||
ToBuffer(output) => output,
|
||||
ToFile(_) | ToBufferRaw(_) => panic!("expected buffer output"),
|
||||
};
|
||||
Ok(output)
|
||||
}
|
||||
@@ -7,10 +7,14 @@ use mdbook::{
|
||||
|
||||
use crate::{
|
||||
book_config::{admonish_config_from_context, Config, RenderMode},
|
||||
markdown::preprocess,
|
||||
types::{Overrides, RenderTextMode},
|
||||
};
|
||||
|
||||
#[cfg(feature = "parser-markdown")]
|
||||
use crate::markdown::preprocess;
|
||||
#[cfg(feature = "parser-pandoc")]
|
||||
use crate::pandoc::preprocess;
|
||||
|
||||
pub struct Admonish;
|
||||
|
||||
impl Preprocessor for Admonish {
|
||||
@@ -166,8 +170,9 @@ mod test {
|
||||
serde_json::from_value(value).unwrap()
|
||||
}
|
||||
|
||||
#[cfg(feature = "parser-markdown")]
|
||||
#[test]
|
||||
fn run_html() {
|
||||
fn run_markdown_to_html() {
|
||||
let content = r#"
|
||||
````admonish title="Title"
|
||||
```rust
|
||||
@@ -210,6 +215,43 @@ x = 20;
|
||||
assert_eq!(Admonish.run(&ctx, book).unwrap(), expected_book)
|
||||
}
|
||||
|
||||
#[cfg(feature = "parser-pandoc")]
|
||||
#[test]
|
||||
fn run_pandoc_to_html() {
|
||||
let content = r#"
|
||||
:::{.note title="Title"}
|
||||
```rust
|
||||
let x = 10;
|
||||
x = 20;
|
||||
```
|
||||
:::
|
||||
"#;
|
||||
let expected_content = r##"::::: {#admonition-title .admonition .admonish-note role="note" aria-labelledby="admonition-title-title"}
|
||||
::: {#admonition-title-title}
|
||||
Title
|
||||
:::
|
||||
|
||||
::: {}
|
||||
``` rust
|
||||
let x = 10;
|
||||
x = 20;
|
||||
```
|
||||
:::
|
||||
:::::
|
||||
"##;
|
||||
|
||||
let ctx = mock_context(
|
||||
&json!({
|
||||
"assets_version": "3.0.0"
|
||||
}),
|
||||
"html",
|
||||
);
|
||||
let book = mock_book(content);
|
||||
let expected_book = mock_book(expected_content);
|
||||
|
||||
assert_eq!(Admonish.run(&ctx, book).unwrap(), expected_book)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_test_preserves_by_default() {
|
||||
let content = r#"
|
||||
@@ -232,8 +274,9 @@ x = 20;
|
||||
assert_eq!(Admonish.run(&ctx, book).unwrap(), expected_book)
|
||||
}
|
||||
|
||||
#[cfg(feature = "parser-markdown")]
|
||||
#[test]
|
||||
fn run_test_can_strip() {
|
||||
fn run_test_can_strip_markdown() {
|
||||
let content = r#"
|
||||
````admonish title="Title"
|
||||
```rust
|
||||
|
||||
@@ -97,13 +97,15 @@ impl<'a> Admonition<'a> {
|
||||
// - the additional whitespace around the content are deliberate
|
||||
// In line with the commonmark spec, this allows the inner content to be
|
||||
// rendered as markdown paragraphs.
|
||||
// - We should not indent the inner content, as it retains the indent
|
||||
// it is written with.
|
||||
format!(
|
||||
r#"
|
||||
{indent}<{admonition_element} {attributes}>
|
||||
{titlebar_html}{indent}<div>
|
||||
{indent}
|
||||
{indent}{content}
|
||||
{indent}
|
||||
|
||||
{content}
|
||||
|
||||
{indent}</div>
|
||||
{indent}</{admonition_element}>"#,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user