add script embedding
This commit is contained in:
parent
cf626546e7
commit
6b3aa602ef
14
nevernote.py
14
nevernote.py
@ -137,8 +137,18 @@ def embed_scripts(page, script_urls, base_url=None):
|
||||
continue
|
||||
print('New script: %s' % url)
|
||||
script_link = ' src="%s"' % url
|
||||
print(script_link)
|
||||
page = page.replace(script_link, '')
|
||||
script_link_idx = page.index(script_link)
|
||||
script_content = get_text(
|
||||
complete_url(url, base_url),
|
||||
content={'application/x-javascript', 'text/javascript'},
|
||||
charset=base_char
|
||||
)
|
||||
script_start = page.index('>', script_link_idx) + 1
|
||||
script_end = page.index('</script>', script_start)
|
||||
# add script content to page
|
||||
page = page[:script_start] + script_content + page[script_end:]
|
||||
# remove script src link
|
||||
page = page[:script_link_idx] + page[script_link_idx+len(script_link):]
|
||||
return page
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user