#include "state.hpp"
#include "state_save.hpp"
#include "grammar.hpp"
-#include "native_text.hpp"
+#include "stream.hpp"
#include "block_tags.hpp"
#include "phrase_tags.hpp"
#include "document_state.hpp"
-#include "include_paths.hpp"
+#include "path.hpp"
namespace quickbook
{
namespace {
void write_anchors(quickbook::state& state, collector& tgt)
{
- // TODO: This works but is a bit of an odd place to put it.
- // Might need to redefine the purpose of this function.
if (state.source_mode_next) {
detail::outwarn(state.source_mode_next_pos.get_file(),
state.source_mode_next_pos.get_position())
}
std::string add_anchor(quickbook::state& state,
- boost::string_ref id,
+ quickbook::string_view id,
id_category::categories category =
id_category::explicit_anchor_id)
{
quickbook::value const& value)
{
std::string x = value.is_encoded() ?
- value.get_encoded() : detail::to_s(value.get_quickbook());
+ value.get_encoded() : value.get_quickbook().to_s();
if (x.empty()) {
detail::outerr(value.get_file(), value.get_position())
detail::outerr(id_value.get_file(), id_value.get_position())
<< "Invalid id: "
<< (id_value.is_encoded() ? id_value.get_encoded() :
- detail::to_s(id_value.get_quickbook()))
+ id_value.get_quickbook().to_s())
<< std::endl;
++state.error_count;
}
return qbk_version_n >= lower && qbk_version_n < upper;
}
- void explicit_list_action(quickbook::state&, value);
+ bool quickbook_strict::is_strict_checking() const {
+ return state.strict_mode;
+ }
+
+ void list_action(quickbook::state&, value);
void header_action(quickbook::state&, value);
void begin_section_action(quickbook::state&, value);
void end_section_action(quickbook::state&, value, string_iterator);
{
case block_tags::ordered_list:
case block_tags::itemized_list:
- return explicit_list_action(state, v);
+ return list_action(state, v);
case block_tags::generic_heading:
case block_tags::heading1:
case block_tags::heading2:
if (saved_conditional)
{
- boost::string_ref macro1 = values.consume().get_quickbook();
+ bool positive = values.consume().get_quickbook().empty();
+ quickbook::string_view macro1 = values.consume().get_quickbook();
std::string macro(macro1.begin(), macro1.end());
- state.conditional = find(state.macro, macro.c_str());
+ state.conditional =
+ (bool)find(state.macro, macro.c_str()) == positive;
if (!state.conditional) {
state.push_output();
return block;
}
- void explicit_list_action(quickbook::state& state, value list)
+ void list_action(quickbook::state& state, value list)
{
write_anchors(state, state.out);
int code_tag = code_block.get_tag();
value_consumer values = code_block;
- boost::string_ref code_value = values.consume().get_quickbook();
+ quickbook::string_view code_value = values.consume().get_quickbook();
values.finish();
bool inline_code = code_tag == code_tags::inline_code ||
if(hex_digits.size() == 2 && *first > '0' && *first <= '7') {
using namespace std;
- detail::print_char(strtol(hex_digits.c_str(), 0, 16),
+ detail::print_char(
+ (char) strtol(hex_digits.c_str(), 0, 16),
state.phrase.get());
}
else {
detail::print_string(v.get_encoded(), out);
}
else {
- boost::string_ref value = v.get_quickbook();
- for(boost::string_ref::const_iterator
+ quickbook::string_view value = v.get_quickbook();
+ for(string_iterator
first = value.begin(), last = value.end();
first != last; ++first)
{
std::string fileref = attributes["fileref"].is_encoded() ?
attributes["fileref"].get_encoded() :
- detail::to_s(attributes["fileref"].get_quickbook());
+ attributes["fileref"].get_quickbook().to_s();
// Check for windows paths, then convert.
// A bit crude, but there you go.
{
attributes.insert(std::make_pair(
"contentwidth", encoded_value(std::string(
- svg_text.begin() + a + 1, svg_text.begin() + b))
+ boost::next(svg_text.begin(), a + 1),
+ boost::next(svg_text.begin(), b)))
));
}
a = svg_text.find("height");
{
attributes.insert(std::make_pair(
"contentdepth", encoded_value(std::string(
- svg_text.begin() + a + 1, svg_text.begin() + b))
+ boost::next(svg_text.begin(), a + 1),
+ boost::next(svg_text.begin(), b)))
));
}
}
void macro_definition_action(quickbook::state& state, quickbook::value macro_definition)
{
value_consumer values = macro_definition;
- std::string macro_id = detail::to_s(values.consume().get_quickbook());
+ std::string macro_id = values.consume().get_quickbook().to_s();
value phrase_value = values.optional_consume();
std::string phrase;
if (phrase_value.check()) phrase = phrase_value.get_encoded();
void template_body_action(quickbook::state& state, quickbook::value template_definition)
{
value_consumer values = template_definition;
- std::string identifier = detail::to_s(values.consume().get_quickbook());
+ std::string identifier = values.consume().get_quickbook().to_s();
std::vector<std::string> template_values;
BOOST_FOREACH(value const& p, values.consume()) {
- template_values.push_back(detail::to_s(p.get_quickbook()));
+ template_values.push_back(p.get_quickbook().to_s());
}
BOOST_ASSERT(values.check(template_tags::block) || values.check(template_tags::phrase));
void break_arguments(
std::vector<value>& args
, std::vector<std::string> const& params
- , fs::path const& filename
+ , fs::path const& /* filename */
)
{
// Quickbook 1.4-: If there aren't enough parameters seperated by
// then use whitespace to separate them
// (2 = template name + argument).
- if (qbk_version_n < 105 || args.size() == 1)
+ if (qbk_version_n < 105 ? args.size() : args.size() == 1)
{
while (args.size() < params.size())
file_ptr saved_current_file = state.current_file;
state.current_file = content.get_file();
- boost::string_ref source = content.get_quickbook();
+ quickbook::string_view source = content.get_quickbook();
parse_iterator first(source.begin());
parse_iterator last(source.end());
bool template_escape = values.check(template_tags::escape);
if(template_escape) values.consume();
- std::string identifier = detail::to_s(values.consume(template_tags::identifier).get_quickbook());
+ std::string identifier = values.consume(template_tags::identifier).get_quickbook().to_s();
std::vector<value> args;
else {
dst = get_attribute_value(state, dst_value);
- // TODO: Might be better to have an error for some invalid urls.
if (link.get_tag() == phrase_tags::url) {
dst = detail::partially_escape_uri(dst);
}
write_anchors(state, state.out);
value_consumer values = variable_list;
- std::string title = detail::to_s(values.consume(table_tags::title).get_quickbook());
+ std::string title = values.consume(table_tags::title).get_quickbook().to_s();
state.out << "<variablelist>\n";
values.finish();
std::string full_id = state.document.begin_section(
+ element_id,
element_id.empty() ?
detail::make_identifier(content.get_quickbook()) :
validate_id(state, element_id),
state.current_source_mode());
state.out << "\n<section id=\"" << full_id << "\">\n";
- state.out << "<title>";
- write_anchors(state, state.out);
+ std::string title = content.get_encoded();
- if (self_linked_headers && state.document.compatibility_version() >= 103)
- {
- state.out << "<link linkend=\"" << full_id << "\">"
- << content.get_encoded()
- << "</link>"
- ;
- }
- else
- {
- state.out << content.get_encoded();
+ if (!title.empty()) {
+ state.out << "<title>";
+
+ write_anchors(state, state.out);
+
+ if (self_linked_headers && state.document.compatibility_version() >= 103)
+ {
+ state.out << quickbook::detail::linkify(title, full_id);
+ }
+ else
+ {
+ state.out << title;
+ }
+
+ state.out << "</title>\n";
}
-
- state.out << "</title>\n";
}
- void end_section_action(quickbook::state& state, value end_section, string_iterator first)
+ void end_section_action(quickbook::state& state, value end_section_list, string_iterator first)
{
+ value_consumer values = end_section_list;
+ value element_id = values.optional_consume(general_tags::element_id);
+ values.finish();
+
write_anchors(state, state.out);
if (state.document.section_level() <= state.min_section_level)
return;
}
+ if (!element_id.empty() && !(element_id == state.document.explicit_id()))
+ {
+ file_position const pos = state.current_file->position_of(first);
+ value section_element_id = state.document.explicit_id();
+
+ if (section_element_id.empty()) {
+ detail::outerr(state.current_file->path, pos.line)
+ << "Endsect has unexpected id '"
+ << element_id.get_quickbook()
+ << "' in section with no explicit id, near column "
+ << pos.column << ".\n";
+ } else {
+ detail::outerr(state.current_file->path, pos.line)
+ << "Endsect has incorrect id '"
+ << element_id.get_quickbook()
+ << "', expected '"
+ << state.document.explicit_id().get_quickbook()
+ << "', near column "
+ << pos.column << ".\n";
+ }
+ ++state.error_count;
+ }
+
state.out << "</section>";
state.document.end_section();
}
if (x.type == path_parameter::path)
{
- quickbook_path path = resolve_xinclude_path(x.value, state);
+ quickbook_path path = resolve_xinclude_path(x.value, state, true);
state.out << "\n<xi:include href=\"";
detail::print_string(file_path_to_url(path.abstract_file_path), state.out.get());
quickbook_path const& path,
value::tag_type load_type,
string_iterator first,
- value const& include_doc_id = value())
+ value const& /* include_doc_id */ = value())
{
assert(load_type == block_tags::include ||
load_type == block_tags::import);
std::set<quickbook_path> search =
include_search(parameter, state, first);
- std::set<quickbook_path>::iterator i = search.begin();
- std::set<quickbook_path>::iterator e = search.end();
- for (; i != e; ++i)
+ BOOST_FOREACH(quickbook_path const& path, search)
{
- quickbook_path const & path = *i;
try {
if (qbk_version_n >= 106)
{