Merge lp:~martinmassera/beautifulsoup/modifying-string-docs into lp:beautifulsoup

Proposed by martin massera
Status: Needs review
Proposed branch: lp:~martinmassera/beautifulsoup/modifying-string-docs
Merge into: lp:beautifulsoup
Diff against target: 27 lines (+16/-1)
1 file modified
doc/source/index.rst (+16/-1)
To merge this branch: bzr merge lp:~martinmassera/beautifulsoup/modifying-string-docs
Reviewer Review Type Date Requested Status
Leonard Richardson Pending
Review via email: mp+371680@code.launchpad.net

Description of the change

Extending documentation for the "Modifying .string" section for the case of using a string with HTML content. Describes two ways: escaping the content and parsing the content.

To post a comment you must log in.

Unmerged revisions

523. By martin massera

Adding documentation for parsing HTML content in the "Modifying .string" section

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'doc/source/index.rst'
2--- doc/source/index.rst 2019-07-21 19:50:49 +0000
3+++ doc/source/index.rst 2019-08-22 17:41:47 +0000
4@@ -1873,7 +1873,22 @@
5 # <a href="http://example.com/">New link text.</a>
6
7 Be careful: if the tag contained other tags, they and all their
8-contents will be destroyed.
9+contents will be destroyed. If the new string contains HTML content,
10+it will be escaped and added as the tag's text::
11+
12+ html_string = "A <strong>BOLD</strong> statement"
13+
14+ tag.string = html_string
15+ tag
16+ # <a href="http://example.com/">A &lt;strong&gt;BOLD&lt;/strong&gt; statement</a>
17+
18+You can parse the HTML string by creting a
19+``BeautifulSoap`` object and appending it as tags::
20+
21+ tag.clear()
22+ tag.append(BeautifulSoup(html_string, 'html.parser'))
23+ tag
24+ # <a href="http://example.com/">A <strong>BOLD</strong> statement</a>
25
26 ``append()``
27 ------------

Subscribers

People subscribed via source and target branches

to status/vote changes: