From 4291a6aac9ee4a1c79bc24c40d4c558bf88d3e93 Mon Sep 17 00:00:00 2001 From: GrĂ©goire DuchĂȘne Date: Thu, 17 Feb 2011 13:43:53 +0100 Subject: Explicit link support added. --- src/elements.h | 12 ++++++++---- src/generators/latex/text_g.cpp | 5 ++++- src/generators/latex/text_g.h | 3 +++ src/parser/document_p.cpp | 2 +- src/parser/text_p.cpp | 5 ++++- src/parser/text_p.h | 1 + 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/elements.h b/src/elements.h index c207810..82eb559 100644 --- a/src/elements.h +++ b/src/elements.h @@ -24,7 +24,10 @@ typedef std::wstring::iterator iiterator; typedef std::back_insert_iterator oiterator; struct stext_t; -typedef boost::variant, std::wstring> text_t; +struct pstext_t; +typedef boost::variant, + boost::recursive_wrapper, + std::wstring> text_t; enum stattribute_t { EMPH, @@ -36,7 +39,8 @@ enum stattribute_t { MATH, SUPER, QUOTE, - SUB + SUB, + LINK }; struct stext_t { @@ -46,8 +50,8 @@ struct stext_t { struct pstext_t { stattribute_t attribute; - std::wstring parameter; std::vector value; + std::wstring parameter; }; typedef std::vector document_t; @@ -59,7 +63,7 @@ BOOST_FUSION_ADAPT_STRUCT (stext_t, BOOST_FUSION_ADAPT_STRUCT (pstext_t, (stattribute_t, attribute) - (std::wstring, parameter) (std::vector, value) + (std::wstring, parameter) ) #endif diff --git a/src/generators/latex/text_g.cpp b/src/generators/latex/text_g.cpp index 015608d..90471ae 100644 --- a/src/generators/latex/text_g.cpp +++ b/src/generators/latex/text_g.cpp @@ -19,7 +19,7 @@ latex::text_g::text_g() : text_g::base_type(text_) { using namespace ka; using ka::standard_wide::char_; - text_ = stext_ | ptext_; + text_ = stext_ | pstext_ | ptext_; stext_ = &uint_(EMPH) << L"\\emph{" << +text_ << '}' | &uint_(SEMPH) << L"\\textit{\\emph{" << +text_ << L"}}" @@ -32,5 +32,8 @@ latex::text_g::text_g() : text_g::base_type(text_) { | &uint_(QUOTE) << L"``" << +text_ << L"''" | &uint_(SUB) << L"_{" << +text_ << '}'; + pstext_ = &uint_(LINK) << L"\\href{" << ptext_[_1 = ph::at_c<2>(_val)] + << L"}{" << (+text_)[_1 = ph::at_c<1>(_val)] << '}'; + ptext_ = +char_; } diff --git a/src/generators/latex/text_g.h b/src/generators/latex/text_g.h index a2174e7..2d26a4d 100644 --- a/src/generators/latex/text_g.h +++ b/src/generators/latex/text_g.h @@ -16,15 +16,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef _MPPDOWN_LATEX_TEXT_G #define _MPPDOWN_LATEX_TEXT_G #include +#include #include #include "../../elements.h" namespace ka = boost::spirit::karma; +namespace ph = boost::phoenix; namespace latex { struct text_g : ka::grammar { ka::rule text_; ka::rule stext_; + ka::rule pstext_; ka::rule ptext_; text_g(); diff --git a/src/parser/document_p.cpp b/src/parser/document_p.cpp index 208e1f1..5b45212 100644 --- a/src/parser/document_p.cpp +++ b/src/parser/document_p.cpp @@ -16,5 +16,5 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "document_p.h" document_p::document_p() : document_p::base_type(document_) { - document_ = +text_(ph::val(L"*'`$^@")); + document_ = +text_(ph::val(L"*'`$^@[")); } diff --git a/src/parser/text_p.cpp b/src/parser/text_p.cpp index 0701691..ce1e233 100644 --- a/src/parser/text_p.cpp +++ b/src/parser/text_p.cpp @@ -20,7 +20,7 @@ text_p::text_p() : text_p::base_type(text_) { using namespace ph; using qi::standard_wide::char_; - text_ = stext_(_r1) | ptext_(_r1); + text_ = stext_(_r1) | pstext_(_r1) | ptext_(_r1); stext_ = lit("***") >> attr(VSEMPH) >> +text_(_r1) >> "***" | lit("**") >> attr(SEMPH) >> +text_(_r1) >> "**" @@ -34,6 +34,9 @@ text_p::text_p() : text_p::base_type(text_) { | lit(L"@\"") >> attr(QUOTE) >> +text_(val(L"*'`$@\"")) >> '"' | lit(L"@_") >> attr(SUB) >> +text_(val(L"*'`$@_")) >> '_'; + pstext_ = lit('[') >> attr(LINK) >> +text_(val(L"]")) >> ']' >> + lit('(') >> ptext_(val(L")")) >> ')'; + ptext_ = +(echar_ | rchar_(_r1)); echar_ = lit('\\') >> char_; rchar_ = char_ - char_(_r1); diff --git a/src/parser/text_p.h b/src/parser/text_p.h index d9fe7a0..35fc41f 100644 --- a/src/parser/text_p.h +++ b/src/parser/text_p.h @@ -26,6 +26,7 @@ namespace ph = boost::phoenix; struct text_p : qi::grammar { qi::rule text_; qi::rule stext_; + qi::rule pstext_; qi::rule ptext_; qi::rule echar_; qi::rule rchar_; -- cgit v1.2.3-70-g09d2