Skip to content

Commit

Permalink
Added BBCode Support
Browse files Browse the repository at this point in the history
  • Loading branch information
DilemmaGX committed Dec 13, 2023
1 parent e969f88 commit 2275f8a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<img src="https://custom-icon-badges.demolab.com/badge/Markdown-Supported-mediumseagreen?style=flat-square" alt="">
<img src="https://custom-icon-badges.demolab.com/badge/rSt-Supported-mediumseagreen?style=flat-square" alt="">
<img src="https://custom-icon-badges.demolab.com/badge/AsciiDoc-Supported-mediumseagreen?style=flat-square" alt="">
<img src="https://custom-icon-badges.demolab.com/badge/HTML-Supported-mediumseagreen?style=flat-square" alt=""></p></div>
<img src="https://custom-icon-badges.demolab.com/badge/HTML-Supported-mediumseagreen?style=flat-square" alt="">
<img src="https://custom-icon-badges.demolab.com/badge/BBCode-Supported-mediumseagreen?style=flat-square" alt=""></p></div>

> [!NOTE]
> Link support for `rSt` is missing. This means that you **CANNOT** click on the badge to redirect to the page you added in the parameters.
Expand Down
4 changes: 2 additions & 2 deletions doc/HOW.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ <h4>User Interface</h4>
</p>
<p>
The Generator part basically handles the main generation functions to generate a badge. For This version,
the Generate supports <code>URL</code>, <code>Markdown</code>, <code>rSt</code>, <code>AsciiDoc</code>, and
<code>HTML</code>.
the Generate supports <code>URL</code>, <code>Markdown</code>, <code>rSt</code>, <code>AsciiDoc</code>,
<code>HTML</code>, and <code>BBCode</code>.
</p>
<p>
The Quick Reference (QR) contains five iframe elements in current version. The QR contains a doc tab (this
Expand Down
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<body>
<div class="row" style="margin: auto;">
<div class="col col-lg-7">
<div style="max-width: 600px; margin: auto; margin-top: 15px;">
<div style="max-width: 700px; margin: auto; margin-top: 15px;">
<div align="middle">
<h1>Static Badge Maker</h1>
<a href="http://github.com/dilemmaGX/shields-maker"><img alt="GitHub License"
Expand Down Expand Up @@ -71,6 +71,7 @@ <h1>Static Badge Maker</h1>
AsciiDoc</button>
<button type="button" class="btn btn-outline-primary" onclick="copy('o_html')">Copy
HTML</button>
<button type="button" class="btn btn-outline-primary" onclick="copy('o_bbc')">Copy BBCode</button>
</div>
<br><br>
<div id="o_url" class="url">
Expand All @@ -93,6 +94,10 @@ <h4>AsciiDoc</h4>
<h4>HTML</h4>
<pre><code style="white-space: pre-wrap;word-wrap: break-word;">&lt;a href="http://github.com/DilemmaGX"&gt;&lt;img src="https://custom-icon-badges.demolab.com/badge/Hello-World-ff9900?style=flat&amp;logo=github&amp;logoColor=ffffff" alt="Hello - World"&gt;&lt;/a&gt;</code></pre>
</div>
<div id="o_bbc" class="bbc">
<h4>HTML</h4>
<pre><code style="white-space: pre-wrap;word-wrap: break-word;">[url=http://github.com/DilemmaGX][img]https://custom-icon-badges.demolab.com/badge/Hello-World-ff9900?style=flat&logo=github&logoColor=white[/img][/url]</code></pre>
</div>
</div>
</div>
</div>
Expand Down
42 changes: 29 additions & 13 deletions src/static.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
function g_url(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", source="default") {
function g_url(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", source = "default") {
var url = "https://custom-icon-badges.demolab.com/badge/";
left += "-" || "";
if (right != "") {
url += left + right + "-" + color + "?style=" + style;
if (logo != "") {
url += "&logo=" + logo + "&logoColor=" + logoColor;
}
if(source!="default"){
return url+"&logoSource="+source;
if (source != "default") {
return url + "&logoSource=" + source;
} else {
return url;
}
}
}

function g_html(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", link, source="default") {
var url = g_url(left, right, color, style, logo, logoColor,source);
function g_html(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", link, source = "default") {
var url = g_url(left, right, color, style, logo, logoColor, source);
var html;
if (link !== "") {
if (!RegExp("^https?:\/\/").test(link)) {
Expand All @@ -28,8 +28,8 @@ function g_html(left = "", right, color = "default", style = "flat", logo = "",
return html;
}

function g_md(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", link, source="default") {
var url = g_url(left, right, color, style, logo, logoColor,source);
function g_md(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", link, source = "default") {
var url = g_url(left, right, color, style, logo, logoColor, source);
var md;
if (link !== "") {
if (!RegExp("^https?:\/\/").test(link)) {
Expand All @@ -42,8 +42,8 @@ function g_md(left = "", right, color = "default", style = "flat", logo = "", lo
return md;
}

function g_ad(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", link, source="default") {
var url = g_url(left, right, color, style, logo, logoColor,source);
function g_ad(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", link, source = "default") {
var url = g_url(left, right, color, style, logo, logoColor, source);
var ad;
if (link !== "") {
if (!RegExp("^https?:\/\/").test(link)) {
Expand All @@ -56,16 +56,30 @@ function g_ad(left = "", right, color = "default", style = "flat", logo = "", lo
return ad;
}

function g_rst(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", link, source="default") {
var url = g_url(left, right, color, style, logo, logoColor,source);
function g_rst(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", link, source = "default") {
var url = g_url(left, right, color, style, logo, logoColor, source);
var rst;
if (link !== "") {
if (!RegExp("^https?:\/\/").test(link)) {
link = "http://" + link;
}
rst = ".. image:: " + url + "\n :target: " + link;
} else {
rst = ".. image:: " + url ;
rst = ".. image:: " + url;
}
return rst;
}

function g_bbc(left = "", right, color = "default", style = "flat", logo = "", logoColor = "default", link, source = "default") {
var url = g_url(left, right, color, style, logo, logoColor, source);
var rst;
if (link !== "") {
if (!RegExp("^https?:\/\/").test(link)) {
link = "http://" + link;
}
rst = "[url=" + link + "][img]" + url + "[/img][/url]";
} else {
rst = "[img]" + url + "[/img]";
}
return rst;
}
Expand All @@ -88,6 +102,7 @@ function auto() {
var o_md = document.getElementById("o_md");
var o_ad = document.getElementById("o_ad");
var o_rst = document.getElementById("o_rst");
var o_bbc = document.getElementById("o_bbc");

left = left.replace(/[-_]/g, m => m === '-' ? '--' : '__').replace(/\s/g, '_');
right = right.replace(/[-_]/g, m => m === '-' ? '--' : '__').replace(/\s/g, '_');
Expand All @@ -104,7 +119,8 @@ function auto() {
o_html.innerHTML = "<pre><code style=\"white-space: pre-wrap;word-wrap: break-word;\">" + g_html(left, right, color, style, logo, logoColor, link, source).replace(/</g, '&lt;').replace(/>/g, '&gt;') + "</pre></code>";
o_md.innerHTML = "<pre><code style=\"white-space: pre-wrap;word-wrap: break-word;\">" + g_md(left, right, color, style, logo, logoColor, link, source).replace(/</g, '&lt;').replace(/>/g, '&gt;') + "</pre></code>";
o_ad.innerHTML = "<pre><code style=\"white-space: pre-wrap;word-wrap: break-word;\">" + g_ad(left, right, color, style, logo, logoColor, link, source).replace(/</g, '&lt;').replace(/>/g, '&gt;') + "</pre></code>";
o_rst.innerHTML = "<pre><code style=\"white-space: pre-wrap;word-wrap: break-word;\">" + g_rst(left, right, color, style, logo, logoColor, link, source).replace(/</g, '&lt;').replace(/>/g, '&gt;')+ "</pre></code>";
o_rst.innerHTML = "<pre><code style=\"white-space: pre-wrap;word-wrap: break-word;\">" + g_rst(left, right, color, style, logo, logoColor, link, source).replace(/</g, '&lt;').replace(/>/g, '&gt;') + "</pre></code>";
o_bbc.innerHTML = "<pre><code style=\"white-space: pre-wrap;word-wrap: break-word;\">" + g_bbc(left, right, color, style, logo, logoColor, link, source).replace(/</g, '&lt;').replace(/>/g, '&gt;') + "</pre></code>";
}

function copy(id) {
Expand Down

0 comments on commit 2275f8a

Please sign in to comment.