Skip to content

Commit 438c2af

Browse files
committed
added note about "class" to html exercise
1 parent fcfc2b7 commit 438c2af

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

slides_sources/source/exercises/html_renderer.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,42 @@ You can now render some ``<p>`` tags (and others) with attributes
162162

163163
See ``test_html_output4.html``
164164

165+
.. nextslide:: the "class" attribute.
166+
167+
NOTE: if you do "proper" CSS+html, then you wouldn't specify style directly in element attributes.
168+
169+
Rather you would set the "class" attribute::
170+
171+
<p class="intro">
172+
This is my recipe for making curry purely with chocolate
173+
</p>
174+
175+
However, if you try this as a keywork argument in Python:
176+
177+
.. code-block:: ipython
178+
179+
In [1]: P("some content", class="intro")
180+
File "<ipython-input-1-7d9a6b30cd26>", line 1
181+
P("some content", class="intro")
182+
^
183+
SyntaxError: invalid syntax
184+
185+
Huh?
186+
187+
"class" is a reserved work in Python -- for making classes.
188+
So it can't be used as a keywork argument.
189+
190+
But it's a fine key in a dict, so you can put it in a dict, and pass it in with ``**``:
191+
192+
.. code-block:: python
193+
194+
attrs = {'class': 'intro'}
195+
P("some content", **attrs)
196+
197+
You could also special-case this in your code -- so your users could use "clas"
198+
with one s, and you could tranlate it in the generated html.
199+
200+
165201
Step 5:
166202
--------
167203

0 commit comments

Comments
 (0)