Skip to content

Commit

Permalink
🐛 fixed #45 兼容多看,掌阅 & mod update
Browse files Browse the repository at this point in the history
  • Loading branch information
yann0917 committed Sep 12, 2024
1 parent 316d69b commit 7577543
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 116 deletions.
Binary file modified .DS_Store
Binary file not shown.
5 changes: 1 addition & 4 deletions backend/utils/md2html.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (
)

func Md2Pdf(path, title string, md []byte) (err error) {
if err != nil {
return err
}
filePreName := filepath.Join(path, FileName(title, ""))
fileName, err := FilePath(filePreName, "pdf", false)
if err != nil {
Expand Down Expand Up @@ -50,7 +47,7 @@ func genHeadHtml() (result string) {
@font-face { font-family: "Source Code Pro"; src:local("Source Code Pro"), url("https://imgcdn.umiwi.com/ttf/0315911806889993935644188722660020367983.ttf"); }
table, tr, td, th, tbody, thead, tfoot {page-break-inside: avoid !important;}
img { page-break-inside: avoid; max-width: 100% !important;}
img.epub-footnote { padding-right:5px;}
img.epub-footnote { margin-right:5px;display: inline;font-size: 12px;}
body {font-family: PingFang SC,Arial,sans-serif,Source Code Pro;color: #333;text-align: left;line-height: 1.8;}
em {font-style: normal;}
h2>code { background-color: rgb(255, 96, 2);padding: 0.5%;border-radius: 10%;color: white;}
Expand Down
92 changes: 47 additions & 45 deletions backend/utils/svg2html.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package utils

import (
"bytes"
"fmt"
"html"
"path/filepath"
"regexp"
"sort"
Expand Down Expand Up @@ -272,7 +274,6 @@ func OneByOneHtml(eType string, index int, svgContent *SvgContent, toc []EbookTo
vaild.Read(vaildReader)

element, err1 := svgparser.Parse(bytes.NewReader(vaildReader), false)

if err1 != nil {
err = err1
return
Expand Down Expand Up @@ -339,7 +340,7 @@ func OneByOneHtml(eType string, index int, svgContent *SvgContent, toc []EbookTo
`" alt="` + item.Alt +
`" title="` + item.Alt + `"/>`
if len(style) > 0 {
img = `<div style=">` + style + `">` + img + `</div>`
img = `<div style="` + style + `">` + img + `</div>`
}
if (w < footNoteImgW || h < footNoteImgH) && len(item.Class) > 0 {
img = `
Expand All @@ -356,18 +357,21 @@ func OneByOneHtml(eType string, index int, svgContent *SvgContent, toc []EbookTo
`" src="` + item.Href +
`" alt="` + item.Alt + `"/>`
if len(style) > 0 {
img = `<div style=">` + style + `">` + img + `</div>`
img = `<div style="` + style + `">` + img + `</div>`
}
if w < footNoteImgW {
// epub popup comment
if len(item.Class) > 0 {
footnoteId := "footnote-" + strconv.Itoa(index) + "-" + strconv.Itoa(i)
img = `
<sup><a epub:type="noteref" href="#` + footnoteId + `"> <img width="` + strconv.FormatFloat(w, 'f', 0, 64) +
<sup><a class="duokan-footnote" epub:type="noteref" href="#` + footnoteId + `"> <img width="` + strconv.FormatFloat(w, 'f', 0, 64) +
`" src="` + item.Href +
`" alt="` + item.Alt +
`" class="` + item.Class + `"/></a></sup>`
result += `<aside epub:type="footnote" id="` + footnoteId + `">` + item.Alt + `</aside>`
`" zy-footnote="` + item.Alt +
`" class="` + item.Class + ` zhangyue-footnote qqreader-footnote"/></a></sup>`
result += `<aside epub:type="footnote" id="` + footnoteId +
`"><ol class="duokan-footnote-content" style="list-style:none;padding:0px;margin:0px;"><li class="duokan-footnote-item" id="` +
footnoteId + `"></a>` + item.Alt + `</li></ol></aside>`
}
}
}
Expand Down Expand Up @@ -401,63 +405,61 @@ func OneByOneHtml(eType string, index int, svgContent *SvgContent, toc []EbookTo

case "text":
if hasUncloseSpan && item.Style != currentSpanStyle {
cont += `</span>`
cont += "</span>"
hasUncloseSpan = false
}

keepStyle := item.Style != lineStyle
if keepStyle && !hasUncloseSpan {
cont += `<span style="` + item.Style + `">`
if item.Style != lineStyle && !hasUncloseSpan {
cont += fmt.Sprintf(`<span style="%s">`, item.Style)
currentSpanStyle = item.Style
hasUncloseSpan = true
}

if firstX >= centerL && firstX <= centerH {
style = style + "display: block;text-align:center;"
style += "display: block;text-align:center;"
} else if firstX >= rightL {
style = style + "display: block;text-align:right;"
}
if item.Content == "<" {
item.Content = "&lt;"
}
if item.Content == ">" {
item.Content = "&gt;"
style += "display: block;text-align:right;"
}
if item.IsBold {
cont += `<b>`
}
if item.IsItalic {
cont += `<i>`
}
if item.IsFn {
cont += `<sup>`

item.Content = html.EscapeString(item.Content)

tags := []struct {
condition bool
open string
close string
}{
{item.IsBold, "<b>", "</b>"},
{item.IsItalic, "<i>", "</i>"},
{item.IsFn, "<sup>", "</sup>"},
{item.IsSub, "<sub>", "</sub>"},
}
if item.IsSub {
cont += `<sub>`

for _, tag := range tags {
if tag.condition {
cont += tag.open
}
}

if item.Fn.Href != "" {
cont += `<a id=` + item.ID + ` href=` + item.Fn.Href
cont += fmt.Sprintf(`<a id=%s href=%s`, item.ID, item.Fn.Href)
if item.Fn.Style != "" {
cont += ` style="` + item.Fn.Style + `"`
cont += fmt.Sprintf(` style="%s"`, item.Fn.Style)
}
cont += `>`
cont += ">"
}

cont += item.Content

if item.Fn.Href != "" {
cont += `</a>`
}
if item.IsFn {
cont += `</sup>`
}
if item.IsSub {
cont += `</sub>`
cont += "</a>"
}
if item.IsItalic {
cont += `</i>`
}
if item.IsBold {
cont += `</b>`

for i := len(tags) - 1; i >= 0; i-- {
if tags[i].condition {
cont += tags[i].close
}
}

contWOTag += item.Content
}
if i == len(lineContent[v])-1 {
Expand Down Expand Up @@ -521,7 +523,7 @@ func OneByOneHtml(eType string, index int, svgContent *SvgContent, toc []EbookTo

func GenHeadHtml() (result string) {
result = `<!DOCTYPE html>
<html>
<html xml:lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand All @@ -535,7 +537,7 @@ func GenHeadHtml() (result string) {
@font-face { font-family: "Source Code Pro"; src:local("Source Code Pro"), url("https://imgcdn.umiwi.com/ttf/0315911806889993935644188722660020367983.ttf"); }
table, tr, td, th, tbody, thead, tfoot {page-break-inside: avoid !important;}
img { page-break-inside: avoid; max-width: 100% !important;}
img.epub-footnote { padding-right:5px;}
img.epub-footnote { margin-right:5px;display: inline;font-size: 12px;}
</style>
</head>
<body>`
Expand Down
14 changes: 14 additions & 0 deletions frontend/wailsjs/runtime/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,17 @@ export function ClipboardGetText(): Promise<string>;
// [ClipboardSetText](https://wails.io/docs/reference/runtime/clipboard#clipboardsettext)
// Sets a text on the clipboard
export function ClipboardSetText(text: string): Promise<boolean>;

// [OnFileDrop](https://wails.io/docs/reference/runtime/draganddrop#onfiledrop)
// OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
export function OnFileDrop(callback: (x: number, y: number ,paths: string[]) => void, useDropTarget: boolean) :void

// [OnFileDropOff](https://wails.io/docs/reference/runtime/draganddrop#dragandddropoff)
// OnFileDropOff removes the drag and drop listeners and handlers.
export function OnFileDropOff() :void

// Check if the file path resolver is available
export function CanResolveFilePaths(): boolean;

// Resolves file paths for an array of files
export function ResolveFilePaths(files: File[]): void
36 changes: 36 additions & 0 deletions frontend/wailsjs/runtime/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,40 @@ export function ClipboardGetText() {

export function ClipboardSetText(text) {
return window.runtime.ClipboardSetText(text);
}

/**
* Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
*
* @export
* @callback OnFileDropCallback
* @param {number} x - x coordinate of the drop
* @param {number} y - y coordinate of the drop
* @param {string[]} paths - A list of file paths.
*/

/**
* OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
*
* @export
* @param {OnFileDropCallback} callback - Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
* @param {boolean} [useDropTarget=true] - Only call the callback when the drop finished on an element that has the drop target style. (--wails-drop-target)
*/
export function OnFileDrop(callback, useDropTarget) {
return window.runtime.OnFileDrop(callback, useDropTarget);
}

/**
* OnFileDropOff removes the drag and drop listeners and handlers.
*/
export function OnFileDropOff() {
return window.runtime.OnFileDropOff();
}

export function CanResolveFilePaths() {
return window.runtime.CanResolveFilePaths();
}

export function ResolveFilePaths(files) {
return window.runtime.ResolveFilePaths(files);
}
28 changes: 13 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
module github.com/yann0917/dedao-gui

go 1.21

toolchain go1.21.4
go 1.20

require (
github.com/JoshVarga/svgparser v0.0.0-20200804023048-5eaba627a7d1
github.com/PuerkitoBio/goquery v1.9.2
github.com/SebastiaanKlippert/go-wkhtmltopdf v1.9.2
github.com/SebastiaanKlippert/go-wkhtmltopdf v1.9.3
github.com/bmaupin/go-epub v1.1.0
github.com/chromedp/cdproto v0.0.0-20240524221637-55927c2a4565
github.com/chromedp/chromedp v0.9.5
github.com/gabriel-vasile/mimetype v1.4.4
github.com/go-resty/resty/v2 v2.13.1
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2
github.com/chromedp/cdproto v0.0.0-20240810084448-b931b754e476
github.com/chromedp/chromedp v0.10.0
github.com/gabriel-vasile/mimetype v1.4.5
github.com/go-resty/resty/v2 v2.14.0
github.com/gomarkdown/markdown v0.0.0-20240730141124-034f12af3bf6
github.com/json-iterator/go v1.1.12
github.com/mattn/go-colorable v0.1.13
github.com/mitchellh/mapstructure v1.5.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/wailsapp/wails/v2 v2.8.2
golang.org/x/sync v0.7.0
github.com/wailsapp/wails/v2 v2.9.1
golang.org/x/sync v0.8.0
)

require (
Expand Down Expand Up @@ -55,9 +53,9 @@ require (
github.com/vincent-petithory/dataurl v1.0.0 // indirect
github.com/wailsapp/go-webview2 v1.0.10 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
)
Loading

0 comments on commit 7577543

Please sign in to comment.