File tree 5 files changed +48
-4
lines changed
5 files changed +48
-4
lines changed Original file line number Diff line number Diff line change @@ -27,10 +27,9 @@ below.
27
27
## Part Two: Building a browser
28
28
29
29
* [ 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
34
33
HTML pages in the server. See how it works end-to-end.
35
34
36
35
## Part Three: Encryption
Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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!
Original file line number Diff line number Diff line change
1
+ # Exercise 2d: invent your own!
2
+
3
+ Make up your own HTML tag! Do it at both the browser and server side.
You can’t perform that action at this time.
0 commit comments