diff options
| author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
|---|---|---|
| committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
| commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
| tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/epub/utils.py | |
| parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
| download | gn-ai-master.tar.gz | |
Diffstat (limited to '.venv/lib/python3.12/site-packages/epub/utils.py')
| -rw-r--r-- | .venv/lib/python3.12/site-packages/epub/utils.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/epub/utils.py b/.venv/lib/python3.12/site-packages/epub/utils.py new file mode 100644 index 00000000..dc3a73f3 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/epub/utils.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + + +def get_node_text(node): + """ + Return the text content of an xml.dom Element Node. + + If node does not have content, this function return an empty string. + """ + text = '' + + node.normalize() + if node.firstChild and node.firstChild.data: + text = node.firstChild.data.strip() + + return text + + +def get_urlpath_part(urlpath): + """ + Return a path without url fragment (something like `#frag` at the end). + + This function allow to use path from references and NCX file to read + item from Manifest with a correct href (without losing the fragment part). + + eg.: + + url = 'text/chapter1.xhtml#part2' + href, fragment = get_urlpath_part(url) + print href # 'text/chapter1.xhtml' + print fragment # '#part2' + """ + href = urlpath + fragment = None + if urlpath.count('#'): + href, fragment = urlpath.split('#') + return (href, fragment) |
