summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/elements.h12
-rw-r--r--src/generators/latex/text_g.cpp5
-rw-r--r--src/generators/latex/text_g.h3
-rw-r--r--src/parser/document_p.cpp2
-rw-r--r--src/parser/text_p.cpp5
-rw-r--r--src/parser/text_p.h1
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<std::wstring> oiterator;
struct stext_t;
-typedef boost::variant<boost::recursive_wrapper<stext_t>, std::wstring> text_t;
+struct pstext_t;
+typedef boost::variant<boost::recursive_wrapper<stext_t>,
+ boost::recursive_wrapper<pstext_t>,
+ 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<text_t> value;
+ std::wstring parameter;
};
typedef std::vector<text_t> 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<text_t>, 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 <boost/spirit/include/karma.hpp>
+#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/support_standard_wide.hpp>
#include "../../elements.h"
namespace ka = boost::spirit::karma;
+namespace ph = boost::phoenix;
namespace latex {
struct text_g : ka::grammar<oiterator, text_t()> {
ka::rule<oiterator, text_t()> text_;
ka::rule<oiterator, stext_t()> stext_;
+ ka::rule<oiterator, pstext_t()> pstext_;
ka::rule<oiterator, std::wstring()> 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<iiterator, text_t(std::wstring)> {
qi::rule<iiterator, text_t(std::wstring)> text_;
qi::rule<iiterator, stext_t(std::wstring)> stext_;
+ qi::rule<iiterator, pstext_t(std::wstring)> pstext_;
qi::rule<iiterator, std::wstring(std::wstring)> ptext_;
qi::rule<iiterator, wchar_t()> echar_;
qi::rule<iiterator, wchar_t(std::wstring)> rchar_;