Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59671 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-02-13 10:04:32


Author: danieljames
Date: 2010-02-13 10:04:31 EST (Sat, 13 Feb 2010)
New Revision: 59671
URL: http://svn.boost.org/trac/boost/changeset/59671

Log:
HTML footnotes.
Text files modified:
   branches/quickbook-1.5-spirit2/encoder_impl.hpp | 19 +++++++++++
   branches/quickbook-1.5-spirit2/html.cpp | 66 ++++++++++++++++++++++++++++++++++++++-
   2 files changed, 82 insertions(+), 3 deletions(-)

Modified: branches/quickbook-1.5-spirit2/encoder_impl.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/encoder_impl.hpp (original)
+++ branches/quickbook-1.5-spirit2/encoder_impl.hpp 2010-02-13 10:04:31 EST (Sat, 13 Feb 2010)
@@ -2,6 +2,8 @@
 #include "encoder.hpp"
 #include "phrase.hpp"
 #include "state.hpp"
+#include <vector>
+#include <stack>
 
 namespace quickbook
 {
@@ -38,6 +40,9 @@
     };
 
     struct html_encoder : encoder {
+ html_encoder();
+ ~html_encoder();
+
         virtual void operator()(quickbook::state&, doc_info const&);
         virtual void operator()(quickbook::state&, doc_info_post const&);
     
@@ -67,5 +72,19 @@
         virtual std::string encode(std::string const&);
         virtual std::string encode(char);
         virtual std::string encode(char const*);
+ private:
+ void push_footnotes(quickbook::state&);
+ void pop_footnotes(quickbook::state&);
+
+ int footnote_id;
+ struct footnote {
+ footnote(int id, std::string const& content)
+ : id(id), content(content) {}
+
+ int id;
+ std::string content;
+ };
+ typedef std::vector<footnote> footnotes;
+ std::stack<footnotes> footnote_stack;
     };
 }
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/html.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/html.cpp (original)
+++ branches/quickbook-1.5-spirit2/html.cpp 2010-02-13 10:04:31 EST (Sat, 13 Feb 2010)
@@ -1,9 +1,13 @@
 #include <algorithm>
 #include <boost/foreach.hpp>
+#include <boost/assert.hpp>
 #include "encoder_impl.hpp"
 
 namespace quickbook
-{
+{
+ html_encoder::html_encoder() : footnote_id(0) {}
+ html_encoder::~html_encoder() {}
+
     template <typename Iter>
     std::string encode_impl(Iter first, Iter last)
     {
@@ -136,8 +140,23 @@
 
     void html_encoder::operator()(quickbook::state& state, formatted const& x)
     {
- html_markup m = markup_map.at(x.type);
- state.phrase << m.pre << x.content << m.post;
+ std::string type = x.type;
+ if(type == "footnote") {
+ int id = ++footnote_id;
+ footnote_stack.top().push_back(footnote(id, x.content));
+ // TODO: Maybe get section id from the state?
+ state.phrase
+ << "<sup id=\"footnote_ref_" << id << "\">"
+ << "<a href=\"#footnote_" << id << "\">"
+ << "[" << id << "]"
+ << "</a>"
+ << "</sup>"
+ ;
+ }
+ else {
+ html_markup m = markup_map.at(x.type);
+ state.phrase << m.pre << x.content << m.post;
+ }
     }
 
     void html_encoder::operator()(quickbook::state& state, break_ const& x)
@@ -202,10 +221,14 @@
                 << "</h" << level << ">\n"
                 ;
         }
+
+ push_footnotes(state);
     }
 
     void html_encoder::operator()(quickbook::state& state, end_section2 const& x)
     {
+ pop_footnotes(state);
+
         state.phrase << "</section>";
     }
 
@@ -471,6 +494,8 @@
         state.phrase
             << "</header>\n"
             ;
+
+ push_footnotes(state);
     }
 
     void html_encoder::operator()(quickbook::state& state, doc_info_post const& x)
@@ -478,8 +503,43 @@
         // if we're ignoring the document info, do nothing.
         if (x.info.ignore) return;
 
+ pop_footnotes(state);
+
         // We've finished generating our output. Here's what we'll do
         // *after* everything else.
         state.phrase << "</html>";
     }
+
+ void html_encoder::push_footnotes(quickbook::state& state)
+ {
+ footnote_stack.push(footnotes());
+ }
+
+ void html_encoder::pop_footnotes(quickbook::state& state)
+ {
+ BOOST_ASSERT(!footnote_stack.empty());
+ footnotes notes = footnote_stack.top();
+ footnote_stack.pop();
+
+ if(!notes.empty()) {
+ state.phrase
+ << "<dl class=\"footnotes\">\n";
+
+ BOOST_FOREACH(footnote const& x, notes) {
+ state.phrase
+ << "<dt id=\"footnote_" << x.id << "\">"
+ << "<a href=\"#footnote_ref_" << x.id << "\">"
+ << "Footnote"
+ << "</a>"
+ << "</dt>"
+ << "<dd>"
+ << x.content
+ << "</dd>"
+ ;
+ }
+
+ state.phrase
+ << "</dl>\n";
+ }
+ }
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk