From 333f2177f08e0fc5a241827af860f4b2f1b9d8e9 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Mon, 4 Nov 2013 17:19:43 +0000 Subject: [PATCH] Updated syntax doc with new hyperlinking syntax. --- docs/BOSS Metadata Syntax.html | 23 ++++++++------- src/backend/generators.h | 54 ++++++++++++++-------------------- 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/docs/BOSS Metadata Syntax.html b/docs/BOSS Metadata Syntax.html index 2af3d9d9..8a7626e9 100644 --- a/docs/BOSS Metadata Syntax.html +++ b/docs/BOSS Metadata Syntax.html @@ -229,11 +229,11 @@ display: 'OBSE v18+' condition: 'file("foo.esp")' content: - lang: 'eng' - str: 'An example link: http://www.example.com' + str: 'An example link: <http://www.example.com>' - lang: 'rus' - str: 'Это пример ссылки: http://www.example.com' + str: 'Это пример ссылки: <http://www.example.com>' - lang: 'ger' - str: 'Ein Beispiel-Link: http://www.example.com' + str: 'Ein Beispiel-Link: <http://www.example.com>' would be displayed as
@@ -241,7 +241,7 @@ would be displayed as
if the current language was Russian and foo.esp was installed, while type: 'say' -content: 'An alternative "http://www.example.com example link", with no translations.' +content: 'An alternative [example link](http://www.example.com), with no translations.' would be displayed as
@@ -283,7 +283,7 @@ ver:

Examples: crc: 0x3DF62ABC -util: '"http://www.creationkit.com/TES5Edit_Cleaning_Guide_-_TES5Edit TES5Edit"' +util: '[TES5Edit](http://www.creationkit.com/TES5Edit_Cleaning_Guide_-_TES5Edit)' itm: 4 udr: 160 nav: 0 @@ -311,7 +311,7 @@ nav: 0 req: - 'Oblivion.esm' # Don't do this, Oblivion.esm is a master of Oscuro's_Oblivion_Overhaul.esm, so BOSS already knows it's required. - name: 'example.esp' - display: '"http://www.example.com Example Mod"' + display: '[Example Mod](http://www.example.com)' condition: 'version("Oscuro''s_Oblivion_Overhaul.esm", "15.0", ==)' tag: - 'Actors.Spells' @@ -329,14 +329,17 @@ msg:

-

File display strings and message content strings (including the strings in localised content structures) that contain recognised URLs have them displayed as hyperlinks in the BOSS report. Recognised URLs are those that are enclosed in double quotes and that begin with file:, http: or https:. -

Hyperlinks may be labelled by writing the label after the URL inside the double quotes, with a space separating the label and URL. If a label is not provided, then the hyperlink will use the URL as its own label. +

File display strings and message content strings (including the strings in localised content structures) that contain recognised URLs have them displayed as hyperlinks in the BOSS report. +

URLs must begin with file:, http: or https:, and be written according to the following subset of Markdown syntax. Note that BOSS does not recognise additional Markdown syntaxes to those given below. +

For labelled URLs, the syntax is [label](url). A single optional space may be included between the closing square bracket and the opening parenthesis, ie. [label] (url). +

For unlabelled URLs, the syntax is <url>. The URL shall be used as its own label. +

Note that the URLs given as part of a location data structure should not be labelled or enclosed in less-than or greater-than signs, as they consist of raw URL data, rather than URLs within arbitrary strings.

Examples: -'This "https://en.wikipedia.org/wiki/String_(computer_science) string" contains a labelled hyperlink.' +'This [string](https://en.wikipedia.org/wiki/String_(computer_science)) contains a labelled hyperlink.' would be displayed as

This string contains a labelled hyperlink.

While -'This string (see: "https://en.wikipedia.org/wiki/String_(computer_science)") contains an unlabelled hyperlink.' +'This string (see: <https://en.wikipedia.org/wiki/String_(computer_science)>) contains an unlabelled hyperlink.' both get displayed as

This string (see: https://en.wikipedia.org/wiki/String_(computer_science)) contains an unlabelled hyperlink.
diff --git a/src/backend/generators.h b/src/backend/generators.h index 91e22a01..903e852c 100644 --- a/src/backend/generators.h +++ b/src/backend/generators.h @@ -85,46 +85,36 @@ namespace boss { else content = boost::locale::translate("Error:").str() + " " + content; - size_t pos1f = content.find("\"file:"); - size_t pos1h = content.find("\"http"); - size_t pos1; - if (pos1f < pos1h) - pos1 = pos1f; - else - pos1 = pos1h; - size_t pos3 = content.find('"', pos1+1); + //Now look for Markdown URL syntax and convert any found. + boost::regex regex("(\\[(.+)\\]\\s?\\(|<)((file|https?)://\\S+)(\\)|>)", boost::regex::perl | boost::regex::icase); // \2 is the label, \3 is the URL. - while (pos1 != std::string::npos && pos3 != std::string::npos) { - std::string url, display; - size_t pos2 = content.substr(pos1, pos3 - pos1).find(' ', pos1); - if (pos2 != std::string::npos) { //Labelled - url = content.substr(pos1 + 1, pos2 - 1); - display = content.substr(pos1 + pos2 + 1, pos3 - pos1 - pos2 - 1); - } else { //Unlabelled. - url = content.substr(pos1 + 1, pos3 - pos1 - 1); - display = url; - } + boost::match_results results; + std::string::iterator start, end; + start = content.begin(); + end = content.end(); + + while (boost::regex_search(start, end, results, regex)) { + + //Get data from match. + std::string url, label; + url = std::string(results[3].first, results[3].second); + if (results[2].matched) + label = std::string(results[2].first, results[2].second); + else + label = url; + + //Cut matched substring from string. + content = std::string(results[0].second, content.end()); + start = content.begin(); //Insert normal text preceding hyperlink. - listItem.append_child(pugi::node_pcdata).set_value(content.substr(0, pos1).c_str()); + listItem.append_child(pugi::node_pcdata).set_value(std::string(content.begin(), results[0].first).c_str()); //Insert hyperlink. pugi::xml_node a = listItem.append_child(); a.set_name("a"); a.append_attribute("href").set_value(url.c_str()); - a.text().set(display.c_str()); - - //Remove all the processed text from the string. - content = content.substr(pos3+1); - - //Look for the next hyperlink. - pos1f = content.find("\"file:"); - pos1h = content.find("\"http"); - if (pos1f < pos1h) - pos1 = pos1f; - else - pos1 = pos1h; - pos3 = content.find('"', pos1+1); + a.text().set(label.c_str()); } //Insert any leftover text.