diff --git a/src/web/CSS.jl b/src/web/CSS.jl new file mode 100644 index 0000000..82dff55 --- /dev/null +++ b/src/web/CSS.jl @@ -0,0 +1,442 @@ +### A Pluto.jl notebook ### +# v0.19.36 + +#> [frontmatter] +#> license_url = "https://github.com/JuliaPluto/featured/blob/main/LICENSES/Unlicense" +#> image = "https://github.com/JuliaPluto/featured/assets/43678097/ebcd0d6c-fa37-4d2b-8d82-6814854f726b" +#> title = "Styling with CSS" +#> tags = ["web", "css"] +#> order = "2" +#> license = "Unlicense" +#> description = "Learn how to use CSS to give a unique style to your notebooks!" +#> +#> [[frontmatter.author]] +#> name = "Pluto.jl" +#> url = "https://github.com/JuliaPluto" + +using Markdown +using InteractiveUtils + +# ╔═╡ 9e7188e0-9e7f-11ee-1fef-b56479103e4a +md""" +# Styling notebooks with CSS + +Are you looking bring your notebook presentation to the next level? Do you want to change the way Pluto looks for you? Do you want special formatting for your cell output? + +This is the notebook for you! We'll talk about how to style the notebook page using CSS. Let's get started! +""" + +# ╔═╡ 01455807-c26e-478b-a871-f2b28526b5d9 +md""" +## What is CSS? + +CSS stands for _cascading style sheets_ and it's the language we use to describe what web content should look like. + +A typical web page is written in HTML. HTML is essentially text with tags, which your browser is able to make sense of. For example: +""" + +# ╔═╡ 0bbfdbd5-91cd-4faf-98ef-ed2401c7de15 +html""" +

I like apples...

+

but I don't like oranges.

