]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2011-2013 Daniel James | |
3 | ||
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 | =============================================================================*/ | |
8 | ||
9 | #if !defined(BOOST_QUICKBOOK_DOCUMENT_STATE_IMPL_HPP) | |
10 | #define BOOST_QUICKBOOK_DOCUMENT_STATE_IMPL_HPP | |
11 | ||
12 | #include "document_state.hpp" | |
13 | #include "phrase_tags.hpp" | |
14 | #include "utils.hpp" | |
b32b8144 | 15 | #include "string_view.hpp" |
7c673cae FG |
16 | #include <boost/shared_ptr.hpp> |
17 | #include <deque> | |
18 | #include <string> | |
19 | #include <vector> | |
20 | ||
21 | namespace quickbook | |
22 | { | |
23 | // | |
24 | // id_placeholder | |
25 | // | |
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. | |
29 | // | |
30 | ||
31 | struct id_placeholder | |
32 | { | |
b32b8144 | 33 | std::size_t index; // The index in document_state_impl::placeholders. |
7c673cae FG |
34 | // Use for the dollar identifiers in |
35 | // intermediate xml. | |
b32b8144 | 36 | std::string id; // The node id. |
7c673cae FG |
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. | |
7c673cae FG |
41 | id_placeholder const* parent; |
42 | // Placeholder of the parent id. | |
43 | id_category category; | |
b32b8144 | 44 | std::ptrdiff_t num_dots; // Number of dots in the id. |
7c673cae FG |
45 | // Normally equal to the section level |
46 | // but not when an explicit id contains | |
47 | // dots. | |
48 | ||
b32b8144 | 49 | id_placeholder(std::size_t index, quickbook::string_view id, |
7c673cae FG |
50 | id_category category, id_placeholder const* parent_); |
51 | ||
52 | std::string to_string() const; | |
53 | }; | |
54 | ||
55 | // | |
56 | // document_state_impl | |
57 | // | |
58 | // Contains all the data tracked by document_state. | |
59 | // | |
60 | ||
61 | struct file_info; | |
62 | struct doc_info; | |
63 | struct section_info; | |
64 | ||
65 | struct document_state_impl | |
66 | { | |
67 | boost::shared_ptr<file_info> current_file; | |
68 | std::deque<id_placeholder> placeholders; | |
69 | ||
70 | // Placeholder methods | |
71 | ||
b32b8144 | 72 | id_placeholder const* add_placeholder(quickbook::string_view, id_category, |
7c673cae FG |
73 | id_placeholder const* parent = 0); |
74 | ||
b32b8144 | 75 | id_placeholder const* get_placeholder(quickbook::string_view) const; |
7c673cae FG |
76 | |
77 | id_placeholder const* get_id_placeholder( | |
78 | boost::shared_ptr<section_info> const& section) const; | |
79 | ||
80 | // Events | |
81 | ||
82 | id_placeholder const* start_file( | |
83 | unsigned compatibility_version, | |
84 | bool document_root, | |
b32b8144 FG |
85 | quickbook::string_view include_doc_id, |
86 | quickbook::string_view id, | |
7c673cae FG |
87 | value const& title); |
88 | ||
89 | void end_file(); | |
90 | ||
91 | id_placeholder const* add_id( | |
b32b8144 | 92 | quickbook::string_view id, |
7c673cae FG |
93 | id_category category); |
94 | id_placeholder const* old_style_id( | |
b32b8144 | 95 | quickbook::string_view id, |
7c673cae FG |
96 | id_category category); |
97 | id_placeholder const* begin_section( | |
b32b8144 FG |
98 | value const& explicit_id, |
99 | quickbook::string_view id, | |
7c673cae FG |
100 | id_category category, |
101 | source_mode_info const&); | |
102 | void end_section(); | |
103 | ||
104 | private: | |
105 | id_placeholder const* add_id_to_section( | |
b32b8144 | 106 | quickbook::string_view id, |
7c673cae FG |
107 | id_category category, |
108 | boost::shared_ptr<section_info> const& section); | |
109 | id_placeholder const* create_new_section( | |
b32b8144 FG |
110 | value const& explicit_id, |
111 | quickbook::string_view id, | |
7c673cae FG |
112 | id_category category, |
113 | source_mode_info const&); | |
114 | }; | |
115 | ||
b32b8144 | 116 | std::string replace_ids(document_state_impl const& state, quickbook::string_view xml, |
7c673cae | 117 | std::vector<std::string> const* = 0); |
b32b8144 | 118 | std::vector<std::string> generate_ids(document_state_impl const&, quickbook::string_view); |
7c673cae | 119 | |
b32b8144 FG |
120 | std::string normalize_id(quickbook::string_view src_id); |
121 | std::string normalize_id(quickbook::string_view src_id, std::size_t); | |
7c673cae FG |
122 | |
123 | // | |
124 | // Xml subset parser used for finding id values. | |
125 | // | |
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. | |
130 | // | |
131 | ||
132 | struct xml_processor | |
133 | { | |
134 | xml_processor(); | |
135 | ||
136 | std::vector<std::string> id_attributes; | |
137 | ||
138 | struct callback { | |
b32b8144 FG |
139 | virtual void start(quickbook::string_view) {} |
140 | virtual void id_value(quickbook::string_view) {} | |
141 | virtual void finish(quickbook::string_view) {} | |
7c673cae FG |
142 | virtual ~callback() {} |
143 | }; | |
144 | ||
b32b8144 | 145 | void parse(quickbook::string_view, callback&); |
7c673cae FG |
146 | }; |
147 | } | |
148 | ||
149 | #endif |