Skip to content

Commit 6283201

Browse files
committed
More exercises.
1 parent 1a162c3 commit 6283201

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ below.
2727
## Part Two: Building a browser
2828

2929
* [docs/exercise2a.md](Exercise 2a): Add support for italic text in the browser.
30-
* Exercise 2b: Add support for `h1` or `font color` or similar.
31-
* Exercise 2c: Add word wrap in the browser. (TBD - might be too hard)
32-
* Exercise 2d: Add scrolling in the browser. (TBD - might be too hard)
33-
* Exercise 2e: Invent your own HTML tag. Add it to the browser and to some
30+
* [docs/exercise2b.md](Exercise 2b): Add support for `h1` or `font color` or similar.
31+
* [docs/exercise2c.md](Exercise 2c): Add word wrap in the browser. (HARD!)
32+
* [docs/exercise2d.md](Exercise 2d): Invent your own HTML tag. Add it to the browser and to some
3433
HTML pages in the server. See how it works end-to-end.
3534

3635
## Part Three: Encryption

docs/exercise2a.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Exercise 2a
2+
3+
Make the browser support _italic_ text whenever it comes across the
4+
HTML tags `<i>` or `<em>`. (`em` means "emphasis" and sometimes websites
5+
use that rather than `i` for italic.)
6+
7+
Check it works using a web page you create.

docs/exercise2b.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Exercise 2b: Add support for other tags
2+
3+
Do some [research on standard HTML tags](https://www.w3schools.com/tags/), and add support for another one of your choice.
4+
5+
* (Hopefully) easy choices: anything that just alters the appearance of the text, e.g. `h1`-`h6`, `font color`.
6+
* Medium choices: change the title bar of the browser window when it finds a `title` tag. (Hint: this will
7+
probably involve adding another function to the `Browser` class which you'll call from the `Renderer` class).
8+
* Very hard choice: add support for `img src` which will include pictures on the page.
9+
This will likely take several hours even if you're a Python wizard. You'd need to do this:
10+
1. Get an absolute URI to the image (see the existing code in `link_clicked` which does the same)
11+
2. Download the image file using [`requests`](https://pypi.org/project/requests/), perhaps into a
12+
[`NamedTemporaryFile`](https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile)
13+
3. Use `create_image` on the `canvas` to draw it.
14+
* Another very hard choice: the `blink` tag. This will require you to set a timer to re-draw the page
15+
periodically.
16+
* Impossible choice: anything to do with page layout. Don't attempt to support tables, frames or anything
17+
fancy like that. It would take hundreds of hours - it's all very complicated. Don't even try.
18+
19+
Good choices might be h1-h6 or `font color`.
20+

docs/exercise2c.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Exercise 2c: word wrap!
2+
3+
You might notice that the browser doesn't have word wrap.
4+
How would you do that?
5+
6+
Hints:
7+
* This will all be inside the `Renderer` class.
8+
* In `handle_data`
9+
* Do it _approximately_ first
10+
* Right now, it receives all the text inside each HTML tag in one go, for
11+
example `<p>All this text arrives in one call to that function</p>`
12+
* Maybe you can split that into words and draw one word at a time?
13+
* We already measure how wide the text was. Perhaps you can use that to
14+
decide when to start a new line?
15+
* But you already drew too much text, right? Maybe `canvas.delete` helps!

docs/exercise2d.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Exercise 2d: invent your own!
2+
3+
Make up your own HTML tag! Do it at both the browser and server side.

0 commit comments

Comments
 (0)