Skip to content

Commit

Permalink
Fixing notes formating again. This time inline - regression from 1.59.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rupor-github committed Jul 29, 2022
1 parent d13656f commit 6e28bfb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ endif()
# Project version number
set(PRJ_VERSION_MAJOR 1)
set(PRJ_VERSION_MINOR 64)
set(PRJ_VERSION_PATCH 4)
set(PRJ_VERSION_PATCH 5)

if (EXISTS "${PROJECT_SOURCE_DIR}/.git" AND IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git")
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/cmake/githash.sh ${GIT_EXECUTABLE}
Expand Down
9 changes: 8 additions & 1 deletion processor/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,18 @@ func (p *Processor) parseNoteSectionElement(el *etree.Element, name string, note
bodyName: name,
bodyNumber: len(notesPerBody),
}
sep := "\n"
if !p.env.Cfg.Doc.Notes.KeepNL {
sep = " "
}
for _, c := range el.ChildElements() {
if c.Tag == "title" {
note.title = SanitizeTitle(getTextFragment(c))
} else {
note.body += getFullTextFragment(c)
if len(note.body) > 0 {
note.body += sep
}
note.body += strings.ReplaceAll(getFullTextFragment(c), "\n", sep)
}
}
p.Book.NotesOrder = append(p.Book.NotesOrder, notelink{id: id, bodyName: name})
Expand Down
8 changes: 2 additions & 6 deletions processor/xhtml.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,16 @@ func (p *Processor) processBody(index int, from *etree.Element) (err error) {
}
}
}
txt := note.body
if !p.env.Cfg.Doc.Notes.KeepNL {
txt = strings.TrimSuffix(strings.ReplaceAll(txt, "\n", " "), " ")
}
// NOTE: we are adding .SetTail("\n") to make result readable when debugging, it does not have any other use
if p.notesMode == NFloatNew {
// new "preffered" HTML5 method with "aside"
to.AddNext("aside", attr("id", nl.id), attr("epub:type", "footnote")).SetTail("\n").
AddNext("p", attr("class", "floatnote")).
AddNext("a", attr("href", backRef+"#"+backID)).SetText(t).SetTail(strNBSP + txt)
AddNext("a", attr("href", backRef+"#"+backID)).SetText(t).SetTail(strNBSP + note.body)
} 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 + txt)
AddNext("a", attr("href", backRef+"#"+backID)).SetText(t).SetTail(strNBSP + note.body)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion processor/xmlutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func getTextFragment(e *etree.Element) string {
}

func getFullTextFragment(e *etree.Element) string {
return extractText(e, false, false)
return extractText(e, true, false)
}

//lint:ignore U1000 keep getXMLFragment()
Expand Down
4 changes: 2 additions & 2 deletions static/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@
#---- "float-old" - same as "float", pop up notes using "bi-directional links" method
#---- "float-new" - pop up notes using "preferred" method - HTML5 with <aside> recommended by Amazon publishing guidelines
mode = "default"
#---- By default in all float modes new line replaces all fb2 formatting tags.
#---- If "keep_new_line" is set to false all new lines will be replaced with spaces.
#---- By default in all notes modes but "default" new line replaces most fb2 formatting tags.
#---- If "keep_new_line" is set to false in such notes bodies all new lines will be replaced with spaces.
# keep_new_lines = true
#---- Names of the <body> tags in fb2 document to consider for notes processing
body_names = [ "notes", "comments" ]
Expand Down

0 comments on commit 6e28bfb

Please sign in to comment.