|
|
@ -13,7 +13,7 @@ Gemini::Gemini( |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
auto label = Gtk::make_managed<Gtk::Label>( // @TODO separated file?
|
|
|
|
auto label = Gtk::make_managed<Gtk::Label>( // @TODO separated file?
|
|
|
|
to_pango_markup( |
|
|
|
Markup::make( |
|
|
|
GEMTEXT |
|
|
|
GEMTEXT |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
@ -51,10 +51,38 @@ Gemini::Gemini( |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Glib::ustring Gemini::to_pango_markup( |
|
|
|
// Match tools
|
|
|
|
|
|
|
|
bool Gemini::Line::Match::link( |
|
|
|
|
|
|
|
const Glib::ustring & GEMTEXT, |
|
|
|
|
|
|
|
Glib::ustring & address, |
|
|
|
|
|
|
|
Glib::ustring & date, |
|
|
|
|
|
|
|
Glib::ustring & alt |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
auto match = Glib::Regex::split_simple( |
|
|
|
|
|
|
|
R"regex(^=>\s*([^\s]+)(\s(\d{4}-\d{2}-\d{2}))?(\s(.+))?$)regex", |
|
|
|
|
|
|
|
GEMTEXT |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int index = 0; for (const Glib::ustring & MATCH : match) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (index) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case 1: address = MATCH; break; |
|
|
|
|
|
|
|
case 3: date = MATCH; break; |
|
|
|
|
|
|
|
case 5: alt = MATCH; break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
index++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return !address.empty(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Markup tools
|
|
|
|
|
|
|
|
Glib::ustring Gemini::Markup::make( |
|
|
|
const Glib::ustring & GEMTEXT |
|
|
|
const Glib::ustring & GEMTEXT |
|
|
|
) { |
|
|
|
) { |
|
|
|
Glib::ustring markup; |
|
|
|
Glib::ustring pango; |
|
|
|
|
|
|
|
|
|
|
|
std::istringstream stream( |
|
|
|
std::istringstream stream( |
|
|
|
GEMTEXT |
|
|
|
GEMTEXT |
|
|
@ -64,81 +92,70 @@ Glib::ustring Gemini::to_pango_markup( |
|
|
|
|
|
|
|
|
|
|
|
while (std::getline(stream, line)) |
|
|
|
while (std::getline(stream, line)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Convert links
|
|
|
|
// Links
|
|
|
|
auto match = Glib::Regex::split_simple( |
|
|
|
Glib::ustring address; |
|
|
|
R"regex(^=>\s*([^\s]+)(\s(\d{4}-\d{2}-\d{2}))?(\s(.+))?$)regex", |
|
|
|
Glib::ustring date; |
|
|
|
line.c_str() |
|
|
|
Glib::ustring alt; |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Glib::ustring address = ""; |
|
|
|
|
|
|
|
Glib::ustring date = ""; |
|
|
|
|
|
|
|
Glib::ustring alt = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int index = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const Glib::ustring & VALUE : match) |
|
|
|
if (Line::Match::link(line, address, date, alt)) |
|
|
|
{ |
|
|
|
|
|
|
|
switch (index) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
case 1: address = VALUE; break; |
|
|
|
pango.append( |
|
|
|
case 3: date = VALUE; break; |
|
|
|
Markup::Make::link( |
|
|
|
case 5: alt = VALUE; break; |
|
|
|
address, |
|
|
|
|
|
|
|
date, |
|
|
|
|
|
|
|
alt |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
index++; |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
pango.append( |
|
|
|
|
|
|
|
GEMTEXT |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Keep original on address not found in line
|
|
|
|
// @TODO other tags..
|
|
|
|
if (address.empty()) |
|
|
|
|
|
|
|
{ |
|
|
|
pango.append( |
|
|
|
markup.append( |
|
|
|
"\n" // @TODO
|
|
|
|
line |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Make pango link
|
|
|
|
return pango; |
|
|
|
else |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
// Crate link name
|
|
|
|
Glib::ustring Gemini::Markup::Make::link( |
|
|
|
Glib::ustring name; |
|
|
|
const Glib::ustring & ADDRESS, |
|
|
|
|
|
|
|
const Glib::ustring & DATE, |
|
|
|
|
|
|
|
const Glib::ustring & ALT |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
Glib::ustring description; |
|
|
|
|
|
|
|
|
|
|
|
if (!date.empty()) |
|
|
|
if (!DATE.empty()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
name.append( |
|
|
|
description.append( |
|
|
|
date |
|
|
|
DATE |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!alt.empty()) |
|
|
|
if (!ALT.empty()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
name.append( |
|
|
|
description.append( |
|
|
|
name.empty() ? alt |
|
|
|
description.empty() ? ALT : description + " " + ALT // append (to date)
|
|
|
|
: name + " " + alt // append (to date)
|
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create pango markup
|
|
|
|
return Glib::ustring::sprintf( |
|
|
|
markup.append( |
|
|
|
|
|
|
|
Glib::ustring::sprintf( |
|
|
|
|
|
|
|
"<a href=\"%s\" title=\"%s\">%s</a>", |
|
|
|
"<a href=\"%s\" title=\"%s\">%s</a>", |
|
|
|
Glib::Markup::escape_text( |
|
|
|
Glib::Markup::escape_text( |
|
|
|
address // @TODO to absolute
|
|
|
|
ADDRESS // @TODO to absolute
|
|
|
|
), |
|
|
|
), |
|
|
|
Glib::Markup::escape_text( |
|
|
|
Glib::Markup::escape_text( |
|
|
|
address |
|
|
|
ADDRESS |
|
|
|
), |
|
|
|
), |
|
|
|
Glib::Markup::escape_text( |
|
|
|
Glib::Markup::escape_text( |
|
|
|
name |
|
|
|
description |
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
markup.append( |
|
|
|
|
|
|
|
"\n" // @TODO
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return original gemtext on failure or pango markup on success
|
|
|
|
|
|
|
|
return markup.empty() ? GEMTEXT : markup; |
|
|
|
|
|
|
|
} |
|
|
|
|