Browse Source

Create special style for section <body name="notes">

Kandrashin Denis 13 years ago
parent
commit
d4dbf77850
4 changed files with 12 additions and 13 deletions
  1. 3 2
      source/fb2read.cpp
  2. 3 8
      source/fb2save.cpp
  3. 3 0
      source/fb2tree.cpp
  4. 3 3
      source/res/style.css

+ 3 - 2
source/fb2read.cpp

@@ -256,9 +256,10 @@ void Fb2ReadHandler::TextHandler::Init(const QXmlAttributes &atts)
     writer().writeStartElement(m_tag);
     QString id = Value(atts, "id");
     if (!m_style.isEmpty()) {
-        if (m_style == "section" && !id.isEmpty() && isNotes()) m_style = "note";
-        if (m_style == "body" && Value(atts, "name").toLower() == "notes") m_style = "notes";
         writer().writeAttribute("class", m_style);
+        if (m_style == "body" && Value(atts, "name").toLower() == "notes") {
+            writer().writeAttribute("name", "notes");
+        }
     }
     if (!id.isEmpty()) writer().writeAttribute("id", id);
 }

+ 3 - 8
source/fb2save.cpp

@@ -149,19 +149,14 @@ Fb2SaveHandler::BodyHandler::BodyHandler(BodyHandler *parent, const QString &nam
 void Fb2SaveHandler::BodyHandler::Init(const QXmlAttributes &atts)
 {
     if (m_tag.isEmpty()) return;
-    if (m_tag == "notes") {
-        m_writer.writeStartElement("section", m_level);
-        m_writer.writeAttribute("name", "notes");
-    } else if (m_tag == "note") {
-        m_writer.writeStartElement("section", m_level);
-    } else {
-        m_writer.writeStartElement(m_tag, m_level);
-    }
+    m_writer.writeStartElement(m_tag, m_level);
     int count = atts.count();
     for (int i = 0; i < count; i++) {
         QString name = atts.qName(i);
         if (name == "id") {
             m_writer.writeAttribute(name, atts.value(i));
+        } else if (name == "name") {
+            m_writer.writeAttribute(name, atts.value(i));
         } else if (name.left(4) == "fb2:") {
             m_writer.writeAttribute(name.mid(4), atts.value(i));
         }

+ 3 - 0
source/fb2tree.cpp

@@ -19,6 +19,9 @@ Fb2TreeItem::Fb2TreeItem(QWebElement &element, Fb2TreeItem *parent)
             if (m_parent) m_parent->m_text += m_text += " ";
         } else if (style == "subtitle") {
             m_text = title(element);
+        } else if (style == "body") {
+            QString name = element.attribute("name");
+            if (!name.isEmpty()) style += " name=" + name;
         }
         if (!style.isEmpty()) m_name = style;
     } else if (m_name == "img") {

+ 3 - 3
source/res/style.css

@@ -88,7 +88,7 @@ div.poem p {
   margin-bottom: 0;
 }
 
-div.note {
+div.body[name=notes] {
   border-top: none;
   border-bottom: none;
   border-left: thin solid green;
@@ -99,7 +99,7 @@ div.note {
   padding-right: 0;
 }
 
-div.note div.title {
+div.body[name=notes] div[id] div.title {
   font: inherit;
   float: left;
   margin-left: 4;
@@ -108,7 +108,7 @@ div.note div.title {
   padding-right: 4;
 }
 
-div.note div.title p {
+div.body[name=notes] div[id] div.title p {
   margin-top: 0;
   margin-bottom: 0;
 }