diff --git a/example/assets/assets.json b/example/assets/assets.json index cc0597c0..4f02b2b9 100644 --- a/example/assets/assets.json +++ b/example/assets/assets.json @@ -1 +1,359 @@ -[{"hash":"475860768","width":1080.0,"height":720.0,"local_path":"assets/images/sd_cached_475860768.jpeg","type":"cached"},{"hash":"968081805","width":1080.0,"height":1080.0,"local_path":"assets/images/sd_cached_968081805.gif","type":"cached"},{"hash":"580039713","width":1080.0,"height":500.0,"local_path":"assets/images/sd_cached_580039713.jpeg","type":"cached"},{"hash":"165689209","width":270.0,"height":480.0,"local_path":"assets/images/sd_cached_165689209.gif","type":"cached"},{"hash":"151971805","width":300.0,"height":200.0,"local_path":"assets/images/sd_cached_151971805.jpeg","type":"cached"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"hash":"372574455","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_372574455.png","type":"thumbnail"},{"hash":"531847541","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_531847541.png","type":"thumbnail"},{"hash":"231105015","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_231105015.png","type":"thumbnail"},{"hash":"39806272","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_39806272.png","type":"thumbnail"},{"hash":"825215970","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_825215970.png","type":"thumbnail"},{"hash":"126316725","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_126316725.png","type":"thumbnail"},{"hash":"745277359","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_745277359.png","type":"thumbnail"},{"hash":"232865622","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_232865622.png","type":"thumbnail"},{"hash":"890549629","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_890549629.png","type":"thumbnail"},{"hash":"836619553","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_836619553.png","type":"thumbnail"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"hash":"883364285","width":1280.0,"height":720.0,"local_path":"assets/images/sd_thumb_883364285.png","type":"thumbnail"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"},{"width":600.0,"height":860.0,"local_path":"assets/images/sd_generated_7177249.png","hash":"7177249","type":"generated"}] \ No newline at end of file +[ + { + "hash": "475860768", + "width": 1080.0, + "height": 720.0, + "local_path": "assets/images/sd_cached_475860768.jpeg", + "type": "cached" + }, + { + "hash": "968081805", + "width": 1080.0, + "height": 1080.0, + "local_path": "assets/images/sd_cached_968081805.gif", + "type": "cached" + }, + { + "hash": "580039713", + "width": 1080.0, + "height": 500.0, + "local_path": "assets/images/sd_cached_580039713.jpeg", + "type": "cached" + }, + { + "hash": "165689209", + "width": 270.0, + "height": 480.0, + "local_path": "assets/images/sd_cached_165689209.gif", + "type": "cached" + }, + { + "hash": "151971805", + "width": 300.0, + "height": 200.0, + "local_path": "assets/images/sd_cached_151971805.jpeg", + "type": "cached" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "hash": "372574455", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_372574455.png", + "type": "thumbnail" + }, + { + "hash": "531847541", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_531847541.png", + "type": "thumbnail" + }, + { + "hash": "231105015", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_231105015.png", + "type": "thumbnail" + }, + { + "hash": "39806272", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_39806272.png", + "type": "thumbnail" + }, + { + "hash": "825215970", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_825215970.png", + "type": "thumbnail" + }, + { + "hash": "126316725", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_126316725.png", + "type": "thumbnail" + }, + { + "hash": "745277359", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_745277359.png", + "type": "thumbnail" + }, + { + "hash": "232865622", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_232865622.png", + "type": "thumbnail" + }, + { + "hash": "890549629", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_890549629.png", + "type": "thumbnail" + }, + { + "hash": "836619553", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_836619553.png", + "type": "thumbnail" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "hash": "883364285", + "width": 1280.0, + "height": 720.0, + "local_path": "assets/images/sd_thumb_883364285.png", + "type": "thumbnail" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + }, + { + "width": 600.0, + "height": 860.0, + "local_path": "assets/images/sd_generated_7177249.png", + "hash": "7177249", + "type": "generated" + } +] diff --git a/lib/helpers/markdown_processor.dart b/lib/helpers/markdown_processor.dart index 4796d0e7..2cfcdca3 100644 --- a/lib/helpers/markdown_processor.dart +++ b/lib/helpers/markdown_processor.dart @@ -263,9 +263,6 @@ class ImageCachingTask extends Task { await saveAsset(assetUri); } - // Check also if image is on background: or src: in front matter - // and replace the url with the local path, frontmatter is now data.options Map - final background = slide.background; if (background != null) { @@ -301,36 +298,29 @@ class MermaidConverterTask extends Task { final mermaidImageHash = mermaidSyntax.hashCode.toString(); - final cache = await assetService.loadGeneratedAsset(mermaidImageHash); + var asset = await assetService.loadGeneratedAsset(mermaidImageHash); // Check if image already exists - if (cache != null) { - replacements.add(( - start: match.start, - end: match.end, - markdown: '![Mermaid Diagram](${cache.relativePath})', - asset: cache, - )); - continue; - } + if (asset == null) { + // Process the mermaid syntax to generate an image file + final imageData = await mermaidService.generateImage(mermaidSyntax); - // Process the mermaid syntax to generate an image file - final imageData = await mermaidService.generateImage(mermaidSyntax); - - if (imageData != null) { - final asset = await assetService.saveGeneratedAsset( - hash: mermaidImageHash, - data: imageData, - ); - - // Collect replacement information - replacements.add(( - start: match.start, - end: match.end, - markdown: '![Mermaid Diagram](${asset.relativePath})', - asset: asset, - )); + if (imageData != null) { + asset = await assetService.saveGeneratedAsset( + hash: mermaidImageHash, + data: imageData, + ); + } } + + if (asset == null) continue; + + replacements.add(( + start: match.start, + end: match.end, + markdown: '![Mermaid Diagram](${asset.relativePath})', + asset: asset, + )); } var replacedData = slide.data;