-
Notifications
You must be signed in to change notification settings - Fork 75
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 documentation on site.options.style
#1873
Changes from 7 commits
a34346f
4504f16
c054300
1c75706
332d320
bf23f6c
78a55c8
2f2eae0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"myst-transforms": patch | ||
--- | ||
|
||
Add support for `class` in block data |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,3 +167,5 @@ site: | |
title: MyST Markdown Guide | ||
domains: | ||
- mystmd-guide.curve.space | ||
options: | ||
style: public/style.css |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.text-gradient em { | ||
background: -webkit-linear-gradient(#eee, #333); | ||
-webkit-background-clip: text; | ||
-webkit-text-fill-color: transparent; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,83 +11,67 @@ We're still building out custom CSS functionality with the MyST engine. | |
Follow and comment on the issues linked below to help us improve it! | ||
::: | ||
|
||
## Use content blocks | ||
## Defining a Style Sheet | ||
|
||
:::{warning} CSS class support is very limited | ||
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). | ||
See these issues to track some of this: | ||
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. | ||
|
||
- Defining your own CSS classes: https://github.com/jupyter-book/mystmd/issues/857 | ||
- Load extra Tailwind CSS classes when they're used on a page: https://github.com/jupyter-book/mystmd/issues/1617 | ||
```{code} yaml | ||
:filename: myst.yml | ||
:linenos: | ||
:emphasize-lines: 3 | ||
site: | ||
options: | ||
style: ./my-style.css | ||
``` | ||
|
||
For example, the style-sheet could contain styling for `em` elements nested below a particular `text-gradient` class: | ||
|
||
:::{literalinclude} public/style.css | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not think about doing that, great shout! |
||
::: | ||
|
||
## Adding CSS Classes | ||
|
||
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. | ||
|
||
### Use content blocks | ||
|
||
[Content blocks](../blocks.md) allow you to attach arbitrary metadata to chunks of content. | ||
You can attach one or more CSS classes by defining a `class` attribute for a block. | ||
For example the following: | ||
|
||
```md | ||
+++ {"class": "col-gutter-right"} | ||
Right-styled | ||
```{myst} | ||
+++ {"class": "text-gradient"} | ||
This is _emphasized_. This is not emphasized. | ||
|
||
+++ | ||
|
||
Normal-styled | ||
This is not emphasized. | ||
``` | ||
|
||
Results in: | ||
|
||
+++ {"class": "col-gutter-right"} | ||
Right-styled | ||
|
||
+++ | ||
|
||
Normal-styled | ||
|
||
## Use `div` and `span` elements | ||
### Use `div` and `span` elements | ||
|
||
You can attach classes directly to [`div` and `span` elements](#div-and-span). | ||
|
||
{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. | ||
|
||
<div class="col-gutter-right" style="font-weight: bold;">Here's my div</div> | ||
```{myst} | ||
<div class="text-gradient" style="font-weight: bold;">Here's my <em>div</em></div> | ||
|
||
Here's some <span class="col-gutter-right" style="font-weight:bold;">Span</span> content | ||
|
||
## Add CSS classes to directives | ||
Here's some <span class="text-gradient" style="font-weight:bold;">span <em>styled</em></span> content | ||
``` | ||
|
||
:::{note} Not all directives support the `:class:` option | ||
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) | ||
::: | ||
### Add CSS classes to directives | ||
|
||
Many directives and content blocks have a `:class:` option that can be used to add arbitrary CSS classes. | ||
For example, below we add a CSS class to an admonition directive to snap it to the right: | ||
|
||
````md | ||
````{myst} | ||
```{note} | ||
:class: col-gutter-right | ||
I'm on the right! | ||
:class: text-gradient | ||
I'm _very stylish_. | ||
``` | ||
```` | ||
|
||
```{note} | ||
:class: col-gutter-right | ||
I'm on the right! | ||
``` | ||
|
||
## Use the HTML theme grid system classes to position content | ||
|
||
The HTML themes come with [a grid system of CSS classes](https://jupyter-book.github.io/myst-theme/?path=/docs/components-grid-system--docs). | ||
You can use these to position content according to the link above. | ||
|
||
## Use Tailwind CSS classes | ||
|
||
:::{note} Provide feedback | ||
This issue tracks loading extra Tailwind CSS classes when they're used on a page: | ||
|
||
- https://github.com/jupyter-book/mystmd/issues/1617 | ||
::: | ||
## Built-in CSS Classes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a recommendation for how people could build a custom CSS file with scss or tailwind? Might just be an npm command they use, or there's always the web-compile GitHub package if that's useful (currently under executable books but we could move it if need be) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a quickstart repo for generating a custom theme here: https://github.com/jupyter-book/book-theme-tailwind-quickstart We could improve this UX by folding it into I don't love option (2) from an extensibility perspective, but perhaps e.g. @fwkoch has some ideas on that. One approach would be to define a new option-type, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like a place where we can take inspiration from similar projects. Docusaurus has a SASS plugin and recommends using it for SCSS and SASS. Could we do something similar? As an author I almost never want to have to create a new theme, but I do want an expressive way to make modifications to an existing theme from the same repository as my content. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the long run, yes. We would need support for non-transform plugins (perhaps with lifecycle hooks) and/or the ability to patch the site config. |
||
|
||
You can use any [Tailwind CSS class](https://tailwindcss.com/docs/installation) that's loaded on a page to style your content. | ||
See the Tailwind documentation for examples of how to do this. | ||
If a class seems to have no effect, it is likely not loaded on the page by MyST. | ||
Currently, it's not possible to customize which classes are included on a page (see above for an issue tracking this). | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe share a link to the issue where we discuss adding support for user-given tailwind classes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm holding off here because I think we ought to suggest best practice, and what that looks like is evolving? See my comment about e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol this is a ridiculous example to use I love it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪩 gotta funk it up