From 79af79646140d19d7afe9cd69b8f9548b03ce34a Mon Sep 17 00:00:00 2001 From: Daniel Flint Date: Mon, 24 Feb 2014 22:34:43 +0800 Subject: [PATCH] Plugin to show highlighted language, per Issue #1 --- components.js | 3 +- plugins/show-language/index.html | 56 +++++++++++++++++++ plugins/show-language/prism-show-language.css | 21 +++++++ plugins/show-language/prism-show-language.js | 16 ++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 plugins/show-language/index.html create mode 100644 plugins/show-language/prism-show-language.css create mode 100644 plugins/show-language/prism-show-language.js 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); +}); + +})();