+""" + +# ╔═╡ df764c10-adc0-4552-b1cf-a77afb9fbe27 +md""" +In this case, `

`, ``, and `` are tags. When your browser displays this text, it understands that when you use the `` tag, it should be displayed in a particular way - in this case, by writing the text in italics. +""" + +# ╔═╡ 4812a04f-0e9f-484f-9253-cef3b3667a23 +md""" +A CSS stylesheet is what we use to control exactly what each element should look like. + +It lists _selectors_ for elements in the HTML content and then describes the desired look of those elements. + +Here is an example. We have some text: +""" + +# ╔═╡ d6c7985c-ff4b-4799-951f-093bfe920f98 +html""" +I don't like oranges! +""" + +# ╔═╡ 30e31be7-8aa1-4a00-913d-7af3388d71b2 +md""" +And here is a stylesheet: +""" + +# ╔═╡ e70d7a55-7eff-4c29-9af2-3288d99fb37c +html""" + +""" + +# ╔═╡ cdf0c733-bbf0-4e2f-832b-19e13e7fe561 +md""" +What's happening here? + +- Our first cell contains the tag ``. A span is a _generic_ element that just tags a selection of text. It doesn't really do anything. +- The span tag includes another attribute: `id="orange"`. That's a way of giving a unique name to this element. +- We then write some style rules in a ` +""" + +# ╔═╡ 6d224e02-a713-41df-a11c-80f39b7a90f8 +md""" +## CSS selectors + +So far we've used the `id` of elements to describe what they should look like. That's a fine way to do things if we want to style a specific element, like the output of a single cell. + +But a lot of the time, we want to write more _general_ rules that describe the overall layout of the page, like "every code cell should have a blue background" or "images should have a margin of 100 pixels". + +Luckily, CSS selectors can do a lot more than selecting elements by their ID. Let's go over the fundamentals. +""" + +# ╔═╡ 4a0aaf47-3685-4b01-bd57-f1ea0a09d01a +html""" +We've already seen one type of selector: selecting the id of the element. + + +""" + +# ╔═╡ 8c0bd2dd-f819-4f77-ba27-23119a216636 +html""" +You can also select the name of the tag. This is useful for very generic selectors, like "any paragraph". + + +""" + +# ╔═╡ b6279fae-90fc-430f-bcb6-1d79f0e98fba +html""" +

+ Sometimes we want something a bit more fine-tuned than the element type: not all paragraphs, but some of them. We can't use IDs here: those are meant to be unique. +

+ +

+ In this case, we usually use the class attribute. That's a way of saying a bunch of elements belong to a particular category. Then you can select elements of a class. +

+ + +""" + +# ╔═╡ 18613f4c-7beb-4051-ab75-1c3db8c4c97a +md""" +Alright, so we can select by the element type, the unique ID of the element, or the class name we assign to the element. We can also combine selectors! +""" + +# ╔═╡ 8f553705-9f6f-4b0e-babc-1170cede56e6 +html""" +

+ This is the first example. +

+

+ This is the second +

+ This is the third + + +""" + +# ╔═╡ 89f79aa7-bcea-43a7-9596-ec347d67e03b +md""" +There is a lot more that you can do with CSS selectors, but this is already very powerful, and it should be enough to get you underway! +""" + +# ╔═╡ 2c867409-ed53-42db-960d-27d3a25ab1b7 +md""" +### Exercise: CSS selectors + +👉 **Your turn!** Match up the colours with the story! +""" + +# ╔═╡ 7af3994f-b0a1-40c1-9c64-f401a58bbfc7 +html""" +

+

+ I have a red bike but my shoes are green. +

+

+ Yesterday a blue car drove by and splashed brown mud all over my shoes. +

+

+ Luckily, my new purple coat was still clean! I hopped on my bike and went to the shoe cleaner. +

+
+ + +""" + +# ╔═╡ fbf50d51-ba14-4f51-8820-aa1df38fb606 +md""" +### Learn more about CSS + +If this was all new to you so far, there is a lot more you can do with CSS - much more than we can cover in this notebook. + +Luckily, CSS is widely used to there are plenty of tutorials available. I frequently use [MDN's CSS guide and reference](https://developer.mozilla.org/en-US/docs/Web/CSS)! +""" + +# ╔═╡ c211b0c4-3801-4a49-ab78-692420240129 +md""" +## Styling Pluto + +Okay, we've gone over the basics of CSS and we've done some styling. How do we go about styling notebooks? + +There are two things you may want to use CSS for: styling the output of specific cells, or styling the whole notebook page. +""" + +# ╔═╡ dd8f6a67-3a00-4ca8-aaf4-c8d2a320dda0 +md""" +### Selection scope + +When you create a ` +""" + +# ╔═╡ db10ee0f-065e-4207-a20b-37ae17d8bbfe +md""" +With that in mind, let's look at our two uses for styling. +""" + +# ╔═╡ 9483d382-1586-4668-8c1d-89d4afc46fa2 +md""" +### Styling specific cells + +If you want to add some styling to the output of specific styles, it's good to avoid statements that can accidentally affect the whole page. + +A good way to do this is to wrap your cell in a tag with a `class` or `id`. Then when you write rules for that cell, write all your rules within that class or ID. +""" + +# ╔═╡ 063a220c-58fb-4113-8f14-a2b4fe0c5791 +html""" +
+ This cell has special formatting. +
+""" + +# ╔═╡ 0d4dac94-3b71-4cb0-be7d-52fe63878a2f +html""" +
+ So does this one! +
+""" + +# ╔═╡ 3f457aad-ffe9-4453-b11b-2e74e7bb45a1 +html""" +But this is just a plain-looking cell! +""" + +# ╔═╡ 7d989347-3aa1-4bc7-8202-d2590bfd2a4e +html""" + +""" + +# ╔═╡ 0edc1d57-baff-4372-94bb-55cea542ebbc +md""" +!!! info "What's a div?" + + We used `
` as the top-level tag in these examples. `
` stands for division: it's a generic element meant to divide the content of a page into parts without really saying anything else about what those parts are for - it's a suitable generic wrapper for cell output. +""" + +# ╔═╡ 00398409-91c3-4bec-8f80-d53d71c33bdd +md""" +If the style is supposed to apply to a single cell, it often makes sense to write it in there, like we've seen in this notebook a few times. But doing so won't restrict the styling to that cell: you should still use a selector. +""" + +# ╔═╡ d1e9080c-e998-43a0-8f57-759c24b3207a +html""" +
+

This cell has its own styling!

