View Single Post
Old 03-27-2021, 09:11 PM   #1
ebray187
Member
ebray187 began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Dec 2020
Device: epub
Problems with Beautifulsoup with custom tags

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
ebray187 is offline   Reply With Quote