diff --git a/components.js b/components.js index db764b61d6..c503422eb0 100644 --- a/components.js +++ b/components.js @@ -122,6 +122,7 @@ var components = { 'file-highlight': { title: 'File Highlight', noCSS: true - } + }, + 'show-language': 'Show Language' } }; diff --git a/plugins/show-language/index.html b/plugins/show-language/index.html new file mode 100644 index 0000000000..aa790af970 --- /dev/null +++ b/plugins/show-language/index.html @@ -0,0 +1,56 @@ + + + + + + +Show Language ▲ Prism plugins + + + + + + + + + + + +
+
+ +

Show Language

+

Display the highlighted language in code blocks (inline code does not show the label).

+
+ +
+

Examples

+ +

JavaScript

+

+
+	

CSS

+

+
+	

HTML (Markup)

+

+
+ +
+

Known Issues

+ + +
+ + + + + + + + + + + \ No newline at end of file diff --git a/plugins/show-language/prism-show-language.css b/plugins/show-language/prism-show-language.css new file mode 100644 index 0000000000..5561baeb7b --- /dev/null +++ b/plugins/show-language/prism-show-language.css @@ -0,0 +1,21 @@ +pre[class*='language-'] { + position: relative; +} +pre[class*='language-'] > code[data-language] { + overflow: scroll; + max-height: 28em; + display: block; +} +pre[class*='language-'] > code[data-language]::before { + content: attr(data-language); + color: black; + background-color: #CFCFCF; + display: inline-block; + position: absolute; + top: 0; + right: 0; + font-size: 0.9em; + border-radius: 0 0 0 5px; + padding: 0 0.5em; + text-shadow: none; +} \ No newline at end of file diff --git a/plugins/show-language/prism-show-language.js b/plugins/show-language/prism-show-language.js new file mode 100644 index 0000000000..7ca2f231a9 --- /dev/null +++ b/plugins/show-language/prism-show-language.js @@ -0,0 +1,16 @@ +(function(){ + +if (!self.Prism) { + return; +} + +var Languages = { + 'csharp': 'C#', + 'cpp': 'C++' +}; +Prism.hooks.add('before-highlight', function(env) { + var language = Languages[env.language] || env.language; + env.element.setAttribute('data-language', language); +}); + +})();