-
Notifications
You must be signed in to change notification settings - Fork 15
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
Content iterator #82
Merged
Merged
Content iterator #82
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
9016389
content iterator WIP
chocolatkey e16f89f
add more manifest utilities
chocolatkey e02ade9
add CSS selector implementation
chocolatkey a7a711a
HTML content iterator MVP
chocolatkey c64ff2e
fix content
chocolatkey 5b51db4
fix typo
chocolatkey f6d7b1f
bugfix
chocolatkey f74288b
improvements to htmlconverter
chocolatkey 314eb33
update pdfcpu api
chocolatkey 15b98dc
minimizeReads for stream zip entry reading
chocolatkey f277ad9
bump up to go 1.21
chocolatkey c652c01
fix zipped range reading bug
chocolatkey 29a4d17
add safety fix
chocolatkey a8f16d9
support range reads with minimizeReads
chocolatkey 54f6297
bump action to go 1.21
chocolatkey 3c1221a
fix bytesresource
chocolatkey e0e64ef
fix bug in JSON marshalling
chocolatkey 221ff3b
fix font deobfuscating bug
chocolatkey 9a1dbc5
deduplicate contributors in WebPub JSON
chocolatkey a95526f
use atoms instead of strings for inlineTags
chocolatkey 31bb79a
fix bug in parsing of displayoptions XML
chocolatkey 4c3038f
fix mediatype test failing
chocolatkey f3c807d
Fix concurrent R/W access to link properties (#87)
chocolatkey ba558c9
Merge branch 'main' into content-iterator
chocolatkey 51f1f66
add mimetype sniffing for audio
chocolatkey ef1cdc2
Make contentImplementation private
chocolatkey f0963ce
move CSSSelector utility to internal pkg
chocolatkey 22cc345
Merge branch 'content-iterator' of github.com:readium/go-toolkit into…
chocolatkey e928aaa
fix missing refactor instances
chocolatkey 58327b0
Use AttributesHolder for Attributes function of Element interface
chocolatkey 83f6dd7
Fix properties access for ArchiveEntryLength
chocolatkey d0df31d
fix further bugs in resource properties
chocolatkey 5139988
Adjust attributes interface
chocolatkey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package content | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/readium/go-toolkit/pkg/content/element" | ||
"github.com/readium/go-toolkit/pkg/content/iterator" | ||
) | ||
|
||
type Content interface { | ||
Text(separator *string) (string, error) // Extracts the full raw text, or returns null if no text content can be found. | ||
Iterator() iterator.Iterator // Creates a new iterator for this content. | ||
Elements() ([]element.Element, error) // Returns all the elements as a list. | ||
} | ||
|
||
// Extracts the full raw text, or returns null if no text content can be found. | ||
func ContentText(content Content, separator *string) (string, error) { | ||
sep := "\n" | ||
if separator != nil { | ||
sep = *separator | ||
} | ||
var sb strings.Builder | ||
els, err := content.Elements() | ||
if err != nil { | ||
return "", err | ||
} | ||
for _, el := range els { | ||
if txel, ok := el.(element.TextualElement); ok { | ||
txt := txel.Text() | ||
if txt != "" { | ||
sb.WriteString(txel.Text()) | ||
sb.WriteString(sep) | ||
} | ||
} | ||
} | ||
return strings.TrimSuffix(sb.String(), sep), nil | ||
} | ||
|
||
func ContentElements(content Content) ([]element.Element, error) { | ||
var elements []element.Element | ||
it := content.Iterator() | ||
for { | ||
hasNext, err := it.HasNext() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !hasNext { | ||
break | ||
} | ||
elements = append(elements, it.Next()) | ||
} | ||
return elements, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Kotlin toolkit,
text()
andelements()
are in the interface with a default implementation, but they should probably be extensions instead. The only thing that should be required to implement isIterator
.Maybe we can remove them from the interface and keep only
ContentText()
andContentElements()
on the side?Alternatively if we want to keep the API easy to use,
Content
could be a struct and have aIteratorFactory
interface instead.