fasdfsa commited on
Commit
fab29d7
·
1 Parent(s): 40b7e90
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +12 -0
  2. .gitignore +25 -0
  3. .gitmodules +6 -0
  4. Clean-Temporary-Files.cmd +11 -0
  5. EpubReader/.github/ISSUE_TEMPLATE/bug_report.md +20 -0
  6. EpubReader/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  7. EpubReader/.github/ISSUE_TEMPLATE/question.md +10 -0
  8. EpubReader/.github/pull_request_template.md +19 -0
  9. EpubReader/.github/workflows/build.yml +29 -0
  10. EpubReader/.github/workflows/generate-docs.yml +43 -0
  11. EpubReader/.github/workflows/publish-to-nuget.yml +29 -0
  12. EpubReader/.github/workflows/release.yml +47 -0
  13. EpubReader/.github/workflows/test.yml +32 -0
  14. EpubReader/.github/workflows/update-versions.yml +31 -0
  15. EpubReader/.gitignore +10 -0
  16. EpubReader/Documentation/docfx.json +62 -0
  17. EpubReader/Documentation/examples/example-1.md +9 -0
  18. EpubReader/Documentation/examples/example-2.md +12 -0
  19. EpubReader/Documentation/examples/example-3.md +9 -0
  20. EpubReader/Documentation/examples/toc.yml +6 -0
  21. EpubReader/Documentation/faq/index.md +32 -0
  22. EpubReader/Documentation/getting-started/index.md +134 -0
  23. EpubReader/Documentation/images/epubreader-in-a-nutshell.png +3 -0
  24. EpubReader/Documentation/images/favicon.ico +3 -0
  25. EpubReader/Documentation/images/github-icon.svg +6 -0
  26. EpubReader/Documentation/images/logo-with-title-dark.svg +25 -0
  27. EpubReader/Documentation/images/logo-with-title-light.svg +25 -0
  28. EpubReader/Documentation/images/logo-with-title.svg +25 -0
  29. EpubReader/Documentation/images/logo.svg +1 -0
  30. EpubReader/Documentation/index.md +131 -0
  31. EpubReader/Documentation/malformed-epub/index.md +127 -0
  32. EpubReader/Documentation/reference/index.md +21 -0
  33. EpubReader/Documentation/templates/default/index.html.tmpl +18 -0
  34. EpubReader/Documentation/templates/default/partials/affix.tmpl.partial +28 -0
  35. EpubReader/Documentation/templates/default/partials/class.tmpl.partial +199 -0
  36. EpubReader/Documentation/toc.yml +11 -0
  37. EpubReader/LICENSE +24 -0
  38. EpubReader/README.md +47 -0
  39. EpubReader/Release checklist.md +18 -0
  40. EpubReader/Source/.editorconfig +78 -0
  41. EpubReader/Source/EpubReader.sln +49 -0
  42. EpubReader/Source/VersOne.Epub.ConsoleDemo/ExtractPlainText.cs +32 -0
  43. EpubReader/Source/VersOne.Epub.ConsoleDemo/PrintNavigation.cs +30 -0
  44. EpubReader/Source/VersOne.Epub.ConsoleDemo/Program.cs +91 -0
  45. EpubReader/Source/VersOne.Epub.ConsoleDemo/Properties/PublishProfiles/FolderProfile.pubxml +17 -0
  46. EpubReader/Source/VersOne.Epub.ConsoleDemo/TestDirectory.cs +116 -0
  47. EpubReader/Source/VersOne.Epub.ConsoleDemo/VersOne.Epub.ConsoleDemo.csproj +30 -0
  48. EpubReader/Source/VersOne.Epub.ConsoleDemo/stylecop.json +14 -0
  49. EpubReader/Source/VersOne.Epub.Test/Comparers/CollectionComparer.cs +32 -0
  50. EpubReader/Source/VersOne.Epub.Test/Comparers/Epub2NcxComparer.cs +142 -0
.gitattributes CHANGED
@@ -1,4 +1,16 @@
1
  *.7z filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
2
  *.arrow filter=lfs diff=lfs merge=lfs -text
3
  *.bin filter=lfs diff=lfs merge=lfs -text
4
  *.bz2 filter=lfs diff=lfs merge=lfs -text
 
1
  *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.pdf filter=lfs diff=lfs merge=lfs -text
