Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inline WebP/GIF/JPEG images #759

Merged
merged 1 commit into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Expanders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@ function Selectors.runner(::Type{ExampleBlocks}, x, page, doc)
Documents.RawHTML(Base.invokelatest(stringmime, MIME"image/svg+xml"(), result))
elseif showable(MIME"image/png"(), result)
Documents.RawHTML(string("<img src=\"data:image/png;base64,", Base.invokelatest(stringmime, MIME"image/png"(), result), "\" />"))
elseif showable(MIME"image/webp"(), result)
Documents.RawHTML(string("<img src=\"data:image/webp;base64,", Base.invokelatest(stringmime, MIME"image/webp"(), result), "\" />"))
elseif showable(MIME"image/gif"(), result)
Documents.RawHTML(string("<img src=\"data:image/gif;base64,", Base.invokelatest(stringmime, MIME"image/gif"(), result), "\" />"))
elseif showable(MIME"image/jpeg"(), result)
Documents.RawHTML(string("<img src=\"data:image/jpeg;base64,", Base.invokelatest(stringmime, MIME"image/jpeg"(), result), "\" />"))
else
Markdown.Code(Documenter.DocChecks.result_to_string(buffer, result))
end
Expand Down
Binary file added test/examples/images/logo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/examples/images/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/examples/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/examples/images/logo.webp
Binary file not shown.
37 changes: 36 additions & 1 deletion test/examples/src/man/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,45 @@ end # module

```@example inlinepng
using .InlinePNG
PNG(joinpath(Pkg.dir("Documenter"), "docs", "src", "assets", "logo.png"))
PNG(joinpath(Pkg.dir("Documenter"), "test", "examples", "images", "logo.png"))
```


.. and JPEG, GIF and WebP files:

```@setup inlinewebpgifjpeg
module InlineWEBPGIFJPEG
export WEBP, GIF, JPEG
mutable struct WEBP
filename :: String
end
Base.show(io, ::MIME"image/webp", image::WEBP) = write(io, read(image.filename))
mutable struct GIF
filename :: String
end
Base.show(io, ::MIME"image/gif", image::GIF) = write(io, read(image.filename))
mutable struct JPEG
filename :: String
end
Base.show(io, ::MIME"image/jpeg", image::JPEG) = write(io, read(image.filename))
end # module
```

```@example inlinewebpgifjpeg
using .InlineWEBPGIFJPEG
WEBP(joinpath(Pkg.dir("Documenter"), "test", "examples", "images", "logo.webp"))
```

```@example inlinewebpgifjpeg
using .InlineWEBPGIFJPEG
GIF(joinpath(Pkg.dir("Documenter"), "test", "examples", "images", "logo.gif"))
```

```@example inlinewebpgifjpeg
using .InlineWEBPGIFJPEG
JPEG(joinpath(Pkg.dir("Documenter"), "test", "examples", "images", "logo.jpg"))
```

## Interacting with external files

You can also write output files and then refer to them in the document:
Expand Down