Skip to content

Commit

Permalink
Fixes for updates to pulldown_cmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Cypher1 committed Apr 7, 2024
1 parent 94a06a7 commit 0c50910
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
14 changes: 6 additions & 8 deletions src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mdbook::errors::Result;
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
use mdbook::utils::new_cmark_parser;
use mdbook::BookItem;
use pulldown_cmark::{CodeBlockKind, Event, Tag};
use pulldown_cmark::Event;
use pulldown_cmark_to_cmark::cmark;

use crate::renderer::{CLIGraphviz, CLIGraphvizToFile, GraphvizRenderer};
Expand Down Expand Up @@ -126,10 +126,10 @@ impl<R: GraphvizRenderer> Graphviz<R> {
builder.append_code(&**text);
graphviz_block_builder = Some(builder);
}
Event::End(Tag::CodeBlock(CodeBlockKind::Fenced(ref info_string))) => {
Event::Code(info_string) => {
assert_eq!(
Some(0),
(**info_string).find(INFO_STRING_PREFIX),
info_string.find(INFO_STRING_PREFIX),
"We must close our graphviz block"
);

Expand All @@ -145,12 +145,10 @@ impl<R: GraphvizRenderer> Graphviz<R> {
}
} else {
match e {
Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(ref info_string)))
if (**info_string).find(INFO_STRING_PREFIX) == Some(0) =>
{
Event::Code(info_string) if info_string.find(INFO_STRING_PREFIX) == Some(0) => {
graphviz_block_builder = Some(GraphvizBlockBuilder::new(
&**info_string,
&chapter.name.clone(),
info_string.to_string(),
chapter.name.clone(),
chapter_path.clone(),
));
}
Expand Down
13 changes: 9 additions & 4 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tokio::process::{Child, Command};

use async_trait::async_trait;
use mdbook::errors::Result;
use pulldown_cmark::{Event, LinkType, Tag};
use pulldown_cmark::{Event, LinkType, Tag, TagEnd};
use regex::Regex;

use crate::preprocessor::GraphvizBlock;
Expand Down Expand Up @@ -60,11 +60,16 @@ impl GraphvizRenderer for CLIGraphvizToFile {
.await?
.success()
{
let image_tag = Tag::Image(LinkType::Inline, file_name.into(), graph_name.into());
let image_tag = Tag::Image {
link_type: LinkType::Inline,
dest_url: file_name.into(),
title: graph_name.into(),
id: "".into(),
};

Ok(vec![
Event::Start(image_tag.clone()),
Event::End(image_tag),
Event::Start(image_tag),
Event::End(TagEnd::Image),
Event::Text("\n\n".into()),
])
} else {
Expand Down

0 comments on commit 0c50910

Please sign in to comment.