+
+ + +""" + +# ╔═╡ a08b40ea-9d80-4552-83bc-50d0c1bdaa13 +md""" +## Styling Pluto + +What if we _don't_ want to style specific cells? + +Sometimes it's useful to style the entire page. For instance, you could change the layout of a notebook for a presentation to show bigger text or hide the live docs. Or maybe you just have a personal preference to show all text in purple! + +We've already seen that ` +""" + +# ╔═╡ d9ac05cc-3c54-46fc-bf28-ad38418fe413 +md""" +Keep in mind that Pluto doesn't guarantee a stable API for styling. That is to say, new versions of Pluto might change class names or element names, or just slightly restyle the page in a way that messes up your own styling rules. + +That said, Pluto has been around for a while, so you can expect it to be reasonably stable. +""" + +# ╔═╡ Cell order: +# ╟─9e7188e0-9e7f-11ee-1fef-b56479103e4a +# ╟─01455807-c26e-478b-a871-f2b28526b5d9 +# ╠═0bbfdbd5-91cd-4faf-98ef-ed2401c7de15 +# ╟─df764c10-adc0-4552-b1cf-a77afb9fbe27 +# ╟─4812a04f-0e9f-484f-9253-cef3b3667a23 +# ╠═d6c7985c-ff4b-4799-951f-093bfe920f98 +# ╟─30e31be7-8aa1-4a00-913d-7af3388d71b2 +# ╠═e70d7a55-7eff-4c29-9af2-3288d99fb37c +# ╟─cdf0c733-bbf0-4e2f-832b-19e13e7fe561 +# ╟─0742d69f-246c-4c69-ae48-e80fc4ed3cf5 +# ╠═e6f1b9dc-8243-4d11-bd21-aa37396cb1e7 +# ╟─6d224e02-a713-41df-a11c-80f39b7a90f8 +# ╠═4a0aaf47-3685-4b01-bd57-f1ea0a09d01a +# ╠═8c0bd2dd-f819-4f77-ba27-23119a216636 +# ╠═b6279fae-90fc-430f-bcb6-1d79f0e98fba +# ╟─18613f4c-7beb-4051-ab75-1c3db8c4c97a +# ╠═8f553705-9f6f-4b0e-babc-1170cede56e6 +# ╟─89f79aa7-bcea-43a7-9596-ec347d67e03b +# ╟─2c867409-ed53-42db-960d-27d3a25ab1b7 +# ╠═7af3994f-b0a1-40c1-9c64-f401a58bbfc7 +# ╟─fbf50d51-ba14-4f51-8820-aa1df38fb606 +# ╟─c211b0c4-3801-4a49-ab78-692420240129 +# ╟─dd8f6a67-3a00-4ca8-aaf4-c8d2a320dda0 +# ╠═ad900671-1662-415e-a1a2-48fcef3df6e2 +# ╟─db10ee0f-065e-4207-a20b-37ae17d8bbfe +# ╟─9483d382-1586-4668-8c1d-89d4afc46fa2 +# ╠═063a220c-58fb-4113-8f14-a2b4fe0c5791 +# ╠═0d4dac94-3b71-4cb0-be7d-52fe63878a2f +# ╠═3f457aad-ffe9-4453-b11b-2e74e7bb45a1 +# ╠═7d989347-3aa1-4bc7-8202-d2590bfd2a4e +# ╟─0edc1d57-baff-4372-94bb-55cea542ebbc +# ╟─00398409-91c3-4bec-8f80-d53d71c33bdd +# ╠═d1e9080c-e998-43a0-8f57-759c24b3207a +# ╟─a08b40ea-9d80-4552-83bc-50d0c1bdaa13 +# ╠═838600d7-1965-445d-ab79-cc81866eca24 +# ╟─d9ac05cc-3c54-46fc-bf28-ad38418fe413 diff --git a/src/web/JavaScript.jl b/src/web/JavaScript.jl index 5bd12fd..1ef8624 100644 --- a/src/web/JavaScript.jl +++ b/src/web/JavaScript.jl @@ -1,12 +1,12 @@ ### A Pluto.jl notebook ### -# v0.19.32 +# v0.19.36 #> [frontmatter] +#> license_url = "https://github.com/JuliaPluto/featured/blob/2a6a9664e5428b37abe4957c1dca0994f4a8b7fd/LICENSES/Unlicense" #> image = "https://upload.wikimedia.org/wikipedia/commons/9/99/Unofficial_JavaScript_logo_2.svg" -#> order = "2" +#> order = "3" #> tags = ["javascript", "web", "classic"] #> license = "Unlicense" -#> license_url = "https://github.com/JuliaPluto/featured/blob/2a6a9664e5428b37abe4957c1dca0994f4a8b7fd/LICENSES/Unlicense" #> description = "Use HTML, CSS and JavaScript to make your own interactive visualizations!" #> #> [[frontmatter.author]] @@ -44,44 +44,9 @@ md""" This document assumes that you have used HTML, CSS and JavaScript before in another context. If you know Julia, and you want to add these web languages to your skill set, we encourage you to do so! It will be useful knowledge, also outside of Pluto. +If you're new to all this, Pluto's featured notebooks also include more basic notebooks on using HTML and CSS! """ -# ╔═╡ 28ae1424-67dc-4b76-a172-1185cc76cb59 -@htl(""" - -
-

- Learning HTML and CSS -

-

- It is easy to learn HTML and CSS because they are not 'programming languages' like Julia and JavaScript, they are markup languages: there are no loops, functions or arrays, you only declare how your document is structured (HTML) and what that structure looks like on a 2D color display (CSS). -

-

- As an example, this is what this cell looks like, written in HTML and CSS: -

-
- - - -""") - # ╔═╡ ea39c63f-7466-4015-a66c-08bd9c716343 md""" > My personal favourite resource for learning HTML and CSS is the [Mozilla Developer Network (MDN)](https://developer.mozilla.org/en-US/docs/Web/CSS). @@ -112,7 +77,7 @@ TableOfContents() md""" # Essentials -## Using HTML, CSS and JavaScript +## Using HTML and JavaScript To use web languages inside Pluto, we recommend the small package [`HypertextLiteral.jl`](https://github.com/MechanicalRabbit/HypertextLiteral.jl), which provides an `@htl` macro. @@ -124,11 +89,11 @@ You wrap `@htl` around a string expression to mark it as an *HTML literal*, as w # ╔═╡ 858745a9-cd59-43a6-a296-803515518e57 md""" -### CSS and JavaScript +### Adding JavaScript to a cell -You can use CSS and JavaScript by including it inside HTML, just like you do when writing a web page. +You can use JavaScript by including it inside HTML, just like you do when writing a web page. -For example, here we use ` - - - """) # ╔═╡ 4a3398be-ee86-45f3-ac8b-f627a38c00b8 @@ -804,60 +760,6 @@ details(x, summary="Show more") = @htl(""" """) -# ╔═╡ 93abe0dc-f041-475f-9ef7-d8ee4408414b -details(md""" - ```htmlmixed - -
-

- Learning HTML and CSS -

-

- It is easy to learn HTML and CSS because they are not 'programming languages' like Julia and JavaScript, they are markup languages: there are no loops, functions or arrays, you only declare how your document is structured (HTML) and what that structure looks like on a 2D color display (CSS). -

-

- As an example, this is what this cell looks like, written in HTML and CSS: -

-
- - - - ``` - """, "Show with syntax highlighting") - -# ╔═╡ d12b98df-8c3f-4620-ba3c-2f3dadac521b -details(md""" - ```htmlmixed - - ``` - """, "Show with syntax highlighting") - # ╔═╡ 94561cb1-2325-49b6-8b22-943923fdd91b details(md""" ```htmlmixed @@ -1224,9 +1126,9 @@ uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" [[Parsers]] deps = ["Dates", "PrecompileTools", "UUIDs"] -git-tree-sha1 = "a935806434c9d4c506ba941871b327b96d41f2bf" +git-tree-sha1 = "8489905bcdbcfac64d1daa51ca07c0d8f0283821" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "2.8.0" +version = "2.8.1" [[Pkg]] deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] @@ -1330,8 +1232,6 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" # ╟─97914842-76d2-11eb-0c48-a7eedca870fb # ╠═571613a1-6b4b-496d-9a68-aac3f6a83a4b # ╟─168e13f7-2ff2-4207-be56-e57755041d36 -# ╠═28ae1424-67dc-4b76-a172-1185cc76cb59 -# ╟─93abe0dc-f041-475f-9ef7-d8ee4408414b # ╟─ea39c63f-7466-4015-a66c-08bd9c716343 # ╟─8b082f9a-073e-4112-9422-4087850fc89e # ╟─d70a3a02-ef3a-450f-bf5a-4a0d7f6262e2 @@ -1357,7 +1257,6 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" # ╟─7afbf8ef-e91c-45b9-bf22-24201cbb4828 # ╠═b226da72-9512-4d14-8582-2f7787c25028 # ╠═a6fd1f7b-a8fc-420d-a8bb-9f549842ad3e -# ╟─d12b98df-8c3f-4620-ba3c-2f3dadac521b # ╟─965f3660-6ec4-4a86-a2a2-c167dbe9315f # ╠═01ce31a9-6856-4ee7-8bce-7ce635167457 # ╠═00d97588-d591-4dad-9f7d-223c237deefd