]>
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 | ||
7c673cae FG |
12 | #include <deque> |
13 | #include <string> | |
14 | #include <vector> | |
11fdf7f2 TL |
15 | #include <boost/shared_ptr.hpp> |
16 | #include "document_state.hpp" | |
17 | #include "phrase_tags.hpp" | |
18 | #include "string_view.hpp" | |
19 | #include "utils.hpp" | |
7c673cae FG |
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 | { | |
11fdf7f2 TL |
33 | std::size_t index; // The index in document_state_impl::placeholders. |
34 | // Use for the dollar identifiers in | |
35 | // intermediate xml. | |
36 | std::string id; // The node id. | |
7c673cae | 37 | std::string unresolved_id; |
11fdf7f2 TL |
38 | // The id that would be generated |
39 | // without any duplicate handling. | |
40 | // Used for generating old style header anchors. | |
7c673cae | 41 | id_placeholder const* parent; |
11fdf7f2 | 42 | // Placeholder of the parent id. |
7c673cae | 43 | id_category category; |
b32b8144 | 44 | std::ptrdiff_t num_dots; // Number of dots in the id. |
11fdf7f2 TL |
45 | // Normally equal to the section level |
46 | // but not when an explicit id contains | |
47 | // dots. | |
7c673cae | 48 | |
11fdf7f2 TL |
49 | id_placeholder( |
50 | std::size_t index, | |
51 | quickbook::string_view id, | |
52 | id_category category, | |
53 | id_placeholder const* parent_); | |
7c673cae FG |
54 | |
55 | std::string to_string() const; | |
56 | }; | |
57 | ||
58 | // | |
59 | // document_state_impl | |
60 | // | |
61 | // Contains all the data tracked by document_state. | |
62 | // | |
63 | ||
64 | struct file_info; | |
65 | struct doc_info; | |
66 | struct section_info; | |
67 | ||
68 | struct document_state_impl | |
69 | { | |
70 | boost::shared_ptr<file_info> current_file; | |
71 | std::deque<id_placeholder> placeholders; | |
72 | ||
73 | // Placeholder methods | |
74 | ||
11fdf7f2 TL |
75 | id_placeholder const* add_placeholder( |
76 | quickbook::string_view, | |
77 | id_category, | |
7c673cae FG |
78 | id_placeholder const* parent = 0); |
79 | ||
b32b8144 | 80 | id_placeholder const* get_placeholder(quickbook::string_view) const; |
7c673cae FG |
81 | |
82 | id_placeholder const* get_id_placeholder( | |
11fdf7f2 | 83 | boost::shared_ptr<section_info> const& section) const; |
7c673cae FG |
84 | |
85 | // Events | |
86 | ||
87 | id_placeholder const* start_file( | |
11fdf7f2 TL |
88 | unsigned compatibility_version, |
89 | bool document_root, | |
90 | quickbook::string_view include_doc_id, | |
91 | quickbook::string_view id, | |
92 | value const& title); | |
7c673cae FG |
93 | |
94 | void end_file(); | |
95 | ||
96 | id_placeholder const* add_id( | |
11fdf7f2 | 97 | quickbook::string_view id, id_category category); |
7c673cae | 98 | id_placeholder const* old_style_id( |
11fdf7f2 | 99 | quickbook::string_view id, id_category category); |
7c673cae | 100 | id_placeholder const* begin_section( |
11fdf7f2 TL |
101 | value const& explicit_id, |
102 | quickbook::string_view id, | |
103 | id_category category, | |
104 | source_mode_info const&); | |
7c673cae FG |
105 | void end_section(); |
106 | ||
11fdf7f2 | 107 | private: |
7c673cae | 108 | id_placeholder const* add_id_to_section( |
11fdf7f2 TL |
109 | quickbook::string_view id, |
110 | id_category category, | |
111 | boost::shared_ptr<section_info> const& section); | |
7c673cae | 112 | id_placeholder const* create_new_section( |
11fdf7f2 TL |
113 | value const& explicit_id, |
114 | quickbook::string_view id, | |
115 | id_category category, | |
116 | source_mode_info const&); | |
7c673cae FG |
117 | }; |
118 | ||
11fdf7f2 TL |
119 | std::string replace_ids( |
120 | document_state_impl const& state, | |
121 | quickbook::string_view xml, | |
122 | std::vector<std::string> const* = 0); | |
123 | std::vector<std::string> generate_ids( | |
124 | document_state_impl const&, quickbook::string_view); | |
7c673cae | 125 | |
b32b8144 FG |
126 | std::string normalize_id(quickbook::string_view src_id); |
127 | std::string normalize_id(quickbook::string_view src_id, std::size_t); | |
7c673cae FG |
128 | |
129 | // | |
130 | // Xml subset parser used for finding id values. | |
131 | // | |
132 | // I originally tried to integrate this into the post processor | |
133 | // but that proved tricky. Alternatively it could use a proper | |
134 | // xml parser, but I want this to be able to survive badly | |
135 | // marked up escapes. | |
136 | // | |
137 | ||
138 | struct xml_processor | |
139 | { | |
140 | xml_processor(); | |
141 | ||
142 | std::vector<std::string> id_attributes; | |
143 | ||
11fdf7f2 TL |
144 | struct callback |
145 | { | |
b32b8144 FG |
146 | virtual void start(quickbook::string_view) {} |
147 | virtual void id_value(quickbook::string_view) {} | |
148 | virtual void finish(quickbook::string_view) {} | |
7c673cae FG |
149 | virtual ~callback() {} |
150 | }; | |
151 | ||
b32b8144 | 152 | void parse(quickbook::string_view, callback&); |
7c673cae FG |
153 | }; |
154 | } | |
155 | ||
156 | #endif |