Skip to content

Commit bd19488

Browse files
choldgrafagoose77
andauthored
Fix inline images (#710)
* Document inline images and build instructions * FIX: Inline images now work * Fix inline images and centered figure captions * Fix dev index link * Address comments * Remove local build fix doc because stefan wants me to ;-) * Apply suggestion from @choldgraf * Apply suggestion from @choldgraf * Fix centered image margin bug * Vertical align inline images to text-bottom * Remove figures changes * chore: fix changeset --------- Co-authored-by: Angus Hollands <[email protected]>
1 parent 96e357a commit bd19488

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

.changeset/yellow-taxis-peel.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'myst-to-react': patch
3+
'@myst-theme/styles': patch
4+
---
5+
6+
Fix inline images and centered figure captions

docs/reference/blocks.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def hello_world():
1414
return True
1515
```
1616

17+
```{code-block} python
18+
:caption: This is a caption for my code block!
19+
def hello_world():
20+
print("Hello, World!")
21+
return True
22+
```
23+
1724
### Code Block with Line Numbers
1825

1926
```{code-block} python

docs/reference/images.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,33 @@ title: Images & Figures
44

55
# Images & Figures
66

7+
78
## Basic Image
89

10+
Here's an image in block form:
11+
912
![MyST Logo](../_static/myst-logo-light.svg)
1013

14+
## Inline Images
15+
16+
Text before ![MyST Logo](../_static/myst-logo-light.svg) text after. This image should appear inline with the text, without line breaks before or after it.
17+
18+
### Inline in lists
19+
20+
- Text before ![MyST Logo](../_static/myst-logo-light.svg) text after within a list item.
21+
- Second item without an image for comparison.
22+
23+
### Inline in tables
24+
25+
| Description | Inline image |
26+
| ----------- | ------------ |
27+
| Text before ![MyST Logo](../_static/myst-logo-light.svg) text after | Works inside table cells too |
28+
29+
### Inline in definition lists
30+
31+
Term with logo
32+
: Text before ![MyST Logo](../_static/myst-logo-light.svg) text after inside a definition description.
33+
1134
## Figure with Caption
1235

1336
:::{figure} ../_static/myst-logo-light.svg

packages/myst-to-react/src/image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function alignToMargin(align: string) {
3232
case 'right':
3333
return { marginLeft: 'auto' };
3434
case 'center':
35-
return { margin: '0 auto' };
35+
return { marginLeft: 'auto', marginRight: 'auto' };
3636
default:
3737
return {};
3838
}

styles/typography.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@
3535
.prose dd {
3636
@apply ml-8;
3737
}
38-
.prose p img {
38+
/* Keep inline images inside text flow from forcing line breaks */
39+
.article p img,
40+
.article table img,
41+
.article dd img,
42+
.prose p img,
43+
.prose table img,
44+
.prose dd img {
3945
margin: 0;
4046
display: inline-block;
47+
max-height: 1.2em;
48+
vertical-align: text-bottom;
4149
}
4250
article.content {
4351
min-height: calc(100vh);

0 commit comments

Comments
 (0)