Quantcast
Channel: MobileRead Forums
Viewing all articles
Browse latest Browse all 50094

Problems with Beautifulsoup with custom tags

$
0
0
Hi!, i'm having troubles to add a custom tag with my plugin using Beautifulsoup:
The code:
Code:

    html = '<p id="nt3"><sup>[3]</sup> Note 1. <a href="../Text/Section0001.xhtml#nt3">&lt;&lt;</a></p>'
   
    ## BeautifulSoup parser
    soup = BeautifulSoup(html, "html.parser")
    orig_soup = str(soup)
    original_tag = soup.p

    dict_atributes = {"xml:lang" : "la"}
    new_tag = soup.new_tag("i", attrs=dict_atributes)
    new_tag.string = "Ibid"
    original_tag.insert(1, " ")
    original_tag.insert(2, new_tag)
    original_tag.insert(3, ".")
   
    print("OUT:\n" + str(original_tag))

Outside Sigil everything OK:
Code:

$ python test.py
OUT:
<p id="nt3"><sup>[3]</sup> <i xml:lang="la">Ibid</i>. Note 1. <a href="../Text/Section0001.xhtml#nt3">&lt;&lt;</a></p>

But from Sigil i get:
Code:

OUT:
<p id="nt3"><sup>[3]</sup> <i attrs="{'xml:lang': 'la'}">Ibid</i>. Note 1. <a href="../Text/Section0001.xhtml#nt3"><<</a></p>

Any ideas? I can't find info about Beautifulsoup Sigil's implementation.
Thanks!

PS: Using python 3.8 and Sigil 1.4.3

Viewing all articles
Browse latest Browse all 50094

Latest Images

Trending Articles



Latest Images