mirror of
https://github.com/boostorg/quickbook.git
synced 2026-01-19 04:22:16 +00:00
Quickbook: Use values for code blocks.
Also better error report for unclosed code block. [SVN r75894]
This commit is contained in:
@@ -89,6 +89,7 @@ namespace quickbook
|
||||
void footnote_action(quickbook::actions&, value);
|
||||
void raw_phrase_action(quickbook::actions&, value);
|
||||
void source_mode_action(quickbook::actions&, value);
|
||||
void code_action(quickbook::actions&, value);
|
||||
void do_template_action(quickbook::actions&, value, string_iterator);
|
||||
|
||||
void element_action::operator()(parse_iterator first, parse_iterator) const
|
||||
@@ -173,6 +174,10 @@ namespace quickbook
|
||||
case source_mode_tags::python:
|
||||
case source_mode_tags::teletype:
|
||||
return source_mode_action(actions, v);
|
||||
case code_tags::code_block:
|
||||
case code_tags::inline_code_block:
|
||||
case code_tags::inline_code:
|
||||
return code_action(actions, v);
|
||||
case template_tags::template_:
|
||||
return do_template_action(actions, v, first.base());
|
||||
default:
|
||||
@@ -586,11 +591,17 @@ namespace quickbook
|
||||
actions.source_mode = source_mode_tags::name(source_mode.get_tag());
|
||||
}
|
||||
|
||||
void code_action::operator()(parse_iterator first, parse_iterator last) const
|
||||
void code_action(quickbook::actions& actions, value code_block)
|
||||
{
|
||||
bool inline_code = type == inline_ ||
|
||||
(type == inline_block && qbk_version_n < 106u);
|
||||
bool block = type != inline_;
|
||||
int code_tag = code_block.get_tag();
|
||||
|
||||
value_consumer values = code_block;
|
||||
string_ref code_value = values.consume().get_quickbook();
|
||||
values.finish();
|
||||
|
||||
bool inline_code = code_tag == code_tags::inline_code ||
|
||||
(code_tag == code_tags::inline_code_block && qbk_version_n < 106u);
|
||||
bool block = code_tag != code_tags::inline_code;
|
||||
|
||||
if (inline_code) {
|
||||
write_anchors(actions, actions.phrase);
|
||||
@@ -600,13 +611,11 @@ namespace quickbook
|
||||
write_anchors(actions, actions.out);
|
||||
}
|
||||
|
||||
std::string str;
|
||||
|
||||
if (block) {
|
||||
// preprocess the code section to remove the initial indentation
|
||||
mapped_file_builder mapped;
|
||||
mapped.start(actions.current_file);
|
||||
mapped.unindent_and_add(first.base(), last.base());
|
||||
mapped.unindent_and_add(code_value.begin(), code_value.end());
|
||||
|
||||
file_ptr f = mapped.release();
|
||||
|
||||
@@ -620,16 +629,11 @@ namespace quickbook
|
||||
boost::swap(actions.current_file, saved_file);
|
||||
|
||||
// print the code with syntax coloring
|
||||
str = syntax_highlight(first_, last_, actions, actions.source_mode);
|
||||
std::string str = syntax_highlight(first_, last_, actions,
|
||||
actions.source_mode);
|
||||
|
||||
boost::swap(actions.current_file, saved_file);
|
||||
}
|
||||
else {
|
||||
parse_iterator first_(first);
|
||||
str = syntax_highlight(first_, last, actions, actions.source_mode);
|
||||
}
|
||||
|
||||
if (block) {
|
||||
collector& output = inline_code ? actions.phrase : actions.out;
|
||||
|
||||
// We must not place a \n after the <programlisting> tag
|
||||
@@ -640,6 +644,11 @@ namespace quickbook
|
||||
output << "</programlisting>\n";
|
||||
}
|
||||
else {
|
||||
parse_iterator first_(code_value.begin());
|
||||
parse_iterator last_(code_value.end());
|
||||
std::string str = syntax_highlight(first_, last_, actions,
|
||||
actions.source_mode);
|
||||
|
||||
actions.phrase << "<code>";
|
||||
actions.phrase << str;
|
||||
actions.phrase << "</code>";
|
||||
|
||||
@@ -242,26 +242,6 @@ namespace quickbook
|
||||
quickbook::actions& actions;
|
||||
};
|
||||
|
||||
struct code_action
|
||||
{
|
||||
enum code_type { block, inline_block, inline_ };
|
||||
|
||||
// Does the actual syntax highlighing of code
|
||||
|
||||
code_action(
|
||||
code_type type
|
||||
, quickbook::actions& actions)
|
||||
: type(type)
|
||||
, actions(actions)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(parse_iterator first, parse_iterator last) const;
|
||||
|
||||
code_type type;
|
||||
quickbook::actions& actions;
|
||||
};
|
||||
|
||||
struct break_action
|
||||
{
|
||||
break_action(collector& phrase, quickbook::actions& actions)
|
||||
|
||||
@@ -51,9 +51,6 @@ namespace quickbook
|
||||
|
||||
, element(*this)
|
||||
, error(*this)
|
||||
, code(code_action::block, *this)
|
||||
, code_block(code_action::inline_block, *this)
|
||||
, inline_code(code_action::inline_, *this)
|
||||
, paragraph(*this)
|
||||
, list_item(*this)
|
||||
, phrase_end(*this)
|
||||
|
||||
@@ -84,9 +84,6 @@ namespace quickbook
|
||||
element_action element;
|
||||
error_action error;
|
||||
|
||||
code_action code;
|
||||
code_action code_block;
|
||||
code_action inline_code;
|
||||
paragraph_action paragraph;
|
||||
list_item_action list_item;
|
||||
phrase_end_action phrase_end;
|
||||
|
||||
@@ -425,10 +425,11 @@ namespace quickbook
|
||||
;
|
||||
|
||||
local.code =
|
||||
(
|
||||
local.code_line
|
||||
actions.values.list(code_tags::code_block)
|
||||
[( local.code_line
|
||||
>> *(*local.blank_line >> local.code_line)
|
||||
) [actions.code]
|
||||
) [actions.values.entry(ph::arg1, ph::arg2)]
|
||||
] [actions.element]
|
||||
>> *eol
|
||||
;
|
||||
|
||||
@@ -552,44 +553,51 @@ namespace quickbook
|
||||
;
|
||||
|
||||
local.inline_code =
|
||||
'`' >>
|
||||
(
|
||||
'`' >> actions.values.list(code_tags::inline_code)
|
||||
[(
|
||||
*(cl::anychar_p -
|
||||
( '`'
|
||||
| (cl::eol_p >> *cl::blank_p >> cl::eol_p)
|
||||
// Make sure that we don't go
|
||||
) // past a single block
|
||||
) >> cl::eps_p('`')
|
||||
) [actions.inline_code]
|
||||
) [actions.values.entry(ph::arg1, ph::arg2)]
|
||||
>> '`'
|
||||
] [actions.element]
|
||||
;
|
||||
|
||||
local.code_block =
|
||||
"```"
|
||||
>> ~cl::eps_p("`")
|
||||
>> *(*cl::blank_p >> cl::eol_p)
|
||||
>> ( *( "````" >> *cl::ch_p('`')
|
||||
| ( cl::anychar_p
|
||||
- (*cl::space_p >> "```" >> ~cl::eps_p("`"))
|
||||
)
|
||||
)
|
||||
>> !(*cl::blank_p >> cl::eol_p)
|
||||
) [actions.code_block]
|
||||
>> ( *cl::space_p >> "```"
|
||||
>> ( actions.values.list(code_tags::inline_code_block)
|
||||
[ *(*cl::blank_p >> cl::eol_p)
|
||||
>> ( *( "````" >> *cl::ch_p('`')
|
||||
| ( cl::anychar_p
|
||||
- (*cl::space_p >> "```" >> ~cl::eps_p("`"))
|
||||
)
|
||||
)
|
||||
>> !(*cl::blank_p >> cl::eol_p)
|
||||
) [actions.values.entry(ph::arg1, ph::arg2)]
|
||||
>> (*cl::space_p >> "```")
|
||||
] [actions.element]
|
||||
| cl::eps_p [actions.error("Unfinished code block")]
|
||||
>> *cl::anychar_p
|
||||
)
|
||||
| "``"
|
||||
>> ~cl::eps_p("`")
|
||||
>> *(*cl::blank_p >> cl::eol_p)
|
||||
>> ( *( "```" >> *cl::ch_p('`')
|
||||
| ( cl::anychar_p
|
||||
- (*cl::space_p >> "``" >> ~cl::eps_p("`"))
|
||||
)
|
||||
)
|
||||
>> !(*cl::blank_p >> cl::eol_p)
|
||||
) [actions.code_block]
|
||||
>> ( *cl::space_p >> "``"
|
||||
>> ( actions.values.list(code_tags::inline_code_block)
|
||||
[ *(*cl::blank_p >> cl::eol_p)
|
||||
>> ( *( "```" >> *cl::ch_p('`')
|
||||
| ( cl::anychar_p
|
||||
- (*cl::space_p >> "``" >> ~cl::eps_p("`"))
|
||||
)
|
||||
)
|
||||
>> !(*cl::blank_p >> cl::eol_p)
|
||||
) [actions.values.entry(ph::arg1, ph::arg2)]
|
||||
>> (*cl::space_p >> "``")
|
||||
] [actions.element]
|
||||
| cl::eps_p [actions.error("Unfinished code block")]
|
||||
>> *cl::anychar_p
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
@@ -30,6 +30,12 @@ namespace quickbook
|
||||
((python)("python"))
|
||||
((teletype)("teletype"))
|
||||
)
|
||||
|
||||
QUICKBOOK_VALUE_TAGS(code_tags, 0x560,
|
||||
(code_block)
|
||||
(inline_code)
|
||||
(inline_code_block)
|
||||
)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -34,6 +34,7 @@ test-suite quickbook.test :
|
||||
[ quickbook-error-test code_python_mismatched_escape-1_4-fail ]
|
||||
[ quickbook-test code_snippet-1_1 ]
|
||||
[ quickbook-test code_teletype-1_5 ]
|
||||
[ quickbook-error-test code_unclosed_block-1_6-fail ]
|
||||
[ quickbook-test command_line_macro-1_1 : : :
|
||||
<quickbook-test-define>__macro__=*bold*
|
||||
<quickbook-test-define>__empty__ ]
|
||||
|
||||
4
test/code_unclosed_block-1_6-fail.quickbook
Normal file
4
test/code_unclosed_block-1_6-fail.quickbook
Normal file
@@ -0,0 +1,4 @@
|
||||
[article Odd code markup. [quickbook 1.6] ]
|
||||
|
||||
``
|
||||
int main() {}
|
||||
Reference in New Issue
Block a user