1 /*=============================================================================
2 Copyright (c) 2011-2013 Daniel James
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
9 #if !defined(BOOST_QUICKBOOK_DOCUMENT_STATE_IMPL_HPP)
10 #define BOOST_QUICKBOOK_DOCUMENT_STATE_IMPL_HPP
12 #include "document_state.hpp"
13 #include "phrase_tags.hpp"
15 #include "string_view.hpp"
16 #include <boost/shared_ptr.hpp>
26 // When generating the xml, quickbook can't allocate the identifiers until
27 // the end, so it stores in the intermedia xml a placeholder string,
28 // e.g. id="$1". This represents one of these placeholders.
33 std::size_t index; // The index in document_state_impl::placeholders.
34 // Use for the dollar identifiers in
36 std::string id; // The node id.
37 std::string unresolved_id;
38 // The id that would be generated
39 // without any duplicate handling.
40 // Used for generating old style header anchors.
41 id_placeholder const* parent;
42 // Placeholder of the parent id.
44 std::ptrdiff_t num_dots; // Number of dots in the id.
45 // Normally equal to the section level
46 // but not when an explicit id contains
49 id_placeholder(std::size_t index, quickbook::string_view id,
50 id_category category, id_placeholder const* parent_);
52 std::string to_string() const;
56 // document_state_impl
58 // Contains all the data tracked by document_state.
65 struct document_state_impl
67 boost::shared_ptr<file_info> current_file;
68 std::deque<id_placeholder> placeholders;
70 // Placeholder methods
72 id_placeholder const* add_placeholder(quickbook::string_view, id_category,
73 id_placeholder const* parent = 0);
75 id_placeholder const* get_placeholder(quickbook::string_view) const;
77 id_placeholder const* get_id_placeholder(
78 boost::shared_ptr<section_info> const& section) const;
82 id_placeholder const* start_file(
83 unsigned compatibility_version,
85 quickbook::string_view include_doc_id,
86 quickbook::string_view id,
91 id_placeholder const* add_id(
92 quickbook::string_view id,
93 id_category category);
94 id_placeholder const* old_style_id(
95 quickbook::string_view id,
96 id_category category);
97 id_placeholder const* begin_section(
98 value const& explicit_id,
99 quickbook::string_view id,
100 id_category category,
101 source_mode_info const&);
105 id_placeholder const* add_id_to_section(
106 quickbook::string_view id,
107 id_category category,
108 boost::shared_ptr<section_info> const& section);
109 id_placeholder const* create_new_section(
110 value const& explicit_id,
111 quickbook::string_view id,
112 id_category category,
113 source_mode_info const&);
116 std::string replace_ids(document_state_impl const& state, quickbook::string_view xml,
117 std::vector<std::string> const* = 0);
118 std::vector<std::string> generate_ids(document_state_impl const&, quickbook::string_view);
120 std::string normalize_id(quickbook::string_view src_id);
121 std::string normalize_id(quickbook::string_view src_id, std::size_t);
124 // Xml subset parser used for finding id values.
126 // I originally tried to integrate this into the post processor
127 // but that proved tricky. Alternatively it could use a proper
128 // xml parser, but I want this to be able to survive badly
129 // marked up escapes.
136 std::vector<std::string> id_attributes;
139 virtual void start(quickbook::string_view) {}
140 virtual void id_value(quickbook::string_view) {}
141 virtual void finish(quickbook::string_view) {}
142 virtual ~callback() {}
145 void parse(quickbook::string_view, callback&);