Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An extension method for <meta> is added to the EpubHtml object #298

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ebooklib/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def __init__(self, uid=None, file_name='', media_type='', content=None, title=''
self.media_overlay = media_overlay
self.media_duration = media_duration

self.metas = []
self.links = []
self.properties = []
self.pages = []
Expand Down Expand Up @@ -297,6 +298,23 @@ def get_language(self):
"""
return self.lang

def add_meta(self, **kwgs):
"""
Add additional <meta> to the document.

>>> add_meta(name='viewport', content='width=device-width, initial-scale=1')
"""
self.metas.append(kwgs)

def get_metas(self):
"""
Returns list of additional metas defined for this document.

:Returns:
As tuple return list of metas.
"""
return (meta for meta in self.metas)

def add_link(self, **kwgs):
"""
Add additional link to the document. Links will be embeded only inside of this document.
Expand Down Expand Up @@ -402,6 +420,9 @@ def get_content(self, default=None):

_head = etree.SubElement(tree_root, 'head')

for meta in self.metas:
_meta = etree.SubElement(_head, 'meta', meta)

if self.title != '':
_title = etree.SubElement(_head, 'title')
_title.text = self.title
Expand Down