mirror of
https://github.com/boostorg/quickbook.git
synced 2026-01-27 19:12:17 +00:00
Quickbook: further improvements for simple markup.
[SVN r70196]
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/range/distance.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/next_prior.hpp>
|
||||
#include "quickbook.hpp"
|
||||
#include "actions.hpp"
|
||||
#include "utils.hpp"
|
||||
@@ -311,18 +312,31 @@ namespace quickbook
|
||||
{
|
||||
if(!actions.output_pre(out)) return;
|
||||
|
||||
out << pre;
|
||||
std::string str(first, last);
|
||||
char mark = *first;
|
||||
int tag =
|
||||
mark == '*' ? phrase_tags::bold :
|
||||
mark == '/' ? phrase_tags::italic :
|
||||
mark == '_' ? phrase_tags::underline :
|
||||
mark == '=' ? phrase_tags::teletype :
|
||||
0;
|
||||
|
||||
assert(tag != 0);
|
||||
detail::markup markup = detail::markups[tag];
|
||||
|
||||
std::string str(
|
||||
boost::next(first.base()),
|
||||
boost::prior(last.base()));
|
||||
|
||||
out << markup.pre;
|
||||
if (std::string const* ptr = find(macro, str.c_str()))
|
||||
{
|
||||
out << *ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (first != last)
|
||||
detail::print_char(*first++, out.get());
|
||||
detail::print_string(str, out.get());
|
||||
}
|
||||
out << post;
|
||||
out << markup.post;
|
||||
}
|
||||
|
||||
bool cond_phrase_push::start()
|
||||
|
||||
@@ -136,21 +136,15 @@ namespace quickbook
|
||||
|
||||
simple_phrase_action(
|
||||
collector& out
|
||||
, std::string const& pre
|
||||
, std::string const& post
|
||||
, string_symbols const& macro
|
||||
, quickbook::actions& actions)
|
||||
: out(out)
|
||||
, pre(pre)
|
||||
, post(post)
|
||||
, macro(macro)
|
||||
, actions(actions) {}
|
||||
|
||||
void operator()(iterator first, iterator last) const;
|
||||
|
||||
collector& out;
|
||||
std::string pre;
|
||||
std::string post;
|
||||
string_symbols const& macro;
|
||||
quickbook::actions& actions;
|
||||
};
|
||||
|
||||
@@ -77,11 +77,7 @@ namespace quickbook
|
||||
, raw_char(phrase, *this)
|
||||
, escape_unicode(phrase, *this)
|
||||
|
||||
, simple_bold(phrase, bold_pre_, bold_post_, macro, *this)
|
||||
, simple_italic(phrase, italic_pre_, italic_post_, macro, *this)
|
||||
, simple_underline(phrase, underline_pre_, underline_post_, macro, *this)
|
||||
, simple_teletype(phrase, teletype_pre_, teletype_post_, macro, *this)
|
||||
, simple_strikethrough(phrase, strikethrough_pre_, strikethrough_post_, macro, *this)
|
||||
, simple_markup(phrase, macro, *this)
|
||||
|
||||
, break_(phrase, *this)
|
||||
, do_macro(phrase, *this)
|
||||
|
||||
@@ -122,11 +122,7 @@ namespace quickbook
|
||||
raw_char_action raw_char;
|
||||
escape_unicode_action escape_unicode;
|
||||
|
||||
simple_phrase_action simple_bold;
|
||||
simple_phrase_action simple_italic;
|
||||
simple_phrase_action simple_underline;
|
||||
simple_phrase_action simple_teletype;
|
||||
simple_phrase_action simple_strikethrough;
|
||||
simple_phrase_action simple_markup;
|
||||
|
||||
break_action break_;
|
||||
do_macro_action do_macro;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <boost/spirit/include/classic_chset.hpp>
|
||||
#include <boost/spirit/include/classic_if.hpp>
|
||||
#include <boost/spirit/include/classic_loops.hpp>
|
||||
#include <boost/spirit/include/classic_attribute.hpp>
|
||||
#include <boost/spirit/include/phoenix1_primitives.hpp>
|
||||
#include <boost/spirit/include/phoenix1_casts.hpp>
|
||||
|
||||
@@ -26,47 +27,6 @@ namespace quickbook
|
||||
{
|
||||
namespace cl = boost::spirit::classic;
|
||||
|
||||
template <typename Rule, typename Action>
|
||||
inline void
|
||||
simple_markup(
|
||||
Rule& simple
|
||||
, char mark
|
||||
, Action const& action
|
||||
, Rule const& close
|
||||
)
|
||||
{
|
||||
simple =
|
||||
mark
|
||||
>> lookback
|
||||
[ cl::anychar_p
|
||||
>> ~cl::eps_p(mark) // first mark not be preceeded by
|
||||
// the same character.
|
||||
>> (cl::space_p | cl::punct_p | cl::end_p)
|
||||
// first mark must be preceeded
|
||||
// by space or punctuation or the
|
||||
// mark character or a the start.
|
||||
]
|
||||
>> ( cl::graph_p // graph_p must follow first mark
|
||||
>> *( cl::anychar_p -
|
||||
( lookback[cl::graph_p]
|
||||
// final mark must be preceeded by
|
||||
// graph_p
|
||||
>> mark
|
||||
>> ~cl::eps_p(mark) // final mark not be followed by
|
||||
// the same character.
|
||||
>> (cl::space_p | cl::punct_p | cl::end_p)
|
||||
// final mark must be followed by
|
||||
// space or punctuation
|
||||
| close // Make sure that we don't go
|
||||
// past a single block
|
||||
)
|
||||
)
|
||||
>> cl::eps_p(mark)
|
||||
) [action]
|
||||
>> mark
|
||||
;
|
||||
}
|
||||
|
||||
struct main_grammar_local
|
||||
{
|
||||
struct assign_element_type {
|
||||
@@ -141,11 +101,9 @@ namespace quickbook
|
||||
top_level, blocks, paragraph_separator,
|
||||
code, code_line, blank_line, hr,
|
||||
list, list_item, element,
|
||||
simple_phrase_end,
|
||||
escape,
|
||||
inline_code, simple_format,
|
||||
simple_bold, simple_italic, simple_underline,
|
||||
simple_teletype, template_,
|
||||
inline_code,
|
||||
template_,
|
||||
code_block, macro,
|
||||
template_args,
|
||||
template_args_1_4, template_arg_1_4,
|
||||
@@ -157,6 +115,15 @@ namespace quickbook
|
||||
dummy_block
|
||||
;
|
||||
|
||||
struct simple_markup_closure
|
||||
: cl::closure<simple_markup_closure, char>
|
||||
{
|
||||
member1 mark;
|
||||
};
|
||||
|
||||
cl::rule<scanner, simple_markup_closure::context_t>
|
||||
simple_markup, simple_markup_end;
|
||||
|
||||
element_info::type_enum element_type;
|
||||
cl::rule<scanner> element_rule;
|
||||
value::tag_type element_tag;
|
||||
@@ -293,7 +260,7 @@ namespace quickbook
|
||||
| local.break_
|
||||
| local.code_block
|
||||
| local.inline_code
|
||||
| local.simple_format
|
||||
| local.simple_markup
|
||||
| local.escape
|
||||
| comment
|
||||
;
|
||||
@@ -413,23 +380,40 @@ namespace quickbook
|
||||
)
|
||||
;
|
||||
|
||||
local.simple_format =
|
||||
local.simple_bold
|
||||
| local.simple_italic
|
||||
| local.simple_underline
|
||||
| local.simple_teletype
|
||||
local.simple_markup =
|
||||
( cl::chset<>("*/_=") [local.simple_markup.mark = ph::arg1]
|
||||
>> lookback
|
||||
[ cl::anychar_p
|
||||
>> ~cl::eps_p(cl::f_ch_p(local.simple_markup.mark))
|
||||
// first mark not be preceeded by
|
||||
// the same character.
|
||||
>> (cl::space_p | cl::punct_p | cl::end_p)
|
||||
// first mark must be preceeded
|
||||
// by space or punctuation or the
|
||||
// mark character or a the start.
|
||||
]
|
||||
>> cl::graph_p // graph_p must follow first mark
|
||||
>> *(cl::anychar_p - local.simple_markup_end(local.simple_markup.mark))
|
||||
>> cl::f_ch_p(local.simple_markup.mark)
|
||||
) [actions.simple_markup]
|
||||
;
|
||||
|
||||
local.simple_phrase_end = '[' | phrase_end;
|
||||
|
||||
simple_markup(local.simple_bold,
|
||||
'*', actions.simple_bold, local.simple_phrase_end);
|
||||
simple_markup(local.simple_italic,
|
||||
'/', actions.simple_italic, local.simple_phrase_end);
|
||||
simple_markup(local.simple_underline,
|
||||
'_', actions.simple_underline, local.simple_phrase_end);
|
||||
simple_markup(local.simple_teletype,
|
||||
'=', actions.simple_teletype, local.simple_phrase_end);
|
||||
local.simple_markup_end
|
||||
= ( lookback[cl::graph_p] // final mark must be preceeded by
|
||||
// graph_p
|
||||
>> cl::f_ch_p(local.simple_markup_end.mark)
|
||||
>> ~cl::eps_p(cl::f_ch_p(local.simple_markup_end.mark))
|
||||
// final mark not be followed by
|
||||
// the same character.
|
||||
>> (cl::space_p | cl::punct_p | cl::end_p)
|
||||
// final mark must be followed by
|
||||
// space or punctuation
|
||||
)
|
||||
| '['
|
||||
| "'''"
|
||||
| '`'
|
||||
| phrase_end
|
||||
;
|
||||
|
||||
phrase =
|
||||
actions.scoped_context(element_info::in_phrase)
|
||||
@@ -479,7 +463,9 @@ namespace quickbook
|
||||
| (
|
||||
("'''" >> !eol) [actions.escape_pre]
|
||||
>> *(cl::anychar_p - "'''") [actions.raw_char]
|
||||
>> cl::str_p("'''") [actions.escape_post]
|
||||
>> ( cl::str_p("'''") [actions.escape_post]
|
||||
| cl::eps_p [actions.error("Unclosed boostbook escape.")]
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ test-suite quickbook.test :
|
||||
[ quickbook-error-test fail-unknown-quickbook-1 ]
|
||||
[ quickbook-error-test fail-unknown-quickbook-2 ]
|
||||
[ quickbook-error-test fail-unknown-quickbook-3 ]
|
||||
[ quickbook-error-test fail-mismatched-boostbook-escape ]
|
||||
[ quickbook-test utf-8 ]
|
||||
[ quickbook-test utf-8-bom ]
|
||||
[ quickbook-test unicode-escape ]
|
||||
|
||||
5
test/fail-mismatched-boostbook-escape.quickbook
Normal file
5
test/fail-mismatched-boostbook-escape.quickbook
Normal file
@@ -0,0 +1,5 @@
|
||||
[article Badly escaped boostbook
|
||||
[quickbook 1.5]
|
||||
]
|
||||
|
||||
'''<emphasis>something</emphasis>
|
||||
@@ -17,7 +17,7 @@
|
||||
not__underlined__hopefully
|
||||
</para>
|
||||
<para>
|
||||
(<emphasis role="bold">bold</emphasis>)
|
||||
(<emphasis role="bold">bold</emphasis>) <emphasis role="underline">und/er/lined</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>all/italic</emphasis> * not bold*
|
||||
@@ -28,5 +28,8 @@
|
||||
<para>
|
||||
not_underlined_
|
||||
</para>
|
||||
<para>
|
||||
_Should not underline escaped markup_. _or this escaped_ markup form.
|
||||
</para>
|
||||
</section>
|
||||
</article>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
not__underlined__hopefully
|
||||
|
||||
(*bold*)
|
||||
(*bold*) _und/er/lined_
|
||||
|
||||
/all/italic/ * not bold*
|
||||
|
||||
@@ -18,4 +18,7 @@ not__underlined__hopefully
|
||||
|
||||
not_underlined_
|
||||
|
||||
_Should not underline '''escaped''' markup_.
|
||||
_or this '''escaped_ markup''' form.
|
||||
|
||||
[endsect]
|
||||
Reference in New Issue
Block a user