Skip to content

Commit

Permalink
Fix remote image urls
Browse files Browse the repository at this point in the history
  • Loading branch information
ealmloff committed Oct 5, 2024
1 parent 3f8e2b4 commit dfd4a72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mdbook-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn generate_router(book_path: PathBuf, book: mdbook_shared::MdBook<PathBuf>) ->
let book_pages = book.pages().iter().map(|(_, page)| {
let name = path_to_route_variant(&page.url);
// Rsx doesn't work very well in macros because the path for all the routes generated point to the same characters. We manually expand rsx here to get around that issue.
match rsx::parse(page.url.clone(), &page.raw, ) {
match rsx::parse(page.url.clone(), &page.raw) {
Ok(rsx) => {
quote! {
#[component(no_case_check)]
Expand Down
15 changes: 13 additions & 2 deletions mdbook-macro/src/rsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,15 @@ impl<'a, I: Iterator<Item = Event<'a>>> RsxMarkdownParser<'a, I> {
syn::parse_quote!(#dest)
};
#[cfg(feature = "manganis")]
let url: syn::Expr = syn::parse_quote! { manganis::mg!(file(#dest)) };
let url: syn::Expr = {
let remote_image = dest.starts_with("http:") || dest.starts_with("https:");
if remote_image {
let dest = escape_text(dest);
syn::parse_quote!(#dest)
} else {
syn::parse_quote! { manganis::mg!(file(#dest)) }
}
};

self.start_node(parse_quote! {
img {
Expand Down Expand Up @@ -403,7 +411,10 @@ impl<'a, I: Iterator<Item = Event<'a>>> RsxMarkdownParser<'a, I> {
if let (Some(BodyNode::Text(last_text)), BodyNode::Text(new_text)) =
(element_list.last_mut(), &node)
{
last_text.input.formatted_input.push_ifmt(new_text.input.formatted_input.clone());
last_text
.input
.formatted_input
.push_ifmt(new_text.input.formatted_input.clone());
} else {
element_list.push(node);
}
Expand Down

0 comments on commit dfd4a72

Please sign in to comment.