Skip to content

Commit 92839fb

Browse files
agoose77rowanc1
andauthored
💇 Add documentation on site.options.style (#1873)
Co-authored-by: Rowan Cockett <rowanc1@gmail.com>
1 parent aa49c51 commit 92839fb

7 files changed

Lines changed: 52 additions & 53 deletions

File tree

.changeset/spotty-planets-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"myst-transforms": patch
3+
---
4+
5+
Add support for `class` in block data

docs/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The high-level differences between these approaches are outlined in [](#deployme
2323
:::{note} MyST was designed to be deployed as an application
2424
Deploying MyST as an application has many benefits. For example, [performance enhancements](./accessibility-and-performance.md) (like pre-fetching for instant page-transitions, loading indicators, and smaller network payloads) and easier upgrades as new MyST versions are released.
2525

26-
The [default themes](website-templates.md#themes-bundled-with-myst) for MyST are designed to be MyST applications rather than static sites, but the core functionality is equally shared between the two options.
26+
The [default themes](#default-web-themes) for MyST are designed to be MyST applications rather than static sites, but the core functionality is equally shared between the two options.
2727
:::
2828

2929
% - Static deployments are MPA (each page own HTML document), SSG (rendered ahead of time)

docs/myst.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,5 @@ site:
167167
title: MyST Markdown Guide
168168
domains:
169169
- mystmd-guide.curve.space
170+
options:
171+
style: public/style.css

docs/public/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.text-gradient em {
2+
background: -webkit-linear-gradient(#eee, #333);
3+
-webkit-background-clip: text;
4+
-webkit-text-fill-color: transparent;
5+
}

docs/website-style.md

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,83 +11,67 @@ We're still building out custom CSS functionality with the MyST engine.
1111
Follow and comment on the issues linked below to help us improve it!
1212
:::
1313

14-
## Use content blocks
14+
## Defining a Style Sheet
1515

16-
:::{warning} CSS class support is very limited
17-
Currently, you can only use CSS classes that are pre-loaded by MyST from Tailwind CSS, or defined in the HTML theme (see below for examples of both).
18-
See these issues to track some of this:
16+
The [default MyST website themes](#default-web-themes) support bundling a custom [style-sheet](https://en.wikipedia.org/wiki/CSS). This can be used to introduce custom CSS styling to your website. To include a custom CSS file as part of your website build, you can define the @template-site-myst-book-theme-style option, e.g.
1917

20-
- Defining your own CSS classes: https://github.com/jupyter-book/mystmd/issues/857
21-
- Load extra Tailwind CSS classes when they're used on a page: https://github.com/jupyter-book/mystmd/issues/1617
18+
```{code} yaml
19+
:filename: myst.yml
20+
:linenos:
21+
:emphasize-lines: 3
22+
site:
23+
options:
24+
style: ./my-style.css
25+
```
26+
27+
For example, the style-sheet could contain styling for `em` elements nested below a particular `text-gradient` class:
28+
29+
:::{literalinclude} public/style.css
2230
:::
2331

32+
## Adding CSS Classes
33+
34+
The intended way to apply custom styling to your MyST website is to use CSS classes to connect your content to the style sheet. There are several ways to do this.
35+
36+
### Use content blocks
37+
2438
[Content blocks](../blocks.md) allow you to attach arbitrary metadata to chunks of content.
2539
You can attach one or more CSS classes by defining a `class` attribute for a block.
2640
For example the following:
2741

28-
```md
29-
+++ {"class": "col-gutter-right"}
30-
Right-styled
42+
```{myst}
43+
+++ {"class": "text-gradient"}
44+
This is _emphasized_. This is not emphasized.
3145
3246
+++
3347
34-
Normal-styled
48+
This is not emphasized.
3549
```
3650

37-
Results in:
38-
39-
+++ {"class": "col-gutter-right"}
40-
Right-styled
41-
42-
+++
43-
44-
Normal-styled
45-
46-
## Use `div` and `span` elements
51+
### Use `div` and `span` elements
4752

4853
You can attach classes directly to [`div` and `span` elements](#div-and-span).
4954

5055
{myst:directive}`div` and {myst:role}`span` are analogous to their HTML counterparts. Unlike their directive/role, the HTML elements can also be given `style` options, e.g.
5156

52-
<div class="col-gutter-right" style="font-weight: bold;">Here's my div</div>
57+
```{myst}
58+
<div class="text-gradient" style="font-weight: bold;">Here's my <em>div</em></div>
5359
54-
Here's some <span class="col-gutter-right" style="font-weight:bold;">Span</span> content
55-
56-
## Add CSS classes to directives
60+
Here's some <span class="text-gradient" style="font-weight:bold;">span <em>styled</em></span> content
61+
```
5762

58-
:::{note} Not all directives support the `:class:` option
59-
If you wish to attach classes to a directive that doesn't seem to support it, please [open an issue](https://github.com/jupyter-book/mystmd/issues)
60-
:::
63+
### Add CSS classes to directives
6164

6265
Many directives and content blocks have a `:class:` option that can be used to add arbitrary CSS classes.
6366
For example, below we add a CSS class to an admonition directive to snap it to the right:
6467

65-
````md
68+
````{myst}
6669
```{note}
67-
:class: col-gutter-right
68-
I'm on the right!
70+
:class: text-gradient
71+
I'm _very stylish_.
6972
```
7073
````
7174

72-
```{note}
73-
:class: col-gutter-right
74-
I'm on the right!
75-
```
76-
77-
## Use the HTML theme grid system classes to position content
78-
79-
The HTML themes come with [a grid system of CSS classes](https://jupyter-book.github.io/myst-theme/?path=/docs/components-grid-system--docs).
80-
You can use these to position content according to the link above.
81-
82-
## Use Tailwind CSS classes
83-
84-
:::{note} Provide feedback
85-
This issue tracks loading extra Tailwind CSS classes when they're used on a page:
86-
87-
- https://github.com/jupyter-book/mystmd/issues/1617
88-
:::
75+
## Built-in CSS Classes
8976

90-
You can use any [Tailwind CSS class](https://tailwindcss.com/docs/installation) that's loaded on a page to style your content.
91-
See the Tailwind documentation for examples of how to do this.
92-
If a class seems to have no effect, it is likely not loaded on the page by MyST.
93-
Currently, it's not possible to customize which classes are included on a page (see above for an issue tracking this).
77+
The HTML themes come with [a grid system of CSS classes](https://jupyter-book.github.io/myst-theme/?path=/docs/components-grid-system--docs), which can be used out-of-the-box to position content.

docs/website-templates.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ They are defined via the same templating system used for [static document export
1111
For the remainder of this page, assume that "theme" and "template" mean the same thing.
1212
:::
1313

14+
(default-web-themes)=
15+
1416
## Themes bundled with MyST
1517

1618
There are two templates for MyST websites, a `book-theme`, which is the default and is based loosely on Jupyter Book and an `article-theme` that is designed for scientific documents with supporting notebooks. The documentation for this site uses the `book-theme`. For a demonstration of the `article-theme`, you can see [an article on finite volume](https://simpeg.xyz/tle-finitevolume).

packages/myst-cli/src/build/html/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ function rewriteAssetsFolder(directory: string, baseurl?: string): void {
8989
const data = fs.readFileSync(file).toString();
9090
const modified = data
9191
.replace(new RegExp(`\\/${ASSETS_FOLDER}\\/`, 'g'), `${baseurl || ''}/build/`)
92-
.replace('href="/favicon.ico"', `href="${baseurl || ''}/favicon.ico"`);
92+
.replace('href="/favicon.ico"', `href="${baseurl || ''}/favicon.ico"`)
93+
.replace('href="/myst-theme.css"', `href="${baseurl || ''}/myst-theme.css"`);
9394
fs.writeFileSync(file, modified);
9495
});
9596
}

0 commit comments

Comments
 (0)