diff --git a/processor/enums.go b/processor/enums.go index 827c76f7..edda1cd5 100644 --- a/processor/enums.go +++ b/processor/enums.go @@ -38,6 +38,7 @@ const ( NFloat // float NFloatOld // float-old NFloatNew // float-new + NFloatNewMore // float-new-more UnsupportedNotesFmt // ) diff --git a/processor/enums_string.go b/processor/enums_string.go index c66cf845..fa3be69d 100644 --- a/processor/enums_string.go +++ b/processor/enums_string.go @@ -35,12 +35,13 @@ func _() { _ = x[NFloat-3] _ = x[NFloatOld-4] _ = x[NFloatNew-5] - _ = x[UnsupportedNotesFmt-6] + _ = x[NFloatNewMore-6] + _ = x[UnsupportedNotesFmt-7] } -const _NotesFmt_name = "defaultinlineblockfloatfloat-oldfloat-new" +const _NotesFmt_name = "defaultinlineblockfloatfloat-oldfloat-newfloat-new-more" -var _NotesFmt_index = [...]uint8{0, 7, 13, 18, 23, 32, 41, 41} +var _NotesFmt_index = [...]uint8{0, 7, 13, 18, 23, 32, 41, 55, 55} func (i NotesFmt) String() string { if i < 0 || i >= NotesFmt(len(_NotesFmt_index)-1) { diff --git a/processor/process.go b/processor/process.go index f838e8f2..86f697dc 100644 --- a/processor/process.go +++ b/processor/process.go @@ -104,7 +104,7 @@ func NewFB2(r io.Reader, unknownEncoding bool, src, dst string, nodirs, stk, ove env.Log.Warn("Unknown notes mode requested, switching to default", zap.String("mode", env.Cfg.Doc.Notes.Mode)) notes = NDefault } - if notes != NFloat && notes != NFloatOld && notes != NFloatNew && env.Cfg.Doc.Notes.Renumber { + if notes != NFloat && notes != NFloatOld && notes != NFloatNew && notes != NFloatNewMore && env.Cfg.Doc.Notes.Renumber { env.Log.Warn("Notes can be renumbered in floating modes only, ignoring", zap.String("mode", env.Cfg.Doc.Notes.Mode)) } toct := ParseTOCTypeString(env.Cfg.Doc.TOC.Type) diff --git a/processor/xhtml.go b/processor/xhtml.go index ddacd9bb..fbca663a 100644 --- a/processor/xhtml.go +++ b/processor/xhtml.go @@ -44,7 +44,7 @@ func (p *Processor) processBody(index int, from *etree.Element) (err error) { if p.notesMode == NDefault || !IsOneOf(p.ctx().bodyName, p.env.Cfg.Doc.Notes.BodyNames) { // initialize first XHTML buffer ns := []*etree.Attr{attr("xmlns", `http://www.w3.org/1999/xhtml`)} - if p.notesMode == NFloatNew { + if p.notesMode == NFloatNew || p.notesMode == NFloatNewMore { ns = append(ns, attr("xmlns:epub", `http://www.idpf.org/2007/ops`)) } to, f := p.ctx().createXHTML("", ns...) @@ -53,14 +53,14 @@ func (p *Processor) processBody(index int, from *etree.Element) (err error) { return p.transfer(from, to) } - if p.notesMode != NFloat && p.notesMode != NFloatOld && p.notesMode != NFloatNew { + if p.notesMode < NFloat { // NOTE: for block and inline notes we do not need to save XHTML, have nothing to put there return nil } // initialize XHTML buffer for notes ns := []*etree.Attr{attr("xmlns", `http://www.w3.org/1999/xhtml`)} - if p.notesMode == NFloatNew { + if p.notesMode == NFloatNew || p.notesMode == NFloatNewMore { ns = append(ns, attr("xmlns:epub", `http://www.idpf.org/2007/ops`)) } to, f := p.ctx().createXHTML("", ns...) @@ -128,7 +128,7 @@ func (p *Processor) processBody(index int, from *etree.Element) (err error) { } } // NOTE: we are adding .SetTail("\n") to make result readable when debugging, it does not have any other use - if p.notesMode == NFloatNew { + if p.notesMode == NFloatNew || p.notesMode == NFloatNewMore { // new bidirectional mode if len(note.parsed.ChildElements()) == 0 || len(note.parsed.Child) == 0 { p.env.Log.Warn("Unable to interpret parsed note body, ignoring xml...", @@ -139,7 +139,9 @@ func (p *Processor) processBody(index int, from *etree.Element) (err error) { AddNext("a", attr("href", backRef+"#"+backID)).SetText(t).SetTail(strNBSP + note.body) } else { aside := to.AddNext("aside", attr("id", nl.id), attr("epub:type", "footnote")).SetTail("\n") - for i, c := range note.parsed.ChildElements() { + children := note.parsed.ChildElements() + first := true + for i, c := range children { cc := c.Copy() if i == 0 { // We need to insert back ref anchor into first note xml element as a first child, so popup would recognize it properly @@ -153,10 +155,10 @@ func (p *Processor) processBody(index int, from *etree.Element) (err error) { if cc.Tag == "p" { cc.CreateAttr("class", "floatnote") } - for _, a := range cc.FindElements(".//p") { - if len(getAttrValue(a, "class")) == 0 { - a.CreateAttr("class", "floatnote") - } + if p.notesMode == NFloatNewMore && len(children) > 1 && cc.Tag == "p" && first { + // indicate that note body has more than one paragraph + cc.CreateCharData(" (…etc.)") + first = false } aside.AddChild(cc) } @@ -164,7 +166,6 @@ func (p *Processor) processBody(index int, from *etree.Element) (err error) { } } else { // old bi-directional mode - // to.AddNext("p", attr("class", "floatnote"), attr("id", nl.id)).SetTail("\n").AddNext("a", attr("href", backRef+"#"+backID)).SetText(t).SetTail(strNBSP + note.body) p.formatText(strNBSP+note.body, false, true, to.AddNext("p", attr("class", "floatnote"), attr("id", nl.id)).SetTail("\n"). AddNext("a", attr("href", backRef+"#"+backID)).SetText(t)) @@ -407,6 +408,8 @@ func (p *Processor) transfer(from, to *etree.Element, decorations ...string) err case NFloatOld: fallthrough case NFloatNew: + fallthrough + case NFloatNewMore: if note, ok := p.Book.Notes[noteID]; !ok { css = "linkanchor" } else { @@ -460,7 +463,7 @@ func (p *Processor) transfer(from, to *etree.Element, decorations ...string) err attrs[0] = attr("id", newid) attrs[1] = attr("class", css) attrs[2] = attr("href", href) - if p.notesMode == NFloatNew && tag == "a" { + if (p.notesMode == NFloatNew || p.notesMode == NFloatNewMore) && tag == "a" { attrs = append(attrs, attr("epub:type", "noteref")) } inner = to.AddNext(tag, attrs...) @@ -629,7 +632,7 @@ func transferSubtitle(p *Processor, from, to *etree.Element) error { if t == dv && !p.ctx().inHeader && !p.ctx().inSubHeader && len(p.ctx().bodyName) == 0 && !p.ctx().specialParagraph { // open next XHTML ns := []*etree.Attr{attr("xmlns", `http://www.w3.org/1999/xhtml`)} - if p.notesMode == NFloatNew { + if p.notesMode == NFloatNew || p.notesMode == NFloatNewMore { ns = append(ns, attr("xmlns:epub", `http://www.idpf.org/2007/ops`)) } var f *dataFile @@ -655,7 +658,7 @@ func transferParagraph(p *Processor, from, to *etree.Element) error { !p.ctx().inHeader && !p.ctx().inSubHeader && len(p.ctx().bodyName) == 0 && !p.ctx().specialParagraph { // open next XHTML ns := []*etree.Attr{attr("xmlns", `http://www.w3.org/1999/xhtml`)} - if p.notesMode == NFloatNew { + if p.notesMode == NFloatNew || p.notesMode == NFloatNewMore { ns = append(ns, attr("xmlns:epub", `http://www.idpf.org/2007/ops`)) } var f *dataFile @@ -805,7 +808,7 @@ func transferSection(p *Processor, from, to *etree.Element) error { if len(p.ctx().bodyName) == 0 && p.ctx().header.Int() < p.env.Cfg.Doc.ChapterLevel { // open next XHTML ns := []*etree.Attr{attr("xmlns", `http://www.w3.org/1999/xhtml`)} - if p.notesMode == NFloatNew { + if p.notesMode == NFloatNew || p.notesMode == NFloatNewMore { ns = append(ns, attr("xmlns:epub", `http://www.idpf.org/2007/ops`)) } var f *dataFile diff --git a/static/configuration.toml b/static/configuration.toml index 08c0b2c7..e2609bb1 100644 --- a/static/configuration.toml +++ b/static/configuration.toml @@ -157,12 +157,15 @@ [document.notes] #---- How to render notes in the book - #---- "default" - notes are links - #---- "inline" - note is shown "in-place" and could be styled via css - #---- "block" - notes are shown "in-place" at the paragraph end and could be styled via css - #---- "float" - pop up notes using "bi-directional links" method - #---- "float-old" - same as "float", pop up notes using "bi-directional links" method - #---- "float-new" - pop up notes using "preferred" method - HTML5 with