Skip to content

Commit

Permalink
Added support for BBCode (#2095)
Browse files Browse the repository at this point in the history
This adds support for the BBCode markup language.
  • Loading branch information
RunDevelopment committed Oct 25, 2019
1 parent ee7fdbe commit aaf13aa
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -160,6 +160,10 @@
"title": "Batch",
"owner": "Golmote"
},
"bbcode": {
"title": "BBcode",
"owner": "RunDevelopment"
},
"bison": {
"title": "Bison",
"require": "c",
Expand Down
27 changes: 27 additions & 0 deletions components/prism-bbcode.js
@@ -0,0 +1,27 @@
Prism.languages.bbcode = {
'tag': {
pattern: /\[\/?[^\s=\]]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'"\]=]+))?(?:\s+[^\s=\]]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'"\]=]+))*\s*\]/,
inside: {
'tag': {
pattern: /^\[\/?[^\s=\]]+/,
inside: {
'punctuation': /^\[\/?/
}
},
'attr-value': {
pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'"\]=]+)/i,
inside: {
'punctuation': [
/^=/,
{
pattern: /^(\s*)["']|["']$/,
lookbehind: true
}
]
}
},
'punctuation': /\]/,
'attr-name': /[^\s=\]]+/
}
}
};
1 change: 1 addition & 0 deletions components/prism-bbcode.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions examples/prism-bbcode.html
@@ -0,0 +1,21 @@
<h2>Full example</h2>
<pre><code>[list]
[*]Entry A
[*]Entry B
[/list]

[list=1]
[*]Entry 1
[*]Entry 2
[/list]

[style color="fuchsia"]Text in fuchsia[/style] or
[style color=#FF00FF]Text in fuchsia[/style] or
[color=#FF00FF]Text in fuchsia[/color]
[quote]quoted text[/quote]
[quote="author"]quoted text[/quote]

[:-)]

[url]https://en.wikipedia.org[/url]
[url=https://en.wikipedia.org]English Wikipedia[/url]</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -35,6 +35,7 @@
"autoit": "AutoIt",
"shell": "Bash",
"basic": "BASIC",
"bbcode": "BBcode",
"bnf": "Backus–Naur form",
"rbnf": "Routing Backus–Naur form",
"csharp": "C#",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

237 changes: 237 additions & 0 deletions tests/languages/bbcode/tag_feature.test
@@ -0,0 +1,237 @@
[list]
[*]Entry A
[*]Entry B
[/list]

[list=1]
[*]Entry 1
[*]Entry 2
[/list]

[style color="fuchsia"]Text in fuchsia[/style] or
[style color=#FF00FF]Text in fuchsia[/style] or
[color=#FF00FF]Text in fuchsia[/color]
[quote]quoted text[/quote]
[quote="author"]quoted text[/quote]

[:-)]

[url]https://en.wikipedia.org[/url]
[url=https://en.wikipedia.org]English Wikipedia[/url]

----------------------------------------------------

[
["tag", [
["tag", [
["punctuation", "["],
"list"
]],
["punctuation", "]"]
]],
["tag", [
["tag", [
["punctuation", "["],
"*"
]],
["punctuation", "]"]
]],
"Entry A\n ",
["tag", [
["tag", [
["punctuation", "["],
"*"
]],
["punctuation", "]"]
]],
"Entry B\n",
["tag", [
["tag", [
["punctuation", "[/"],
"list"
]],
["punctuation", "]"]
]],

["tag", [
["tag", [
["punctuation", "["],
"list"
]],
["attr-value", [
["punctuation", "="],
"1"
]],
["punctuation", "]"]
]],
["tag", [
["tag", [
["punctuation", "["],
"*"
]],
["punctuation", "]"]
]],
"Entry 1\n ",
["tag", [
["tag", [
["punctuation", "["],
"*"
]],
["punctuation", "]"]
]],
"Entry 2\n",
["tag", [
["tag", [
["punctuation", "[/"],
"list"
]],
["punctuation", "]"]
]],

["tag", [
["tag", [
["punctuation", "["],
"style"
]],
["attr-name", "color"],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"fuchsia",
["punctuation", "\""]
]],
["punctuation", "]"]
]],
"Text in fuchsia",
["tag", [
["tag", [
["punctuation", "[/"],
"style"
]],
["punctuation", "]"]
]],
" or\n",
["tag", [
["tag", [
["punctuation", "["],
"style"
]],
["attr-name", "color"],
["attr-value", [
["punctuation", "="],
"#FF00FF"
]],
["punctuation", "]"]
]],
"Text in fuchsia",
["tag", [
["tag", [
["punctuation", "[/"],
"style"
]],
["punctuation", "]"]
]],
" or\n",
["tag", [
["tag", [
["punctuation", "["],
"color"
]],
["attr-value", [
["punctuation", "="],
"#FF00FF"
]],
["punctuation", "]"]
]],
"Text in fuchsia",
["tag", [
["tag", [
["punctuation", "[/"],
"color"
]],
["punctuation", "]"]
]],
["tag", [
["tag", [
["punctuation", "["],
"quote"
]],
["punctuation", "]"]
]],
"quoted text",
["tag", [
["tag", [
["punctuation", "[/"],
"quote"
]],
["punctuation", "]"]
]],
["tag", [
["tag", [
["punctuation", "["],
"quote"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"author",
["punctuation", "\""]
]],
["punctuation", "]"]
]],
"quoted text",
["tag", [
["tag", [
["punctuation", "[/"],
"quote"
]],
["punctuation", "]"]
]],

["tag", [
["tag", [
["punctuation", "["],
":-)"
]],
["punctuation", "]"]
]],

["tag", [
["tag", [
["punctuation", "["],
"url"
]],
["punctuation", "]"]
]],
"https://en.wikipedia.org",
["tag", [
["tag", [
["punctuation", "[/"],
"url"
]],
["punctuation", "]"]
]],
["tag", [
["tag", [
["punctuation", "["],
"url"
]],
["attr-value", [
["punctuation", "="],
"https://en.wikipedia.org"
]],
["punctuation", "]"]
]],
"English Wikipedia",
["tag", [
["tag", [
["punctuation", "[/"],
"url"
]],
["punctuation", "]"]
]]
]

----------------------------------------------------

Checks for tags.

0 comments on commit aaf13aa

Please sign in to comment.