Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/halogenica/beautifulhugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorMichael Romero <halogenica@users.noreply.github.com>2018-09-16 08:09:16 +0300
committerGitHub <noreply@github.com>2018-09-16 08:09:16 +0300
commit7de78468e04c1b75aea647f8b1375b512d67abf1 (patch)
tree272d3de8b9985b0c21beabac6d0e69a560a13899 /static
parent37825f541e2dc6728ebdcf83d23baa6c7ffb046d (diff)
parentbf36c16ef9c6668d46bb7c7f1d59f30528c35e39 (diff)
Merge pull request #187 from rsletta/master
Add Markdown links to bigimg description
Diffstat (limited to 'static')
-rw-r--r--static/js/main.js32
1 files changed, 31 insertions, 1 deletions
diff --git a/static/js/main.js b/static/js/main.js
index fea58db..99200c7 100644
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -140,7 +140,37 @@ var main = {
$(".intro-header.big-img").css("background-position", "");
}
if (typeof desc !== typeof undefined && desc !== false) {
- $(".img-desc").text(desc).show();
+ // Check for Markdown link
+ var mdLinkRe = /\[(.*?)\]\((.+?)\)/;
+ if (desc.match(mdLinkRe)) {
+ // Split desc into parts, extracting md links
+ var splitDesc = desc.split(mdLinkRe);
+
+ // Build new description
+ var imageDesc = $(".img-desc");
+ splitDesc.forEach(function (element, index){
+ // Check element type. If links every 2nd element is link text, and every 3rd link url
+ if (index % 3 === 0) {
+ // Regular text, just append it
+ imageDesc.append(element);
+ }
+ if (index % 3 === 1) {
+ // Link text - do nothing at the moment
+ }
+ if (index % 3 === 2) {
+ // Link url - Create anchor tag with text
+ var link = $("<a>", {
+ "href": element,
+ "target": "_blank",
+ "rel": "noopener noreferrer"
+ }).text(splitDesc[index - 1]);
+ imageDesc.append(link);
+ }
+ });
+ imageDesc.show();
+ } else {
+ $(".img-desc").text(desc).show();
+ }
} else {
$(".img-desc").hide();
}