Comments (7)
Hi @Johnnynator - thanks for the bugreport. Let's check if I understand your request correctly:
- Docutils 0.21+ allows some image files in source
rST
projects to be annotated as for embedded use; this means that each relevant image file is not included in the output build as a standalone named file, but is instead replicated (perhaps usingdata:
URIs, embedded XML, or other formatting as available based on the output format and image type) each time the image is referenced, from each output document that references it. - You would like Sphinx to respect the same
loading
option flag that docutils uses for these annotations.
Could I also ask what behaviour docutils
provides if-and-when writing such embedded-annotated images to a purely text-based output format?
And if possible: could you share more about the use-case(s) that you anticipate this would help with? In other words: not only the change in behaviour that you'd like, but the reasons why that could be beneficial in particular usage scenarios.
from sphinx.
https://docutils.sourceforge.io/docs/ref/rst/directives.html#footnote-4
Yep, base64 data uri for for most things, svg directly embedded as is into the html.
Could I also ask what behaviour docutils provides if-and-when writing such embedded-annotated images to a purely text-based output format?
The loading attribute is only used for their html writer, other writers do ignore it.
My usecase is primarly taking use of how svg's get styled differently when they are embeddes in the html document compared getting linked with e.g. . Makes it easier to have a single svg that can handle both light and dark mode.
For normal images it would be beneficial to get rid of the ugly error message in the output html.
from sphinx.
Could I also ask what behaviour docutils provides if-and-when writing such embedded-annotated images to a purely text-based output format?
The loading attribute is only used for their html writer, other writers do ignore it.
Ok, thank you.
My usecase is primarly taking use of how svg's get styled differently when they are embeddes in the html document compared getting linked with e.g. . Makes it easier to have a single svg that can handle both light and dark mode.
I'm not sure I understand this part - what's a situation where an embedded SVG is easier to style than an SVG included by using a (non-data) img
src
reference?
For normal images it would be beneficial to get rid of the ugly error message in the output html.
Could you post some build logs including the error message?
from sphinx.
I'm not sure I understand this part - what's a situation where an embedded SVG is easier to style than an SVG included by using a (non-data) img src reference?
will inherit all the style of the document, so if you e.g. the furo
theme you can reuse the css properties of it, or at least access body[data-theme="dark"]
(or light
), an svg in an <img>
tag can only use the dark/light media query and would break with the dark/light mode toggle of furo
.
Could you post some build logs including the error message?
Build log:
Running Sphinx v7.3.7
making output directory... done
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets... copying static files... done
copying extra files... done
done
writing output... [100%] index
/home/john/Projects/sphinx-test/doc/index.rst:7: ERROR: Cannot embed image "_images/test.png":
[Errno 2] No such file or directory: '_images/test.png'
generating indices... genindex done
writing additional pages... search done
copying images... [100%] test.png
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 1 warning.
The HTML pages are in build.
Error Message on the Webpage:
System Message: ERROR/3 (/home/john/Projects/sphinx-test/doc/index.rst, line 8)
Cannot embed image "_images/test.png": [Errno 2] No such file or directory: '_images/test.png'
from sphinx.
First of all, thanks for the screenshot: when you mentioned that the error message appeared in the output in your previous messages, I misinterpreted that as being the Sphinx build logs -- I didn't realize that the error appears within the built project content itself (output is a perfectly valid way to refer to that).
The SVG styling question seems to make some sense, but it is at-or-beyond the limits of my SVG/stylesheet experience; I'll try to learn some more about that.
The docutils
code to embed SVGs has a comment to indicate that it's provisional and subject to change, so it may be worth proceeding gradually with functionality here.
from sphinx.
A small concern I had about adding support for embedded SVGs is that there is no implicit namespace for each SVG file embedded within an HTML document. This can cause collisions between the id
values of separate SVG images within a document. It seems that the docutils
folks are aware of this, though - it's mentioned in the relevant commit message.
from sphinx.
heya yep agree that this should be in sphinx and is useful,
in fact I'm just dealing with a case now of moving from <img src
to embedded, to deal with theme compatibility: useblocks/sphinx-needs#1181
from sphinx.
Related Issues (20)
- LaTeX/ImageConverter: Regression with `data:` URIs HOT 1
- Have emoji and U+28FF working in sphinx ``lualatex`` generated for titles and code HOT 6
- Should `defusedxml` be moved to the runtime dependencies? HOT 5
- When compiling linux kernel(drm-tis), failed at module `docutils.nodes` for no attribute โreprunicodeโ HOT 11
- sphinx-build hard-codes the python path into the exe HOT 7
- ext.napoleon to work with ext.todo HOT 2
- ``todo`` directive treat repeated special characters as headers
- toc_object_entries uses language (Python) scoping instead of documentation scoping HOT 2
- TOWER_HOST=https://awx.example.org TOWER_USERNAME=example TOWER_PASSWORD=secret make clean html HOT 1
- Index pages use `–` but it can not be used in ePub HOT 3
- Intersphinx Mapping link not working with Plotly objects in signature HOT 4
- Internationalization doc mentions deprecated transifex-client HOT 1
- 7.3.7: missing `defusedxml` install time dependency HOT 2
- THYDUX COIN ๐ ๐ฅ
- Multiple labels inside math directives HOT 2
- LaTeX: footnote mark may indicate "Page N, M" but footnote M is already on page N
- Gettext builder cannot extract 'option' directive HOT 4
- `autodoc_class_signature = "separated"` cause a warning for enum with no `__init__` HOT 12
- [search] issues with the new HTML search algorithm HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sphinx.