3
+ **/data/img/*.txt filter=lfs diff=lfs merge=lfs -text
4
+ src/WeChatOcrCpp/wco_data/**/* filter=lfs diff=lfs merge=lfs -text
5
+ *.aps filter=lfs diff=lfs merge=lfs -text
6
+ *.ico filter=lfs diff=lfs merge=lfs -text
7
+ *.pgm filter=lfs diff=lfs merge=lfs -text
8
+ # *.exe filter=lfs diff=lfs merge=lfs -text
9
+ # *.dll filter=lfs diff=lfs merge=lfs -text
10
+ # *.lib filter=lfs diff=lfs merge=lfs -text
11
+ # *.exp filter=lfs diff=lfs merge=lfs -text
12
+ data/img/*.txt filter=lfs diff=lfs merge=lfs -text
13
+ *.ttf filter=lfs diff=lfs merge=lfs -text
14
  *.arrow filter=lfs diff=lfs merge=lfs -text
15
  *.bin filter=lfs diff=lfs merge=lfs -text
16
  *.bz2 filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ TestResults/
2
+ .vs/
3
+
4
+ [Oo]bj*/
5
+ [Bb]in*/
6
+ [Dd]ebug*/
7
+ [Rr]elease*/
8
+ *.exe
9
+ *.dll
10
+ *.lib
11
+ *.exp
12
+
13
+ *.[Cc]ache
14
+ *.suo
15
+ *.user
16
+ *.ruleset
17
+ *.cso
18
+ *.autogenerated.cs
19
+ *.autogenerated.wxi
20
+ *.autogenerated.wxs
21
+ *_wpftmp.csproj
22
+ *.shfbproj_*
23
+ /packages
24
+ *.log
25
+ /LediReader/Properties/launchSettings.json
.gitmodules ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [submodule "HtmlToFlowDocument"]
2
+ path = HtmlToFlowDocument
3
+ url = https://github.com/lellid/HtmlToFlowDocument.git
4
+ [submodule "EpubReader"]
5
+ path = EpubReader
6
+ url = https://github.com/vers-one/EpubReader.git
Clean-Temporary-Files.cmd ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ rmdir /S /Q .\.vs
2
+ rmdir /S /Q .\EpubReader\Source\VersOne.Epub\bin
3
+ rmdir /S /Q .\EpubReader\Source\VersOne.Epub\obj
4
+ rmdir /S /Q .\HtmlToFlowDocument\HtmlToFlowDocument\bin
5
+ rmdir /S /Q .\HtmlToFlowDocument\HtmlToFlowDocument\obj
6
+ rmdir /S /Q .\HtmlToFlowDocument\HtmlToFlowDocument.Wpf\bin
7
+ rmdir /S /Q .\HtmlToFlowDocument\HtmlToFlowDocument.Wpf\obj
8
+ rmdir /S /Q .\LediReader\bin
9
+ rmdir /S /Q .\LediReader\obj
10
+ rmdir /S /Q .\SlobViewer\bin
11
+ rmdir /S /Q .\SlobViewer\obj
EpubReader/.github/ISSUE_TEMPLATE/bug_report.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ ## Description
11
+ <!-- A clear and concise description of what the bug is. If this bug is related to an unexpected exception thrown by the library, please provide the call stack of the exception here. -->
12
+
13
+ ## Sample EPUB file
14
+ <!-- Please provide a link to a sample EPUB file reproducing the bug (unless this EPUB file is under copyright restrictions). -->
15
+
16
+ ## EPUB specification link
17
+ <!-- If you believe that the library violates some parts of the EPUB standard, provide a link to a relevant EPUB specification section. EPUB 2 specification can be found here: http://idpf.org/epub/201 and the latest version of EPUB 3 specification is located here: https://www.w3.org/TR/epub-33/ -->
18
+
19
+ ## Additional context
20
+ <!-- Add any other context about the problem here. -->
EpubReader/.github/ISSUE_TEMPLATE/feature_request.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an enhancement for this library
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ ## Description
11
+ <!-- A clear and concise description of what the feature request is. If this request related to a problem, please describe the problem. -->
12
+
13
+ ## Proposed solution
14
+ <!-- A clear and concise description of what you want to happen. Provide a code sample if applicable. -->
15
+
16
+ ## Additional context
17
+ <!-- Add any other context about the feature request here. -->
EpubReader/.github/ISSUE_TEMPLATE/question.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: Question
3
+ about: Ask a question about the library
4
+ title: ''
5
+ labels: question
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ <!-- Write your question here. Provide a code sample if applicable. If your question is related to a specific EPUB file, please add a link to that file. -->
EpubReader/.github/pull_request_template.md ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # {Pull request title}
2
+
3
+ <!-- Thank you for submitting a pull request! -->
4
+
5
+ This is:
6
+ - [ ] a bug fix
7
+ - [ ] an enhancement
8
+
9
+ <!-- If you'd like to propose a new feature or implement a bug fix, please open an issue to discuss the change or find an existing issue. -->
10
+
11
+ Related issue: #{issue number}
12
+
13
+ ## Description
14
+
15
+ <!-- Describe the implementation details. -->
16
+
17
+ ## Testing steps
18
+
19
+ <!-- Describe how a reviewer can check if the bug is fixed or the feature is working properly. Provide the expected result at the end. -->
EpubReader/.github/workflows/build.yml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: windows-2022
12
+ env:
13
+ Configuration: Debug
14
+ Solution_Name: Source\EpubReader.sln
15
+ steps:
16
+ - name: Checkout
17
+ uses: actions/checkout@v4
18
+ with:
19
+ fetch-depth: 0
20
+ - name: Install .NET
21
+ uses: actions/setup-dotnet@v4
22
+ with:
23
+ dotnet-version: 9
24
+ - name: Setup MSBuild
25
+ uses: microsoft/setup-msbuild@v2
26
+ - name: Restore dependencies
27
+ run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration /p:RestorePackagesConfig=true
28
+ - name: Build solution
29
+ run: msbuild $env:Solution_Name /p:Configuration=$env:Configuration
EpubReader/.github/workflows/generate-docs.yml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Generate documentation
2
+
3
+ on: workflow_dispatch
4
+
5
+ permissions:
6
+ contents: read
7
+ pages: write
8
+ id-token: write
9
+
10
+ concurrency:
11
+ group: "pages"
12
+ cancel-in-progress: true
13
+
14
+ jobs:
15
+ generate-documentation:
16
+ environment:
17
+ name: github-pages
18
+ url: ${{ steps.deployment.outputs.page_url }}
19
+ runs-on: windows-2022
20
+ steps:
21
+ - name: Checkout
22
+ uses: actions/checkout@v4
23
+ with:
24
+ fetch-depth: 0
25
+ - name: Install .NET
26
+ uses: actions/setup-dotnet@v4
27
+ with:
28
+ dotnet-version: 9
29
+ - name: Restore dependencies
30
+ run: dotnet restore .\Source\VersOne.Epub\VersOne.Epub.csproj
31
+ - name: Install DocFX
32
+ run: dotnet tool install -g docfx
33
+ - name: Run DocFX
34
+ run: docfx Documentation\docfx.json
35
+ - name: Setup Pages
36
+ uses: actions/configure-pages@v5
37
+ - name: Upload artifact
38
+ uses: actions/upload-pages-artifact@v3
39
+ with:
40
+ path: './Documentation/docfx_output'
41
+ - name: Deploy to GitHub Pages
42
+ id: deployment
43
+ uses: actions/deploy-pages@v4
EpubReader/.github/workflows/publish-to-nuget.yml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Publish to Nuget
2
+
3
+ on: workflow_dispatch
4
+
5
+ jobs:
6
+ publish-to-nuget:
7
+ runs-on: windows-2022
8
+ env:
9
+ Configuration: Release
10
+ Solution_Name: Source\EpubReader.sln
11
+ steps:
12
+ - name: Checkout
13
+ uses: actions/checkout@v4
14
+ with:
15
+ fetch-depth: 0
16
+ - name: Install .NET
17
+ uses: actions/setup-dotnet@v4
18
+ with:
19
+ dotnet-version: 9
20
+ - name: Setup MSBuild
21
+ uses: microsoft/setup-msbuild@v2
22
+ - name: Restore dependencies
23
+ run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration /p:RestorePackagesConfig=true
24
+ - name: Build solution
25
+ run: msbuild $env:Solution_Name /p:Configuration=$env:Configuration
26
+ - name: Make Nuget package
27
+ run: nuget.exe pack Source\VersOne.Epub\VersOne.Epub.nuspec
28
+ - name: Publish Nuget package
29
+ run: nuget.exe push *.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }} -SkipDuplicate
EpubReader/.github/workflows/release.yml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Create release
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ version:
7
+ description: "Version for the release"
8
+ required: true
9
+ type: string
10
+
11
+ jobs:
12
+ create-release:
13
+ runs-on: windows-2022
14
+ env:
15
+ Configuration: Release
16
+ Solution_Name: Source\EpubReader.sln
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v4
20
+ with:
21
+ fetch-depth: 0
22
+ - name: Install .NET
23
+ uses: actions/setup-dotnet@v4
24
+ with:
25
+ dotnet-version: 9
26
+ - name: Setup MSBuild
27
+ uses: microsoft/setup-msbuild@v2
28
+ - name: Restore dependencies
29
+ run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration /p:RestorePackagesConfig=true
30
+ - name: Build solution
31
+ run: msbuild $env:Solution_Name /p:Configuration=$env:Configuration
32
+ - name: Package release files
33
+ run: |
34
+ 7z a VersOne.Epub.Net46.zip .\Source\VersOne.Epub\bin\Release\net46\VersOne.Epub.dll
35
+ 7z a VersOne.Epub.NetStandard.zip .\Source\VersOne.Epub\bin\Release\netstandard1.3\VersOne.Epub.dll
36
+ 7z a ConsoleDemo.zip .\Source\VersOne.Epub.ConsoleDemo\bin\Release\net9.0\HtmlAgilityPack.dll .\Source\VersOne.Epub.ConsoleDemo\bin\Release\net9.0\VersOne.Epub.dll .\Source\VersOne.Epub.ConsoleDemo\bin\Release\net9.0\VersOne.Epub.ConsoleDemo.dll .\Source\VersOne.Epub.ConsoleDemo\bin\Release\net9.0\VersOne.Epub.ConsoleDemo.exe .\Source\VersOne.Epub.ConsoleDemo\bin\Release\net9.0\VersOne.Epub.ConsoleDemo.deps.json .\Source\VersOne.Epub.ConsoleDemo\bin\Release\net9.0\VersOne.Epub.ConsoleDemo.runtimeconfig.json
37
+ 7z a WpfDemo.zip .\Source\VersOne.Epub.WpfDemo\bin\Release\HtmlRenderer.dll .\Source\VersOne.Epub.WpfDemo\bin\Release\HtmlRenderer.WPF.dll .\Source\VersOne.Epub.WpfDemo\bin\Release\System.IO.Compression.dll .\Source\VersOne.Epub.WpfDemo\bin\Release\VersOne.Epub.dll .\Source\VersOne.Epub.WpfDemo\bin\Release\VersOne.Epub.WpfDemo.exe
38
+ - name: Create release
39
+ uses: softprops/action-gh-release@v2
40
+ with:
41
+ tag_name: v${{ github.event.inputs.version }}
42
+ draft: true
43
+ files: |
44
+ VersOne.Epub.Net46.zip
45
+ VersOne.Epub.NetStandard.zip
46
+ ConsoleDemo.zip
47
+ WpfDemo.zip
EpubReader/.github/workflows/test.yml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: windows-2022
12
+ env:
13
+ Configuration: Debug
14
+ steps:
15
+ - name: Checkout
16
+ uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0
19
+ - name: Install .NET
20
+ uses: actions/setup-dotnet@v4
21
+ with:
22
+ dotnet-version: 9
23
+ - name: Build test project and its dependencies
24
+ run: dotnet build Source\VersOne.Epub.Test -c $env:Configuration
25
+ - name: Run unit tests
26
+ run: dotnet test Source\VersOne.Epub.Test --filter Unit --no-restore --collect:"XPlat Code Coverage" --settings Source\VersOne.Epub.Test\coverlet.runsettings
27
+ - name: Upload code coverage result to Codecov
28
+ uses: codecov/codecov-action@v4
29
+ with:
30
+ token: ${{ secrets.CODECOV_TOKEN }}
31
+ - name: Run integration tests
32
+ run: dotnet test Source\VersOne.Epub.Test --filter Integration --no-restore
EpubReader/.github/workflows/update-versions.yml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Update versions
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ version:
7
+ description: "New version for all projects"
8
+ required: true
9
+ type: string
10
+
11
+ jobs:
12
+ update-versions:
13
+ runs-on: ubuntu-latest
14
+ name: Update versions
15
+ steps:
16
+ - name: Checkout
17
+ uses: actions/checkout@v4
18
+ - name: Update project versions
19
+ id: update
20
+ uses: vers-one/dotnet-project-version-updater@v1.6
21
+ with:
22
+ file: |
23
+ "Source/VersOne.Epub/VersOne.Epub.csproj", "Source/VersOne.Epub/VersOne.Epub.nuspec", "Source/VersOne.Epub.Test/VersOne.Epub.Test.csproj", "Source/VersOne.Epub.ConsoleDemo/VersOne.Epub.ConsoleDemo.csproj", "Source/VersOne.Epub.WpfDemo/Properties/AssemblyInfo.cs"
24
+ version: ${{ github.event.inputs.version }}
25
+ - run: |
26
+ git config user.name "vers-one"
27
+ git config user.email "vers-one@users.noreply.github.com"
28
+ git add .
29
+ git commit -m "Update project versions to ${{ steps.update.outputs.newVersion }}"
30
+ git tag v${{ steps.update.outputs.newVersion }}
31
+ git push --atomic origin master v${{ steps.update.outputs.newVersion }}
EpubReader/.gitignore ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ .vs/
2
+ packages/
3
+ bin/
4
+ obj/
5
+ .misc/
6
+ *.user
7
+ Documentation/docfx_output/
8
+ Documentation/reference/*.yml
9
+ Documentation/reference/.*
10
+ coverage.*.xml
EpubReader/Documentation/docfx.json ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": [
3
+ {
4
+ "src": [
5
+ {
6
+ "src": "../Source/VersOne.Epub/",
7
+ "files": [
8
+ "*.csproj"
9
+ ]
10
+ }
11
+ ],
12
+ "dest": "reference",
13
+ "disableGitFeatures": false,
14
+ "disableDefaultFilter": false,
15
+ "properties": {
16
+ "TargetFramework": "netstandard1.3"
17
+ }
18
+ }
19
+ ],
20
+ "build": {
21
+ "content": [
22
+ {
23
+ "files": [
24
+ "*.md",
25
+ "toc.yml",
26
+ "getting-started/*.md",
27
+ "reference/*.md",
28
+ "reference/*.yml",
29
+ "examples/*.md",
30
+ "examples/toc.yml",
31
+ "malformed-epub/*.md",
32
+ "faq/*.md"
33
+ ]
34
+ }
35
+ ],
36
+ "resource": [
37
+ {
38
+ "files": [
39
+ "images/**"
40
+ ]
41
+ }
42
+ ],
43
+ "globalMetadata": {
44
+ "_appLogoPath": "images/logo.svg",
45
+ "_appFaviconPath": "images/favicon.ico"
46
+ },
47
+ "dest": "docfx_output",
48
+ "template": [
49
+ "default",
50
+ "templates/default"
51
+ ],
52
+ "xref": [
53
+ "https://learn.microsoft.com/en-us/dotnet/.xrefmap.json"
54
+ ],
55
+ "postProcessors": [],
56
+ "markdownEngineName": "markdig",
57
+ "noLangKeyword": false,
58
+ "keepFileLink": false,
59
+ "cleanupCacheHistory": false,
60
+ "disableGitFeatures": false
61
+ }
62
+ }
EpubReader/Documentation/examples/example-1.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # How to extract the table of contents
2
+
3
+ ## Example
4
+
5
+ [!code-csharp[Main](../../Source/VersOne.Epub.ConsoleDemo/PrintNavigation.cs)]
6
+
7
+ ## See it in action
8
+
9
+ Download the [.NET console demo app](https://github.com/vers-one/EpubReader/releases/latest/download/ConsoleDemo.zip), run it, and select the **1. Print book navigation tree (table of contents)** option.
EpubReader/Documentation/examples/example-2.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # How to extract the plain text of the whole book
2
+
3
+ ## Example
4
+
5
+ > [!Important]
6
+ > In order to run this example, you need to install the [HtmlAgilityPack Nuget package](https://www.nuget.org/packages/HtmlAgilityPack).
7
+
8
+ [!code-csharp[Main](../../Source/VersOne.Epub.ConsoleDemo/ExtractPlainText.cs)]
9
+
10
+ ## See it in action
11
+
12
+ Download the [.NET console demo app](https://github.com/vers-one/EpubReader/releases/latest/download/ConsoleDemo.zip), run it, and select the **2. Extract plain text from the whole book** option.
EpubReader/Documentation/examples/example-3.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # How to iterate over all EPUB files in a directory and gather some stats
2
+
3
+ ## Example
4
+
5
+ [!code-csharp[Main](../../Source/VersOne.Epub.ConsoleDemo/TestDirectory.cs)]
6
+
7
+ ## See it in action
8
+
9
+ Download the [.NET console demo app](https://github.com/vers-one/EpubReader/releases/latest/download/ConsoleDemo.zip), run it, and select the **3. Test the library by reading all EPUB files from a directory** option.
EpubReader/Documentation/examples/toc.yml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ - name: How to extract the table of contents
2
+ href: example-1.md
3
+ - name: How to extract the plain text of the whole book
4
+ href: example-2.md
5
+ - name: How to iterate over all EPUB files in a directory and gather some stats
6
+ href: example-3.md
EpubReader/Documentation/faq/index.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Frequently Asked Questions
2
+
3
+ ## How to write EPUB files?
4
+
5
+ EpubReader is only for reading EPUB files. It doesn't have a support to write them.
6
+
7
+ ## How to display a EPUB book in my application?
8
+
9
+ EpubReader allows to parse and extract the content of a EPUB book but it doesn't have any means to render the extracted content. Since a EPUB book is essentially just a collection of HTML files (along with CSS, images, fonts, etc), you need a way to render these HTML files in the same way a web browser does.
10
+
11
+ [WPF demo app](https://github.com/vers-one/EpubReader/tree/master/Source/VersOne.Epub.WpfDemo/) contains an example of how to render a EPUB book in a WPF application but the third-party HTML renderer used in this demo app is far from perfect and may have difficulties while rendering the content if the HTML structure is too complicated.
12
+
13
+ ## How to convert EPUB to PDF?
14
+
15
+ EPUB and PDF are two very different formats. EPUB is a flow-layout format which means that it usually doesn't have page breaks and can be easily scaled to occupy the whole screen of the device regardless of its size and aspect ratio. PDF on the other hand is a fixed-layout paged-based format, i.e. it determines how the whole page should look like. For example, if you increase the font size in your EPUB reader, you will be reducing the amount of text that can fit on the "page" of the reader and the number of "pages" will go up. If you scale the content of a PDF book, the number of pages will stay the same but the content of the current page may not fit into the screen of the reader.
16
+
17
+ Due to all this, there is no straightforward way to convert a EPUB book to PDF. In order to do that, you'll need to [render the EPUB book first](#how-to-display-a-epub-book-in-my-application) (allowing the end user to customize the page size, styles, fonts, font sizes, margins, table of contents' rendering options and so on) and then write the rendered content as a PDF file.
18
+
19
+ ## What are the differences between `EpubBook` and `EpubBookRef` classes?
20
+
21
+ [`EpubBook`](xref:VersOne.Epub.EpubBook) is returned by [`EpubReader.ReadBook`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_ReadBook_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_) and [`EpubReader.ReadBookAsync`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_ReadBookAsync_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_) methods. [`EpubBookRef`](xref:VersOne.Epub.EpubBookRef) is returned by [`EpubReader.OpenBook`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_OpenBook_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_) and [`EpubReader.OpenBookAsync`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_OpenBookAsync_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_) methods.
22
+
23
+ Both `EpubBook` and `EpubBookRef` classes contain parsed metadata of the EPUB book. However there are two main differences between them:
24
+ 1. Book content:
25
+ * `EpubBook` has all the content of the book (HTML, CSS, images and other files) loaded into the memory.
26
+ * `EpubBookRef` doesn't have the content loaded. Instead it lets the consumer to load individual content files on demand.
27
+ 2. File handle:
28
+ * `EpubBook`, once it's created, doesn't keep the EPUB file open, which means that the file can be changed or even deleted.
29
+ * `EpubBookRef` contains a reference to the EPUB file (to be able to load content files on demand). Instances of this class need to be disposed (either by calling the `Dispose` method or by enclosing it into a `using()` block) to release the file handle.
30
+
31
+ In the end, you should use `EpubBookRef` if you don't want the whole content of the file to be loaded into memory (for example, you are concerned about the memory consumption or the time it takes to load the whole content). Conversely, you should use `EpubBook` if you don't want the EPUB file to remain open for the whole lifetime of the `EpubBookRef` instance.
32
+
EpubReader/Documentation/getting-started/index.md ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Getting Started
2
+
3
+ ## 1. Create an app
4
+
5
+ In your command prompt, run the following command to create a .NET console app:
6
+
7
+ ```cmd
8
+ dotnet new console -o MyApp
9
+ ```
10
+
11
+ Then, navigate to the new directory created by the previous command:
12
+
13
+ ```cmd
14
+ cd MyApp
15
+ ```
16
+
17
+ ## 2. Install Nuget packages
18
+
19
+ Install EpubReader package:
20
+
21
+ ```cmd
22
+ dotnet add package VersOne.Epub
23
+ ```
24
+
25
+ Also install HtmlAgilityPack package:
26
+
27
+ ```cmd
28
+ dotnet add package HtmlAgilityPack
29
+ ```
30
+
31
+ HtmlAgilityPack will be used to extract the plain text from the HTML files of the book.
32
+
33
+ ## 3. Edit the code
34
+
35
+ Open the *Program.cs* file in the editor of your choice and replace the content of the file with the following:
36
+
37
+ ```csharp
38
+ using System.Text;
39
+ using VersOne.Epub;
40
+ using HtmlAgilityPack;
41
+
42
+ // Load the book into memory
43
+ EpubBook book = EpubReader.ReadBook("test.epub");
44
+
45
+ // Print the title and the author of the book
46
+ Console.WriteLine($"Title: {book.Title}");
47
+ Console.WriteLine($"Author: {book.Author}");
48
+ Console.WriteLine();
49
+
50
+ // Print the table of contents
51
+ Console.WriteLine("TABLE OF CONTENTS:");
52
+ PrintTableOfContents();
53
+ Console.WriteLine();
54
+
55
+ // Print the text content of all chapters in the book
56
+ Console.WriteLine("CHAPTERS:");
57
+ PrintChapters();
58
+
59
+ void PrintTableOfContents()
60
+ {
61
+ foreach (EpubNavigationItem navigationItem in book.Navigation)
62
+ {
63
+ PrintNavigationItem(navigationItem, 0);
64
+ }
65
+ }
66
+
67
+ void PrintNavigationItem(EpubNavigationItem navigationItem, int identLevel)
68
+ {
69
+ Console.Write(new string(' ', identLevel * 2));
70
+ Console.WriteLine(navigationItem.Title);
71
+ foreach (EpubNavigationItem nestedNavigationItem in navigationItem.NestedItems)
72
+ {
73
+ PrintNavigationItem(nestedNavigationItem, identLevel + 1);
74
+ }
75
+ }
76
+
77
+ void PrintChapters()
78
+ {
79
+ foreach (EpubTextContentFile textContentFile in book.ReadingOrder)
80
+ {
81
+ PrintTextContentFile(textContentFile);
82
+ }
83
+ }
84
+
85
+ void PrintTextContentFile(EpubTextContentFile textContentFile)
86
+ {
87
+ HtmlDocument htmlDocument = new();
88
+ htmlDocument.LoadHtml(textContentFile.Content);
89
+ StringBuilder sb = new();
90
+ foreach (HtmlNode node in htmlDocument.DocumentNode.SelectNodes("//text()"))
91
+ {
92
+ sb.AppendLine(node.InnerText.Trim());
93
+ }
94
+ string contentText = sb.ToString();
95
+ Console.WriteLine(contentText);
96
+ Console.WriteLine();
97
+ }
98
+ ```
99
+
100
+ ## 4. Run the app
101
+
102
+ Copy any EPUB file into the *MyApp* directory and rename the file to *test.epub*.
103
+
104
+ Then, run the app using the following command in the command prompt:
105
+
106
+ ```cmd
107
+ dotnet run
108
+ ```
109
+
110
+ The output should look similar to this:
111
+ ```text
112
+ Title: Alice's Adventures in Wonderland
113
+ Author: Lewis Carroll
114
+
115
+ TABLE OF CONTENTS:
116
+ CHAPTER I. Down the Rabbit-Hole
117
+ CHAPTER II. The Pool of Tears
118
+ CHAPTER III. A Caucus-Race and a Long Tale
119
+ CHAPTER IV. The Rabbit Sends in a Little Bill
120
+ CHAPTER V. Advice from a Caterpillar
121
+ CHAPTER VI. Pig and Pepper
122
+ CHAPTER VII. A Mad Tea-Party
123
+ CHAPTER VIII. The Queen's Croquet-Ground
124
+ CHAPTER IX. The Mock Turtle's Story
125
+ CHAPTER X. The Lobster Quadrille
126
+ CHAPTER XI. Who Stole the Tarts?
127
+ CHAPTER XII. Alice's Evidence
128
+
129
+ CHAPTERS:
130
+ CHAPTER I. Down the Rabbit-Hole
131
+
132
+ Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversations?'
133
+ ...
134
+ ```
EpubReader/Documentation/images/epubreader-in-a-nutshell.png ADDED

Git LFS Details

  • SHA256: 7b23740220f4f05f28e9d196a353cae003bab3c72f4992e2b627054973bdd3c6
  • Pointer size: 131 Bytes
  • Size of remote file: 240 kB
EpubReader/Documentation/images/favicon.ico ADDED

Git LFS Details

  • SHA256: f56d05f20555e196a820e6c9fa4752847f521ad4e7ea0892a71be5dfafdfff4d
  • Pointer size: 130 Bytes
  • Size of remote file: 14.3 kB
EpubReader/Documentation/images/github-icon.svg ADDED
EpubReader/Documentation/images/logo-with-title-dark.svg ADDED
EpubReader/Documentation/images/logo-with-title-light.svg ADDED
EpubReader/Documentation/images/logo-with-title.svg ADDED
EpubReader/Documentation/images/logo.svg ADDED
EpubReader/Documentation/index.md ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: EpubReader — .NET library for reading EPUB files
3
+ documentType: index
4
+ ---
5
+ <style type="text/css">
6
+ html
7
+ {
8
+ height: auto;
9
+ }
10
+ body
11
+ {
12
+ background: linear-gradient(219.46deg, #110036 27.63%, #170059 100%), linear-gradient(219.46deg, #FFFFFF 27.63%, #19004E 100%), radial-gradient(100% 246.94% at 100% 100%, #FFFFFF 0%, #000353 100%), linear-gradient(121.18deg, #1400FF 0.45%, #3A0000 100%), linear-gradient(337.69deg, #DC52FF 8.44%, #00BDBD 84.19%), linear-gradient(222.34deg, #FFFFFF 12.99%, #008171 87.21%), linear-gradient(150.76deg, #0015D5 15.35%, #000B6C 89.57%);
13
+ background-blend-mode: screen, overlay, overlay, difference, difference, difference, normal;
14
+ display: flex;
15
+ flex-direction: column;
16
+ min-height: 100vh;
17
+ }
18
+ header
19
+ {
20
+ position: static;
21
+ }
22
+ .navbar-inverse
23
+ {
24
+ background-color: #00000040;
25
+ border-color: #00000040;
26
+ }
27
+ .navbar-inverse .navbar-nav > li > a
28
+ {
29
+ color: #ccc;
30
+ }
31
+ #wrapper
32
+ {
33
+ flex-grow: 1;
34
+ display: flex;
35
+ flex-direction: column;
36
+ }
37
+ .main-page
38
+ {
39
+ flex-grow: 1;
40
+ display: flex;
41
+ flex-direction: row;
42
+ justify-content: center;
43
+ align-items: center;
44
+ color: #fff;
45
+ font-size: 20px;
46
+ padding: 100px;
47
+ }
48
+ .left-column
49
+ {
50
+ width: 100%;
51
+ max-width: 540px;
52
+ margin-right: 25px;
53
+ }
54
+ .left-column .svg
55
+ {
56
+ display: block;
57
+ width: 100%;
58
+ height: auto;
59
+ }
60
+ .left-column p
61
+ {
62
+ text-align: center;
63
+ }
64
+ .buttons
65
+ {
66
+ text-align: center;
67
+ margin-top: 32px;
68
+ }
69
+ .buttons a
70
+ {
71
+ font-size: 20px;
72
+ margin-bottom: 16px;
73
+ }
74
+ .buttons .glyphicon
75
+ {
76
+ margin-right: 5px;
77
+ font-size: 17px;
78
+ }
79
+ .github-logo
80
+ {
81
+ height: 22px;
82
+ vertical-align: top;
83
+ position: relative;
84
+ top: 2px;
85
+ margin-right: 4px;
86
+ }
87
+ .right-column
88
+ {
89
+ margin-left: 25px;
90
+ }
91
+ .right-column img
92
+ {
93
+ width: 100%;
94
+ max-width: 415px;
95
+ border: 10px solid #fff;
96
+ border-radius: 10px;
97
+ box-shadow: 0 0 40px #333;
98
+ }
99
+
100
+ @media only screen and (max-width: 768px)
101
+ {
102
+ .main-page
103
+ {
104
+ flex-direction: column;
105
+ padding: 16px;
106
+ }
107
+ .left-column
108
+ {
109
+ margin: 0;
110
+ }
111
+ .right-column
112
+ {
113
+ margin: 0;
114
+ }
115
+ }
116
+ </style>
117
+
118
+ <div class="main-page">
119
+ <div class="left-column">
120
+ <p><img class="svg" src="images/logo-with-title.svg"></p>
121
+ <p class="subtitle">.NET library for reading EPUB files</p>
122
+ <div class="buttons">
123
+ <a href="getting-started/index.md" class="btn btn-success btn-lg"><span class="glyphicon glyphicon-send"></span>Get Started</a>
124
+ <a href="https://github.com/vers-one/EpubReader#download-the-latest-stable-release" class="btn btn-primary btn-lg"><span class="glyphicon glyphicon-save"></span>Download</a>
125
+ <a href="https://github.com/vers-one/EpubReader" class="btn btn-default btn-lg"><img src="images/github-icon.svg" class="github-logo">View on GitHub</a>
126
+ </div>
127
+ </div>
128
+ <div class="right-column">
129
+ <img src="images/epubreader-in-a-nutshell.png">
130
+ </div>
131
+ </div>
EpubReader/Documentation/malformed-epub/index.md ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Handling Malformed EPUB files
2
+
3
+ EpubReader has a few configuration options to handle the most common cases of malformed EPUB files (i.e. the files that deviate from the EPUB specification). This can be done by creating an instance of the [`EpubReaderOptions`](xref:VersOne.Epub.Options.EpubReaderOptions) class, setting the appropriate properties (see the sections below for examples), and passing it to one of the methods of the [`EpubReader`](xref:VersOne.Epub.EpubReader) class.
4
+
5
+ ## Missing TOC attribute in EPUB 2 spine
6
+
7
+ The `spine` element of the EPUB manifest contains the `toc` attribute which is [not required](https://www.w3.org/TR/epub-33/#sec-pkg-spine) for EPUB 3 books but is [required](https://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.4) for EPUB 2 books. There are [some EPUB 2 books](https://github.com/vers-one/EpubReader/issues/41) that have the `toc` attribute missing which causes EpubReader to throw the *"Incorrect EPUB spine: TOC is missing"* exception.
8
+
9
+ [`PackageReaderOptions.IgnoreMissingToc`](xref:VersOne.Epub.Options.PackageReaderOptions#VersOne_Epub_Options_PackageReaderOptions_IgnoreMissingToc) property can be used to instruct EpubReader to ignore this error:
10
+
11
+ ```csharp
12
+ EpubReaderOptions options = new()
13
+ {
14
+ PackageReaderOptions = new PackageReaderOptions()
15
+ {
16
+ IgnoreMissingToc = true
17
+ }
18
+ };
19
+ ```
20
+
21
+ ## Invalid EPUB manifest items
22
+
23
+ The [`item` element](https://www.w3.org/TR/epub-33/#sec-item-elem) within the EPUB manifest has three required attributes: `id`, `href`, and `media-type`. There are [some EPUB books](https://github.com/vers-one/EpubReader/issues/47) that have at least one of those three attributes missing which causes EpubReader to throw the *"Incorrect EPUB manifest: item ... is missing"* exception.
24
+
25
+ [`PackageReaderOptions.SkipInvalidManifestItems`](xref:VersOne.Epub.Options.PackageReaderOptions#VersOne_Epub_Options_PackageReaderOptions_SkipInvalidManifestItems) property can be used to instruct EpubReader to ignore this error:
26
+
27
+ ```csharp
28
+ EpubReaderOptions options = new()
29
+ {
30
+ PackageReaderOptions = new PackageReaderOptions()
31
+ {
32
+ SkipInvalidManifestItems = true
33
+ }
34
+ };
35
+ ```
36
+
37
+ ## Missing content files
38
+
39
+ The [`item` element](https://www.w3.org/TR/epub-33/#sec-item-elem) within the EPUB manifest has a required `href` attribute which points to a content file in the EPUB archive. There are [some EPUB books](https://github.com/vers-one/EpubReader/issues/25) that declare content files in the EPUB manifest which do not exist in the actual EPUB archive. This causes EpubReader to throw the *"EPUB parsing error: file ... was not found in the EPUB file"* exception. Such exception is thrown immediately, if application uses [`EpubReader.ReadBook`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_ReadBook_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_) / [`EpubReader.ReadBookAsync`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_ReadBookAsync_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_) methods because they try to load the whole content of the book into memory. [`EpubReader.OpenBook`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_OpenBook_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_) and [`EpubReader.OpenBookAsync`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_OpenBookAsync_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_) methods don't load the content, so the exception will be thrown only during an attempt to call any of those methods for a missing file:
40
+ * [`EpubLocalContentFileRef`](xref:VersOne.Epub.EpubLocalContentFileRef) class:
41
+ * [`GetContentStream`](xref:VersOne.Epub.EpubLocalContentFileRef#VersOne_Epub_EpubLocalContentFileRef_GetContentStream)
42
+ * [`ReadContentAsBytes`](xref:VersOne.Epub.EpubLocalContentFileRef#VersOne_Epub_EpubLocalContentFileRef_ReadContentAsBytes)
43
+ * [`ReadContentAsBytesAsync`](xref:VersOne.Epub.EpubLocalContentFileRef#VersOne_Epub_EpubLocalContentFileRef_ReadContentAsBytesAsync)
44
+ * [`ReadContentAsText`](xref:VersOne.Epub.EpubLocalContentFileRef#VersOne_Epub_EpubLocalContentFileRef_ReadContentAsText)
45
+ * [`ReadContentAsTextAsync`](xref:VersOne.Epub.EpubLocalContentFileRef#VersOne_Epub_EpubLocalContentFileRef_ReadContentAsTextAsync)
46
+ * [`EpubLocalByteContentFileRef`](xref:VersOne.Epub.EpubLocalByteContentFileRef) class:
47
+ * [`ReadContent`](xref:VersOne.Epub.EpubLocalByteContentFileRef#VersOne_Epub_EpubLocalByteContentFileRef_ReadContent)
48
+ * [`ReadContentAsync`](xref:VersOne.Epub.EpubLocalByteContentFileRef#VersOne_Epub_EpubLocalByteContentFileRef_ReadContentAsync)
49
+ * [`EpubLocalTextContentFileRef`](xref:VersOne.Epub.EpubLocalTextContentFileRef) class:
50
+ * [`ReadContent`](xref:VersOne.Epub.EpubLocalTextContentFileRef#VersOne_Epub_EpubLocalTextContentFileRef_ReadContent)
51
+ * [`ReadContentAsync`](xref:VersOne.Epub.EpubLocalTextContentFileRef#VersOne_Epub_EpubLocalTextContentFileRef_ReadContentAsync)
52
+
53
+ [`ContentReaderOptions.ContentFileMissing`](xref:VersOne.Epub.Options.ContentReaderOptions#VersOne_Epub_Options_ContentReaderOptions_ContentFileMissing) event can be used to detect those issues and to instruct EpubReader how to handle missing content files. Application can choose one of the following options:
54
+
55
+ ### 1. Get notified about missing content files
56
+
57
+ ```csharp
58
+ EpubReaderOptions options = new();
59
+ options.ContentReaderOptions.ContentFileMissing += (sender, e) =>
60
+ {
61
+ Console.WriteLine($"Content file is missing: content file name = '{e.FileName}', content file path in the EPUB archive = '{e.FilePathInEpubArchive}', content type = {e.ContentType}, MIME type = {e.ContentMimeType}.");
62
+ };
63
+ ```
64
+
65
+ This will let application to be notified about the missing content file but will not prevent the exception from being thrown by the EpubReader.
66
+
67
+ ### 2. Suppress exceptions
68
+
69
+ ```csharp
70
+ EpubReaderOptions options = new();
71
+ options.ContentReaderOptions.ContentFileMissing += (sender, e) =>
72
+ {
73
+ e.SuppressException = true;
74
+ };
75
+ ```
76
+
77
+ This will suppress all missing content file exceptions from being thrown. The EpubReader will treat missing content files as existing but empty files.
78
+
79
+ ### 3. Provide a replacement content
80
+
81
+ ```csharp
82
+ EpubReaderOptions options = new();
83
+ options.ContentReaderOptions.ContentFileMissing += (sender, e) =>
84
+ {
85
+ if (e.FileName == "chapter1.html")
86
+ {
87
+ e.ReplacementContentStream = new FileStream(@"C:\Temp\chapter1-replacement.html", FileMode.Open);
88
+ }
89
+ };
90
+ ```
91
+
92
+ This will let application to substitute the content of a missing file with another content. The value of the [`ReplacementContentStream`](xref:VersOne.Epub.Options.ContentFileMissingEventArgs#VersOne_Epub_Options_ContentFileMissingEventArgs_ReplacementContentStream) property can be any [`Stream`](xref:System.IO.Stream). The content of the stream is read only once, after which it will be cached in the EPUB content reader. The stream will be closed after its content is fully read.
93
+
94
+ ## Missing content attribute for EPUB 2 NCX navigation points
95
+
96
+ The `navPoint` element within the [EPUB 2 NCX navigation document](https://daisy.org/activities/standards/daisy/daisy-3/z39-86-2005-r2012-specifications-for-the-digital-talking-book/#NCX) must contain a nested `content` element pointing to a content file associated with this navigation item. There are some EPUB 2 books that have navigation points without a nested `content` element which causes EpubReader to throw the *"EPUB parsing error: navigation point X should contain content"* exception.
97
+
98
+ [`Epub2NcxReaderOptions.IgnoreMissingContentForNavigationPoints`](xref:VersOne.Epub.Options.Epub2NcxReaderOptions#VersOne_Epub_Options_Epub2NcxReaderOptions_IgnoreMissingContentForNavigationPoints) property can be used to instruct EpubReader to skip such navigation points (as well as all their child navigation points):
99
+
100
+ ```csharp
101
+ EpubReaderOptions options = new()
102
+ {
103
+ Epub2NcxReaderOptions = new Epub2NcxReaderOptions()
104
+ {
105
+ IgnoreMissingContentForNavigationPoints = true
106
+ }
107
+ };
108
+ ```
109
+
110
+ ## Handling XML 1.1 schema files
111
+
112
+ .NET [doesn't have](https://stackoverflow.com/questions/17231675/does-net-4-5-support-xml-1-1-yet-for-characters-invalid-in-xml-1-0) a built-in support for XML 1.1 files (only XML 1.0 files are currently supported). There are [some EPUB books](https://github.com/vers-one/EpubReader/issues/34) that have at least one of their schema files (typically the OPF package file) saved in XML 1.1 format, even though they don't use any XML 1.1 features. This causes EpubReader to throw an `XmlException` with the *"Version number '1.1' is invalid"* message.
113
+
114
+ [`XmlReaderOptions.SkipXmlHeaders`](xref:VersOne.Epub.Options.XmlReaderOptions#VersOne_Epub_Options_XmlReaderOptions_SkipXmlHeaders) property can be used to enable a workaround for handling XML 1.1 files in EpubReader:
115
+
116
+ ```csharp
117
+ EpubReaderOptions options = new()
118
+ {
119
+ XmlReaderOptions = new XmlReaderOptions()
120
+ {
121
+ SkipXmlHeaders = true
122
+ }
123
+ };
124
+ ```
125
+
126
+ > [!Important]
127
+ > Keep in mind that enabling this workaround adds an additional overhead for processing all schema files within EPUB book. If this property is set to `true`, EpubReader will check if an XML file contains a declaration (`<?xml version="..." encoding="UTF-8"?>`) in which case the reader will skip it before passing the file to the underlying .NET `XDocument` class.
EpubReader/Documentation/reference/index.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Class Reference
2
+
3
+ ## Core classes
4
+
5
+ |Class Name |Description |
6
+ |------------------------------------------------------------------|--------------------------------------------------------------------------|
7
+ |[`EpubReader`](xref:VersOne.Epub.EpubReader) |The main static class that provides methods like [`OpenBook`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_OpenBook_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_) and [`ReadBook`](xref:VersOne.Epub.EpubReader#VersOne_Epub_EpubReader_ReadBook_System_IO_Stream_VersOne_Epub_Options_EpubReaderOptions_)|
8
+ |[`EpubBook`](xref:VersOne.Epub.EpubBook) |Represents a EPUB book with all its content and metadata |
9
+ |[`EpubBookRef`](xref:VersOne.Epub.EpubBookRef) |Represents a EPUB book with its metadata but with no content |
10
+ |[`EpubContent`](xref:VersOne.Epub.EpubContent) |A container for all content files within the EPUB book |
11
+ |[`EpubSchema`](xref:VersOne.Epub.EpubSchema) |Parsed content of all EPUB schema files |
12
+ |[`EpubReaderOptions`](xref:VersOne.Epub.Options.EpubReaderOptions)|Various options to configure the behavior of the EPUB reader |
13
+
14
+ ## Namespaces
15
+
16
+ |Namespace |Description |
17
+ |-----------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
18
+ |[`VersOne.Epub`](xref:VersOne.Epub) |The main namespace containing core classes like [`EpubReader`](xref:VersOne.Epub.EpubReader) and [`EpubBook`](xref:VersOne.Epub.EpubBook)|
19
+ |[`VersOne.Epub.Options`](xref:VersOne.Epub.Options) |Contains classes that configure the behavior of the EPUB reader |
20
+ |[`VersOne.Epub.Schema`](xref:VersOne.Epub.Schema) |Contains classes representing the raw EPUB schema fields |
21
+ |[`VersOne.Epub.Environment`](xref:VersOne.Epub.Environment)|Contains interfaces that provide environment abstractions (e.g. file system) to facilitate unit testing|
EpubReader/Documentation/templates/default/index.html.tmpl ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{!include(/^styles/.*/)}}
2
+ {{!include(/^fonts/.*/)}}
3
+ {{!include(favicon.ico)}}
4
+ {{!include(logo.svg)}}
5
+ <!DOCTYPE html>
6
+ <!--[if IE]><![endif]-->
7
+ <html>
8
+ {{>partials/head}}
9
+ <body data-spy="scroll" data-target="#affix">
10
+ <div id="wrapper">
11
+ <header>
12
+ {{>partials/navbar}}
13
+ </header>
14
+ {{{conceptual}}}
15
+ </div>
16
+ {{>partials/scripts}}
17
+ </body>
18
+ </html>
EpubReader/Documentation/templates/default/partials/affix.tmpl.partial ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{!Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}}
2
+
3
+ <div class="hidden-sm col-md-2" role="complementary">
4
+ <div class="sideaffix">
5
+ {{^_disableContribution}}
6
+ <div class="contribution">
7
+ <ul class="nav">
8
+ {{^sourceurl}}
9
+ {{#docurl}}
10
+ <li>
11
+ <a href="{{docurl}}" class="contribution-link">{{__global.improveThisDoc}}</a>
12
+ </li>
13
+ {{/docurl}}
14
+ {{/sourceurl}}
15
+ {{#sourceurl}}
16
+ <li>
17
+ <a href="{{sourceurl}}" class="contribution-link">{{__global.viewSource}}</a>
18
+ </li>
19
+ {{/sourceurl}}
20
+ </ul>
21
+ </div>
22
+ {{/_disableContribution}}
23
+ <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
24
+ <h5>{{__global.inThisArticle}}</h5>
25
+ <div></div>
26
+ </nav>
27
+ </div>
28
+ </div>
EpubReader/Documentation/templates/default/partials/class.tmpl.partial ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{>partials/class.header}}
2
+ {{#children}}
3
+ <h3 id="{{id}}">{{>partials/classSubtitle}}</h3>
4
+ {{#children}}
5
+ {{^_disableContribution}}
6
+ {{#sourceurl}}
7
+ <span class="small pull-right mobile-hide">
8
+ <a href="{{sourceurl}}">{{__global.viewSource}}</a>
9
+ </span>{{/sourceurl}}
10
+ {{/_disableContribution}}
11
+ {{#overload}}
12
+ <a id="{{id}}" data-uid="{{uid}}"></a>
13
+ {{/overload}}
14
+ <h4 id="{{id}}" data-uid="{{uid}}">{{name.0.value}}</h4>
15
+ <div class="markdown level1 summary">{{{summary}}}</div>
16
+ <div class="markdown level1 conceptual">{{{conceptual}}}</div>
17
+ <h5 class="decalaration">{{__global.declaration}}</h5>
18
+ {{#syntax}}
19
+ <div class="codewrapper">
20
+ <pre><code class="lang-{{_lang}} hljs">{{syntax.content.0.value}}</code></pre>
21
+ </div>
22
+ {{#parameters.0}}
23
+ <h5 class="parameters">{{__global.parameters}}</h5>
24
+ <table class="table table-bordered table-striped table-condensed">
25
+ <thead>
26
+ <tr>
27
+ <th>{{__global.type}}</th>
28
+ <th>{{__global.name}}</th>
29
+ <th>{{__global.description}}</th>
30
+ </tr>
31
+ </thead>
32
+ <tbody>
33
+ {{/parameters.0}}
34
+ {{#parameters}}
35
+ <tr>
36
+ <td>{{{type.specName.0.value}}}</td>
37
+ <td><span class="parametername">{{{id}}}</span></td>
38
+ <td>{{{description}}}</td>
39
+ </tr>
40
+ {{/parameters}}
41
+ {{#parameters.0}}
42
+ </tbody>
43
+ </table>
44
+ {{/parameters.0}}
45
+ {{#return}}
46
+ <h5 class="returns">{{__global.returns}}</h5>
47
+ <table class="table table-bordered table-striped table-condensed">
48
+ <thead>
49
+ <tr>
50
+ <th>{{__global.type}}</th>
51
+ <th>{{__global.description}}</th>
52
+ </tr>
53
+ </thead>
54
+ <tbody>
55
+ <tr>
56
+ <td>{{{type.specName.0.value}}}</td>
57
+ <td>{{{description}}}</td>
58
+ </tr>
59
+ </tbody>
60
+ </table>
61
+ {{/return}}
62
+ {{#typeParameters.0}}
63
+ <h5 class="typeParameters">{{__global.typeParameters}}</h5>
64
+ <table class="table table-bordered table-striped table-condensed">
65
+ <thead>
66
+ <tr>
67
+ <th>{{__global.name}}</th>
68
+ <th>{{__global.description}}</th>
69
+ </tr>
70
+ </thead>
71
+ <tbody>
72
+ {{/typeParameters.0}}
73
+ {{#typeParameters}}
74
+ <tr>
75
+ <td><span class="parametername">{{{id}}}</span></td>
76
+ <td>{{{description}}}</td>
77
+ </tr>
78
+ {{/typeParameters}}
79
+ {{#typeParameters.0}}
80
+ </tbody>
81
+ </table>
82
+ {{/typeParameters.0}}
83
+ {{#fieldValue}}
84
+ <h5 class="fieldValue">{{__global.fieldValue}}</h5>
85
+ <table class="table table-bordered table-striped table-condensed">
86
+ <thead>
87
+ <tr>
88
+ <th>{{__global.type}}</th>
89
+ <th>{{__global.description}}</th>
90
+ </tr>
91
+ </thead>
92
+ <tbody>
93
+ <tr>
94
+ <td>{{{type.specName.0.value}}}</td>
95
+ <td>{{{description}}}</td>
96
+ </tr>
97
+ </tbody>
98
+ </table>
99
+ {{/fieldValue}}
100
+ {{#propertyValue}}
101
+ <h5 class="propertyValue">Property type: {{{type.specName.0.value}}}</h5>
102
+ {{/propertyValue}}
103
+ {{#eventType}}
104
+ <h5 class="eventType">Event type: {{{type.specName.0.value}}}</h5>
105
+ {{/eventType}}
106
+ {{/syntax}}
107
+ {{#overridden}}
108
+ <h5 class="overrides">{{__global.overrides}}</h5>
109
+ <div><xref uid="{{uid}}" altProperty="fullName" displayProperty="nameWithType"/></div>
110
+ {{/overridden}}
111
+ {{#remarks}}
112
+ <h5 id="{{id}}_remarks">{{__global.remarks}}</h5>
113
+ <div class="markdown level1 remarks">{{{remarks}}}</div>
114
+ {{/remarks}}
115
+ {{#example.0}}
116
+ <h5 id="{{id}}_examples">{{__global.examples}}</h5>
117
+ {{/example.0}}
118
+ {{#example}}
119
+ {{{.}}}
120
+ {{/example}}
121
+ {{#exceptions.0}}
122
+ <h5 class="exceptions">{{__global.exceptions}}</h5>
123
+ <table class="table table-bordered table-striped table-condensed">
124
+ <thead>
125
+ <tr>
126
+ <th>{{__global.type}}</th>
127
+ <th>{{__global.condition}}</th>
128
+ </tr>
129
+ </thead>
130
+ <tbody>
131
+ {{/exceptions.0}}
132
+ {{#exceptions}}
133
+ <tr>
134
+ <td>{{{type.specName.0.value}}}</td>
135
+ <td>{{{description}}}</td>
136
+ </tr>
137
+ {{/exceptions}}
138
+ {{#exceptions.0}}
139
+ </tbody>
140
+ </table>
141
+ {{/exceptions.0}}
142
+ {{#seealso.0}}
143
+ <h5 id="{{id}}_seealso">{{__global.seealso}}</h5>
144
+ <div class="seealso">
145
+ {{/seealso.0}}
146
+ {{#seealso}}
147
+ {{#isCref}}
148
+ <div>{{{type.specName.0.value}}}</div>
149
+ {{/isCref}}
150
+ {{^isCref}}
151
+ <div>{{{url}}}</div>
152
+ {{/isCref}}
153
+ {{/seealso}}
154
+ {{#seealso.0}}
155
+ </div>
156
+ {{/seealso.0}}
157
+ {{/children}}
158
+ {{/children}}
159
+ {{#implements.0}}
160
+ <h3 id="implements">{{__global.implements}}</h3>
161
+ {{/implements.0}}
162
+ {{#implements}}
163
+ <div>
164
+ {{#definition}}
165
+ <xref uid="{{definition}}" altProperty="fullName" displayProperty="nameWithType"/>
166
+ {{/definition}}
167
+ {{^definition}}
168
+ <xref uid="{{uid}}" altProperty="fullName" displayProperty="nameWithType"/>
169
+ {{/definition}}
170
+ </div>
171
+ {{/implements}}
172
+ {{#extensionMethods.0}}
173
+ <h3 id="extensionmethods">{{__global.extensionMethods}}</h3>
174
+ {{/extensionMethods.0}}
175
+ {{#extensionMethods}}
176
+ <div>
177
+ {{#definition}}
178
+ <xref uid="{{definition}}" altProperty="fullName" displayProperty="nameWithType"/>
179
+ {{/definition}}
180
+ {{^definition}}
181
+ <xref uid="{{uid}}" altProperty="fullName" displayProperty="nameWithType"/>
182
+ {{/definition}}
183
+ </div>
184
+ {{/extensionMethods}}
185
+ {{#seealso.0}}
186
+ <h3 id="seealso">{{__global.seealso}}</h3>
187
+ <div class="seealso">
188
+ {{/seealso.0}}
189
+ {{#seealso}}
190
+ {{#isCref}}
191
+ <div>{{{type.specName.0.value}}}</div>
192
+ {{/isCref}}
193
+ {{^isCref}}
194
+ <div>{{{url}}}</div>
195
+ {{/isCref}}
196
+ {{/seealso}}
197
+ {{#seealso.0}}
198
+ </div>
199
+ {{/seealso.0}}
EpubReader/Documentation/toc.yml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ - name: Getting Started
2
+ href: getting-started/index.md
3
+ - name: Class Reference
4
+ href: reference/
5
+ homepage: reference/index.md
6
+ - name: Examples
7
+ href: examples/
8
+ - name: Malformed EPUB files
9
+ href: malformed-epub/index.md
10
+ - name: FAQ
11
+ href: faq/index.md
EpubReader/LICENSE ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
EpubReader/README.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="Documentation/images/logo-with-title-dark.svg">
3
+ <source media="(prefers-color-scheme: light)" srcset="Documentation/images/logo-with-title-light.svg">
4
+ <img alt="EpubReader logo with title" src="Documentation/images/logo-with-title-light.svg">
5
+ </picture>
6
+
7
+ .NET library for reading EPUB files.
8
+
9
+ [![Build](https://github.com/vers-one/EpubReader/actions/workflows/build.yml/badge.svg)](https://github.com/vers-one/EpubReader/actions/workflows/build.yml)
10
+ [![Tests](https://github.com/vers-one/EpubReader/actions/workflows/test.yml/badge.svg)](https://github.com/vers-one/EpubReader/actions/workflows/test.yml)
11
+ [![Test coverage](https://codecov.io/gh/vers-one/EpubReader/branch/master/graph/badge.svg?token=19RoYjPa56)](https://codecov.io/gh/vers-one/EpubReader)
12
+ [![NuGet](https://img.shields.io/nuget/v/VersOne.Epub.svg)](https://www.nuget.org/packages/VersOne.Epub)
13
+
14
+ Supported EPUB standards:
15
+ * EPUB 2 (2.0, 2.0.1)
16
+ * EPUB 3 (3.0, 3.0.1, 3.1, 3.2, 3.3)
17
+
18
+ Supported runtimes:
19
+ * .NET Standard >= 1.3 (includes .NET Core >= 1.0 and .NET >= 5)
20
+ * .NET Framework >= 4.6
21
+
22
+ [Download](#download-the-latest-stable-release) | [Documentation](https://os.vers.one/EpubReader/) | [WPF & .NET 9 console demo apps](#demo-apps)
23
+
24
+ ## EpubReader in a nutshell
25
+ ![EpubReader in a nutshell](Documentation/images/epubreader-in-a-nutshell.png)
26
+
27
+ ## Demo apps
28
+ * [Download WPF demo app](https://github.com/vers-one/EpubReader/releases/latest/download/WpfDemo.zip) (WpfDemo.zip)
29
+
30
+ This .NET Framework application demonstrates how to open EPUB books and extract their content using the library.
31
+
32
+ HTML renderer used in this demo app may have difficulties while rendering content for some of the books if the HTML structure is too complicated.
33
+
34
+ * [Download .NET 9 console demo app](https://github.com/vers-one/EpubReader/releases/latest/download/ConsoleDemo.zip) (ConsoleDemo.zip)
35
+
36
+ This .NET 9 console application demonstrates how to open EPUB books and retrieve their text content.
37
+
38
+ ## Examples
39
+ 1. [How to extract the table of contents.](https://os.vers.one/EpubReader/examples/example-1.html)
40
+ 2. [How to extract the plain text of the whole book.](https://os.vers.one/EpubReader/examples/example-2.html)
41
+ 3. [How to iterate over all EPUB files in a directory and gather some stats.](https://os.vers.one/EpubReader/examples/example-3.html)
42
+
43
+ ## Download the latest stable release
44
+ * [Download from nuget.org](https://www.nuget.org/packages/VersOne.Epub)
45
+ * DLL file from GitHub:
46
+ * [for .NET Framework](https://github.com/vers-one/EpubReader/releases/latest/download/VersOne.Epub.Net46.zip)
47
+ * [for .NET Standard](https://github.com/vers-one/EpubReader/releases/latest/download/VersOne.Epub.NetStandard.zip)
EpubReader/Release checklist.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Release checklist
2
+
3
+ ## Checks
4
+
5
+ 1. Release milestone doesn't have open issues.
6
+ 2. Documentation has been updated with the changes from the new release.
7
+ 3. README.md file is updated, if necessary.
8
+ 4. All CI checks are passing for the last commit.
9
+
10
+ ## Release procedure
11
+
12
+ 1. Prepare the change log markdown file for the GitHub release description.
13
+ 2. Run **Generate documentation** action.
14
+ 3. Run **Update versions** action with version = `<major>.<minor>.<patch>` format (without `v` prefix). If this is a pre-release version which requires `-alpha` or `-beta` postfixes, the versions need to be updated via a manual code change.
15
+ 4. Run **Publish to Nuget** action.
16
+ 5. Run **Create release** action with version = `<major>.<minor>.<patch>` format (without `v` prefix). This action can also be used for pre-release versions which require `-alpha` or `-beta` postfixes.
17
+ 6. Update the release description for the release draft generated at the previous step and publish the release.
18
+ 7. Make sure that Nuget package published at the step 5 is visible on the Nuget website and the Nuget badge on the Readme page is pointing to the new release.
EpubReader/Source/.editorconfig ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [*]
2
+
3
+ # Visual Studio Spell Checker configuration
4
+ spelling_languages = en-us
5
+ spelling_error_severity = error
6
+ spelling_exclusion_path = .\spell_exclusion.dic
7
+
8
+ [*.cs]
9
+
10
+ # IDE0005: Using directive is unnecessary.
11
+ dotnet_diagnostic.IDE0005.severity = error
12
+
13
+ # IDE0008: Use explicit type
14
+ csharp_style_var_when_type_is_apparent = false
15
+ csharp_style_var_for_built_in_types = false
16
+ csharp_style_var_elsewhere = false
17
+ dotnet_diagnostic.IDE0008.severity = error
18
+
19
+ # IDE0017: Use object initializers
20
+ dotnet_diagnostic.IDE0017.severity = none
21
+
22
+ # IDE0018: Inline variable declaration
23
+ dotnet_diagnostic.IDE0018.severity = error
24
+
25
+ # IDE0060: Remove unused parameter
26
+ dotnet_diagnostic.IDE0060.severity = error
27
+
28
+ # IDE0090: Use 'new(...)'
29
+ dotnet_diagnostic.IDE0090.severity = error
30
+
31
+ # IDE0130: Namespace does not match folder structure
32
+ dotnet_style_namespace_match_folder = false
33
+
34
+ # S1168: Empty arrays and collections should be returned instead of null
35
+ dotnet_diagnostic.S1168.severity = none
36
+
37
+ # S3267: Loops should be simplified with "LINQ" expressions
38
+ dotnet_diagnostic.S3267.severity = none
39
+
40
+ # S3925: "ISerializable" should be implemented correctly
41
+ # .NET Standard 1.3 doesn't have [Serializable] attribute
42
+ dotnet_diagnostic.S3925.severity = none
43
+
44
+ # S3963: "static" fields should be initialized inline
45
+ dotnet_diagnostic.S3963.severity = none
46
+
47
+ # SA1101: Prefix local calls with this
48
+ dotnet_diagnostic.SA1101.severity = none
49
+
50
+ # SA1117: Parameters should be on same line or separate lines
51
+ dotnet_diagnostic.SA1117.severity = none
52
+
53
+ # SA1121: Use built-in type alias
54
+ dotnet_diagnostic.SA1121.severity = none
55
+
56
+ # SA1200: Using directives should be placed correctly
57
+ dotnet_diagnostic.SA1200.severity = none
58
+
59
+ # SA1310: Field names should not contain underscore
60
+ dotnet_diagnostic.SA1310.severity = none
61
+
62
+ # SA1311: Static readonly fields should begin with upper-case letter
63
+ dotnet_diagnostic.SA1311.severity = none
64
+
65
+ # SA1413: Use trailing comma in multi-line initializers
66
+ dotnet_diagnostic.SA1413.severity = none
67
+
68
+ # SA1513: Closing brace should be followed by blank line
69
+ dotnet_diagnostic.SA1513.severity = none
70
+
71
+ # SA1633: File should have header
72
+ dotnet_diagnostic.SA1633.severity = none
73
+
74
+ # SA1516: Elements should be separated by blank line
75
+ dotnet_diagnostic.SA1516.severity = none
76
+
77
+ # xUnit1004: Test methods should not be skipped
78
+ dotnet_diagnostic.xUnit1004.severity = none
EpubReader/Source/EpubReader.sln ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 
2
+ Microsoft Visual Studio Solution File, Format Version 12.00
3
+ # Visual Studio Version 17
4
+ VisualStudioVersion = 17.1.32210.238
5
+ MinimumVisualStudioVersion = 10.0.40219.1
6
+ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VersOne.Epub", "VersOne.Epub\VersOne.Epub.csproj", "{313E44F0-4BC2-4A4F-B24B-C29D8FFB7C4E}"
7
+ EndProject
8
+ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VersOne.Epub.WpfDemo", "VersOne.Epub.WpfDemo\VersOne.Epub.WpfDemo.csproj", "{2C48D6FB-EC93-4B79-8E52-79B579B3C324}"
9
+ EndProject
10
+ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VersOne.Epub.ConsoleDemo", "VersOne.Epub.ConsoleDemo\VersOne.Epub.ConsoleDemo.csproj", "{A6ED4735-3D37-4E44-BEE4-218C6BBAC1BD}"
11
+ EndProject
12
+ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{60C29813-44AB-4FBF-B12C-81FF5968BFC8}"
13
+ ProjectSection(SolutionItems) = preProject
14
+ .editorconfig = .editorconfig
15
+ spell_exclusion.dic = spell_exclusion.dic
16
+ EndProjectSection
17
+ EndProject
18
+ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VersOne.Epub.Test", "VersOne.Epub.Test\VersOne.Epub.Test.csproj", "{2FCDA010-24D2-43E4-B58C-07E88434A966}"
19
+ EndProject
20
+ Global
21
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
22
+ Debug|Any CPU = Debug|Any CPU
23
+ Release|Any CPU = Release|Any CPU
24
+ EndGlobalSection
25
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
26
+ {313E44F0-4BC2-4A4F-B24B-C29D8FFB7C4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27
+ {313E44F0-4BC2-4A4F-B24B-C29D8FFB7C4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
28
+ {313E44F0-4BC2-4A4F-B24B-C29D8FFB7C4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
29
+ {313E44F0-4BC2-4A4F-B24B-C29D8FFB7C4E}.Release|Any CPU.Build.0 = Release|Any CPU
30
+ {2C48D6FB-EC93-4B79-8E52-79B579B3C324}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31
+ {2C48D6FB-EC93-4B79-8E52-79B579B3C324}.Debug|Any CPU.Build.0 = Debug|Any CPU
32
+ {2C48D6FB-EC93-4B79-8E52-79B579B3C324}.Release|Any CPU.ActiveCfg = Release|Any CPU
33
+ {2C48D6FB-EC93-4B79-8E52-79B579B3C324}.Release|Any CPU.Build.0 = Release|Any CPU
34
+ {A6ED4735-3D37-4E44-BEE4-218C6BBAC1BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35
+ {A6ED4735-3D37-4E44-BEE4-218C6BBAC1BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
36
+ {A6ED4735-3D37-4E44-BEE4-218C6BBAC1BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
37
+ {A6ED4735-3D37-4E44-BEE4-218C6BBAC1BD}.Release|Any CPU.Build.0 = Release|Any CPU
38
+ {2FCDA010-24D2-43E4-B58C-07E88434A966}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39
+ {2FCDA010-24D2-43E4-B58C-07E88434A966}.Debug|Any CPU.Build.0 = Debug|Any CPU
40
+ {2FCDA010-24D2-43E4-B58C-07E88434A966}.Release|Any CPU.ActiveCfg = Release|Any CPU
41
+ {2FCDA010-24D2-43E4-B58C-07E88434A966}.Release|Any CPU.Build.0 = Release|Any CPU
42
+ EndGlobalSection
43
+ GlobalSection(SolutionProperties) = preSolution
44
+ HideSolutionNode = FALSE
45
+ EndGlobalSection
46
+ GlobalSection(ExtensibilityGlobals) = postSolution
47
+ SolutionGuid = {8EEE6FCA-0A83-4845-805D-537EBCA647E1}
48
+ EndGlobalSection
49
+ EndGlobal
EpubReader/Source/VersOne.Epub.ConsoleDemo/ExtractPlainText.cs ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System;
2
+ using System.Text;
3
+ using HtmlAgilityPack;
4
+
5
+ namespace VersOne.Epub.ConsoleDemo
6
+ {
7
+ internal static class ExtractPlainText
8
+ {
9
+ public static void Run(string filePath)
10
+ {
11
+ EpubBook book = EpubReader.ReadBook(filePath);
12
+ foreach (EpubLocalTextContentFile textContentFile in book.ReadingOrder)
13
+ {
14
+ PrintTextContentFile(textContentFile);
15
+ }
16
+ }
17
+
18
+ private static void PrintTextContentFile(EpubLocalTextContentFile textContentFile)
19
+ {
20
+ HtmlDocument htmlDocument = new();
21
+ htmlDocument.LoadHtml(textContentFile.Content);
22
+ StringBuilder sb = new();
23
+ foreach (HtmlNode node in htmlDocument.DocumentNode.SelectNodes("//text()"))
24
+ {
25
+ sb.AppendLine(node.InnerText.Trim());
26
+ }
27
+ string contentText = sb.ToString();
28
+ Console.WriteLine(contentText);
29
+ Console.WriteLine();
30
+ }
31
+ }
32
+ }
EpubReader/Source/VersOne.Epub.ConsoleDemo/PrintNavigation.cs ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System;
2
+
3
+ namespace VersOne.Epub.ConsoleDemo
4
+ {
5
+ internal static class PrintNavigation
6
+ {
7
+ public static void Run(string filePath)
8
+ {
9
+ using (EpubBookRef bookRef = EpubReader.OpenBook(filePath))
10
+ {
11
+ Console.WriteLine("Navigation:");
12
+ foreach (EpubNavigationItemRef navigationItemRef in bookRef.GetNavigation())
13
+ {
14
+ PrintNavigationItem(navigationItemRef, 0);
15
+ }
16
+ }
17
+ Console.WriteLine();
18
+ }
19
+
20
+ private static void PrintNavigationItem(EpubNavigationItemRef navigationItemRef, int identLevel)
21
+ {
22
+ Console.Write(new string(' ', identLevel * 2));
23
+ Console.WriteLine(navigationItemRef.Title);
24
+ foreach (EpubNavigationItemRef nestedNavigationItemRef in navigationItemRef.NestedItems)
25
+ {
26
+ PrintNavigationItem(nestedNavigationItemRef, identLevel + 1);
27
+ }
28
+ }
29
+ }
30
+ }
EpubReader/Source/VersOne.Epub.ConsoleDemo/Program.cs ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System;
2
+ using System.IO;
3
+
4
+ namespace VersOne.Epub.ConsoleDemo
5
+ {
6
+ internal static class Program
7
+ {
8
+ private static void Main()
9
+ {
10
+ char input = '\0';
11
+ while (input != 'Q')
12
+ {
13
+ Console.WriteLine("Select example:");
14
+ Console.WriteLine("1. Print book navigation tree (table of contents)");
15
+ Console.WriteLine("2. Extract plain text from the whole book");
16
+ Console.WriteLine("3. Test the library by reading all EPUB files from a directory");
17
+ Console.WriteLine("Q. Exit");
18
+ input = Char.ToUpper(Console.ReadKey(true).KeyChar);
19
+ Console.WriteLine();
20
+ switch (input)
21
+ {
22
+ case '1':
23
+ RunFileExample(PrintNavigation.Run);
24
+ break;
25
+ case '2':
26
+ RunFileExample(ExtractPlainText.Run);
27
+ break;
28
+ case '3':
29
+ RunDirectoryExample(TestDirectory.Run);
30
+ break;
31
+ case 'Q':
32
+ break;
33
+ default:
34
+ Console.WriteLine("Input is not recognized. Please try again.");
35
+ Console.WriteLine();
36
+ break;
37
+ }
38
+ }
39
+ }
40
+
41
+ private static void RunFileExample(Action<string> example)
42
+ {
43
+ Console.Write("Enter the path to the EPUB file: ");
44
+ string filePath = Console.ReadLine();
45
+ Console.WriteLine();
46
+ if (File.Exists(filePath) && Path.GetExtension(filePath).ToLower() == ".epub")
47
+ {
48
+ try
49
+ {
50
+ example(filePath);
51
+ }
52
+ catch (Exception ex)
53
+ {
54
+ Console.WriteLine("Exception was thrown:");
55
+ Console.WriteLine(ex.ToString());
56
+ Console.WriteLine();
57
+ }
58
+ }
59
+ else
60
+ {
61
+ Console.WriteLine("File doesn't exist.");
62
+ Console.WriteLine();
63
+ }
64
+ }
65
+
66
+ private static void RunDirectoryExample(Action<string> example)
67
+ {
68
+ Console.Write("Enter the path to the directory with EPUB files: ");
69
+ string directoryPath = Console.ReadLine();
70
+ Console.WriteLine();
71
+ if (Directory.Exists(directoryPath))
72
+ {
73
+ try
74
+ {
75
+ example(directoryPath);
76
+ }
77
+ catch (Exception ex)
78
+ {
79
+ Console.WriteLine("Exception was thrown:");
80
+ Console.WriteLine(ex.ToString());
81
+ Console.WriteLine();
82
+ }
83
+ }
84
+ else
85
+ {
86
+ Console.WriteLine("Directory doesn't exist.");
87
+ Console.WriteLine();
88
+ }
89
+ }
90
+ }
91
+ }
EpubReader/Source/VersOne.Epub.ConsoleDemo/Properties/PublishProfiles/FolderProfile.pubxml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ https://go.microsoft.com/fwlink/?LinkID=208121.
4
+ -->
5
+ <Project>
6
+ <PropertyGroup>
7
+ <PublishProtocol>FileSystem</PublishProtocol>
8
+ <Configuration>Release</Configuration>
9
+ <Platform>Any CPU</Platform>
10
+ <TargetFramework>net9.0</TargetFramework>
11
+ <PublishDir>bin\Release\net9.0\publish\win-x64\</PublishDir>
12
+ <RuntimeIdentifier>win-x64</RuntimeIdentifier>
13
+ <SelfContained>false</SelfContained>
14
+ <PublishSingleFile>true</PublishSingleFile>
15
+ <PublishReadyToRun>false</PublishReadyToRun>
16
+ </PropertyGroup>
17
+ </Project>
EpubReader/Source/VersOne.Epub.ConsoleDemo/TestDirectory.cs ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.IO;
4
+ using System.Linq;
5
+
6
+ namespace VersOne.Epub.ConsoleDemo
7
+ {
8
+ internal static class TestDirectory
9
+ {
10
+ public static void Run(string directoryPath)
11
+ {
12
+ int totalFiles = 0;
13
+ Dictionary<string, int> filesByVersion = new();
14
+ List<string> filesWithErrors = new();
15
+ TestEpubDirectory(directoryPath, ref totalFiles, filesByVersion, filesWithErrors);
16
+ if (totalFiles == 0)
17
+ {
18
+ Console.WriteLine("No EPUB files found.");
19
+ }
20
+ else
21
+ {
22
+ if (filesByVersion.Any(version => version.Value > 0))
23
+ {
24
+ Console.WriteLine("Statistics");
25
+ Console.WriteLine("-----------------------------------");
26
+ Console.Write("Versions: ");
27
+ bool firstItem = true;
28
+ foreach (string epubVersionString in filesByVersion.Keys.OrderBy(version => version))
29
+ {
30
+ if (firstItem)
31
+ {
32
+ firstItem = false;
33
+ }
34
+ else
35
+ {
36
+ Console.Write(", ");
37
+ }
38
+ Console.Write(epubVersionString + ": " + filesByVersion[epubVersionString]);
39
+ }
40
+ Console.WriteLine(".");
41
+ }
42
+ if (filesWithErrors.Any())
43
+ {
44
+ Console.WriteLine("Files with errors:");
45
+ foreach (string filePath in filesWithErrors)
46
+ {
47
+ Console.WriteLine(filePath);
48
+ }
49
+ }
50
+ else
51
+ {
52
+ Console.WriteLine("No errors.");
53
+ }
54
+ Console.WriteLine();
55
+ }
56
+ }
57
+
58
+ private static void TestEpubDirectory(string directoryPath, ref int totalFiles, Dictionary<string, int> filesByVersion, List<string> filesWithErrors)
59
+ {
60
+ foreach (string subdirectoryPath in Directory.EnumerateDirectories(directoryPath))
61
+ {
62
+ TestEpubDirectory(subdirectoryPath, ref totalFiles, filesByVersion, filesWithErrors);
63
+ }
64
+ foreach (string filePath in Directory.EnumerateFiles(directoryPath, "*.epub"))
65
+ {
66
+ TestEpubFile(filePath, filesByVersion, filesWithErrors);
67
+ totalFiles++;
68
+ }
69
+ }
70
+
71
+ private static void TestEpubFile(string epubFilePath, Dictionary<string, int> filesByVersion, List<string> filesWithErrors)
72
+ {
73
+ Console.WriteLine($"File: {epubFilePath}");
74
+ Console.WriteLine("-----------------------------------");
75
+ try
76
+ {
77
+ using EpubBookRef bookRef = EpubReader.OpenBook(epubFilePath);
78
+ string epubVersionString = bookRef.Schema.Package.GetVersionString();
79
+ if (filesByVersion.TryGetValue(epubVersionString, out int fileCount))
80
+ {
81
+ fileCount++;
82
+ }
83
+ else
84
+ {
85
+ fileCount = 1;
86
+ }
87
+ filesByVersion[epubVersionString] = fileCount;
88
+ Console.WriteLine($"EPUB version: {epubVersionString}");
89
+ Console.WriteLine($"Total files: {bookRef.Content.AllFiles.Local.Count}, HTML files: {bookRef.Content.Html.Local.Count}," +
90
+ $" CSS files: {bookRef.Content.Css.Local.Count}, image files: {bookRef.Content.Images.Local.Count}, font files: {bookRef.Content.Fonts.Local.Count}.");
91
+ Console.WriteLine($"Reading order: {bookRef.GetReadingOrder().Count} file(s).");
92
+ Console.WriteLine("Navigation:");
93
+ foreach (EpubNavigationItemRef navigationItemRef in bookRef.GetNavigation())
94
+ {
95
+ PrintNavigationItem(navigationItemRef, 0);
96
+ }
97
+ }
98
+ catch (Exception exception)
99
+ {
100
+ Console.WriteLine(exception.ToString());
101
+ filesWithErrors.Add(epubFilePath);
102
+ }
103
+ Console.WriteLine();
104
+ }
105
+
106
+ private static void PrintNavigationItem(EpubNavigationItemRef navigationItemRef, int identLevel)
107
+ {
108
+ Console.Write(new string(' ', identLevel * 2));
109
+ Console.WriteLine(navigationItemRef.Title);
110
+ foreach (EpubNavigationItemRef nestedNavigationItemRef in navigationItemRef.NestedItems)
111
+ {
112
+ PrintNavigationItem(nestedNavigationItemRef, identLevel + 1);
113
+ }
114
+ }
115
+ }
116
+ }
EpubReader/Source/VersOne.Epub.ConsoleDemo/VersOne.Epub.ConsoleDemo.csproj ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <Project Sdk="Microsoft.NET.Sdk">
2
+ <PropertyGroup>
3
+ <OutputType>Exe</OutputType>
4
+ <TargetFramework>net9.0</TargetFramework>
5
+ <Authors>vers</Authors>
6
+ <Copyright>vers, 2015-2024</Copyright>
7
+ <Version>3.3.4</Version>
8
+ <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
9
+ <DocumentationFile></DocumentationFile>
10
+ <GenerateDocumentationFile>True</GenerateDocumentationFile>
11
+ <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
12
+ </PropertyGroup>
13
+ <ItemGroup>
14
+ <AdditionalFiles Include="stylecop.json" />
15
+ </ItemGroup>
16
+ <ItemGroup>
17
+ <PackageReference Include="HtmlAgilityPack" Version="1.11.61" />
18
+ <PackageReference Include="SonarAnalyzer.CSharp" Version="9.25.0.90414">
19
+ <PrivateAssets>all</PrivateAssets>
20
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21
+ </PackageReference>
22
+ <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.406">
23
+ <PrivateAssets>all</PrivateAssets>
24
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25
+ </PackageReference>
26
+ </ItemGroup>
27
+ <ItemGroup>
28
+ <ProjectReference Include="..\VersOne.Epub\VersOne.Epub.csproj" />
29
+ </ItemGroup>
30
+ </Project>
EpubReader/Source/VersOne.Epub.ConsoleDemo/stylecop.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
3
+ "settings":
4
+ {
5
+ "documentationRules":
6
+ {
7
+ "documentInternalElements": false
8
+ },
9
+ "layoutRules":
10
+ {
11
+ "newlineAtEndOfFile": "require"
12
+ }
13
+ }
14
+ }
EpubReader/Source/VersOne.Epub.Test/Comparers/CollectionComparer.cs ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ namespace VersOne.Epub.Test.Comparers
2
+ {
3
+ internal static class CollectionComparer
4
+ {
5
+ public static void CompareCollections<T>(IList<T> expected, IList<T> actual, Action<T, T> elementComparer)
6
+ {
7
+ Assert.Equal(expected.Count, actual.Count);
8
+ for (int i = 0; i < expected.Count; i++)
9
+ {
10
+ elementComparer(expected[i], actual[i]);
11
+ }
12
+ }
13
+
14
+ public static void CompareDictionaries<TKey, TValue>(IDictionary<TKey, TValue> expected, IDictionary<TKey, TValue> actual, Action<TValue, TValue> elementValueComparer)
15
+ {
16
+ Assert.Equal(expected.Count, actual.Count);
17
+ foreach (KeyValuePair<TKey, TValue> expectedKeyValuePair in expected)
18
+ {
19
+ TKey expectedKey = expectedKeyValuePair.Key;
20
+ TValue expectedValue = expectedKeyValuePair.Value;
21
+ if (actual.TryGetValue(expectedKey, out TValue? actualValue))
22
+ {
23
+ elementValueComparer(expectedValue, actualValue);
24
+ }
25
+ else
26
+ {
27
+ Assert.Fail($"Key {expectedKey} was expected but not found in the dictionary.");
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
EpubReader/Source/VersOne.Epub.Test/Comparers/Epub2NcxComparer.cs ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using VersOne.Epub.Schema;
2
+
3
+ namespace VersOne.Epub.Test.Comparers
4
+ {
5
+ internal static class Epub2NcxComparer
6
+ {
7
+ public static void CompareEpub2Ncxes(Epub2Ncx? expected, Epub2Ncx? actual)
8
+ {
9
+ if (expected == null)
10
+ {
11
+ Assert.Null(actual);
12
+ }
13
+ else
14
+ {
15
+ Assert.NotNull(actual);
16
+ CompareEpub2NcxHeads(expected.Head, actual.Head);
17
+ Assert.Equal(expected.DocTitle, actual.DocTitle);
18
+ Assert.Equal(expected.DocAuthors, actual.DocAuthors);
19
+ CompareEpub2NcxNavigationMaps(expected.NavMap, actual.NavMap);
20
+ CompareEpub2NcxPageLists(expected.PageList, actual.PageList);
21
+ CompareEpub2NcxNavigationListLists(expected.NavLists, actual.NavLists);
22
+ }
23
+ }
24
+
25
+ public static void CompareEpub2NcxHeads(Epub2NcxHead expected, Epub2NcxHead actual)
26
+ {
27
+ Assert.NotNull(actual);
28
+ CollectionComparer.CompareCollections(expected.Items, actual.Items, CompareEpub2NcxHeadMetas);
29
+ }
30
+
31
+ public static void CompareEpub2NcxNavigationMaps(Epub2NcxNavigationMap expected, Epub2NcxNavigationMap actual)
32
+ {
33
+ Assert.NotNull(actual);
34
+ CompareEpub2NcxNavigationPointLists(expected.Items, actual.Items);
35
+ }
36
+
37
+ public static void CompareEpub2NcxPageLists(Epub2NcxPageList? expected, Epub2NcxPageList? actual)
38
+ {
39
+ if (expected == null)
40
+ {
41
+ Assert.Null(actual);
42
+ }
43
+ else
44
+ {
45
+ Assert.NotNull(actual);
46
+ CompareEpub2NcxPageTargetLists(expected.Items, actual.Items);
47
+ }
48
+ }
49
+
50
+ public static void CompareEpub2NcxNavigationTargetLists(List<Epub2NcxNavigationTarget> expected, List<Epub2NcxNavigationTarget> actual)
51
+ {
52
+ CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxNavigationTargets);
53
+ }
54
+
55
+ public static void CompareEpub2NcxNavigationTargets(Epub2NcxNavigationTarget expected, Epub2NcxNavigationTarget actual)
56
+ {
57
+ Assert.Equal(expected.Id, actual.Id);
58
+ Assert.Equal(expected.Value, actual.Value);
59
+ Assert.Equal(expected.Class, actual.Class);
60
+ Assert.Equal(expected.PlayOrder, actual.PlayOrder);
61
+ CompareEpub2NcxNavigationLabelLists(expected.NavigationLabels, actual.NavigationLabels);
62
+ CompareEpub2NcxContents(expected.Content, actual.Content);
63
+ }
64
+
65
+ public static void CompareEpub2NcxPageTargetLists(List<Epub2NcxPageTarget> expected, List<Epub2NcxPageTarget> actual)
66
+ {
67
+ CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxPageTargets);
68
+ }
69
+
70
+ public static void CompareEpub2NcxPageTargets(Epub2NcxPageTarget expected, Epub2NcxPageTarget actual)
71
+ {
72
+ Assert.Equal(expected.Id, actual.Id);
73
+ Assert.Equal(expected.Value, actual.Value);
74
+ Assert.Equal(expected.Type, actual.Type);
75
+ Assert.Equal(expected.Class, actual.Class);
76
+ Assert.Equal(expected.PlayOrder, actual.PlayOrder);
77
+ CompareEpub2NcxNavigationLabelLists(expected.NavigationLabels, actual.NavigationLabels);
78
+ CompareEpub2NcxContents(expected.Content, actual.Content);
79
+ }
80
+
81
+ public static void CompareEpub2NcxHeadMetas(Epub2NcxHeadMeta expected, Epub2NcxHeadMeta actual)
82
+ {
83
+ Assert.Equal(expected.Name, actual.Name);
84
+ Assert.Equal(expected.Content, actual.Content);
85
+ Assert.Equal(expected.Scheme, actual.Scheme);
86
+ }
87
+
88
+ public static void CompareEpub2NcxNavigationListLists(List<Epub2NcxNavigationList> expected, List<Epub2NcxNavigationList> actual)
89
+ {
90
+ CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxNavigationLists);
91
+ }
92
+
93
+ public static void CompareEpub2NcxNavigationLists(Epub2NcxNavigationList expected, Epub2NcxNavigationList actual)
94
+ {
95
+ Assert.Equal(expected.Id, actual.Id);
96
+ Assert.Equal(expected.Class, actual.Class);
97
+ CompareEpub2NcxNavigationLabelLists(expected.NavigationLabels, actual.NavigationLabels);
98
+ CompareEpub2NcxNavigationTargetLists(expected.NavigationTargets, actual.NavigationTargets);
99
+ }
100
+
101
+ public static void CompareEpub2NcxNavigationLabelLists(List<Epub2NcxNavigationLabel> expected, List<Epub2NcxNavigationLabel> actual)
102
+ {
103
+ CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxNavigationLabels);
104
+ }
105
+
106
+ public static void CompareEpub2NcxNavigationLabels(Epub2NcxNavigationLabel expected, Epub2NcxNavigationLabel actual)
107
+ {
108
+ Assert.NotNull(actual);
109
+ Assert.Equal(expected.Text, actual.Text);
110
+ }
111
+
112
+ public static void CompareEpub2NcxNavigationPointLists(List<Epub2NcxNavigationPoint> expected, List<Epub2NcxNavigationPoint> actual)
113
+ {
114
+ CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxNavigationPoints);
115
+ }
116
+
117
+ public static void CompareEpub2NcxNavigationPoints(Epub2NcxNavigationPoint expected, Epub2NcxNavigationPoint actual)
118
+ {
119
+ Assert.NotNull(actual);
120
+ Assert.Equal(expected.Id, actual.Id);
121
+ Assert.Equal(expected.Class, actual.Class);
122
+ Assert.Equal(expected.PlayOrder, actual.PlayOrder);
123
+ CompareEpub2NcxNavigationLabelLists(expected.NavigationLabels, actual.NavigationLabels);
124
+ CompareEpub2NcxContents(expected.Content, actual.Content);
125
+ CompareEpub2NcxNavigationPointLists(expected.ChildNavigationPoints, actual.ChildNavigationPoints);
126
+ }
127
+
128
+ public static void CompareEpub2NcxContents(Epub2NcxContent? expected, Epub2NcxContent? actual)
129
+ {
130
+ if (expected == null)
131
+ {
132
+ Assert.Null(actual);
133
+ }
134
+ else
135
+ {
136
+ Assert.NotNull(actual);
137
+ Assert.Equal(expected.Id, actual.Id);
138
+ Assert.Equal(expected.Source, actual.Source);
139
+ }
140
+ }
141
+ }
142
+ }