From f300ed0ca5289ff2cbb9679beb3d1de79dacbb95 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Sat, 11 Oct 2014 01:15:28 +0400 Subject: [PATCH] Updated demo styles and docs --- README.md | 37 ++++++++++++++++++++++++++++++++++++- demo/assets/index.css | 9 +++++++-- demo/assets/index.js | 5 +++-- demo/assets/index.styl | 8 ++++++-- demo/index.html | 19 ++++++++++++++++--- demo/sample.js | 19 ++++++++++++++++--- 6 files changed, 84 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 158ec32..3e740b4 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ bower install remarkable --save ```javascript var Remarkable = require('remarkable'); +// This values are default var md = new Remarkable({ html: false, // Enable html tags in source xhtmlOut: false, // Use '/' to close single tags (
) @@ -79,6 +80,32 @@ var Remarkable = require('remarkable'); var md = new Remarkable('commonmark'); ``` +### Highligh fenced blocks + +To highlight content of fenced block, assing function to `highlight` option: + +```javascript +var Remarkable = require('remarkable'); +var hljs = require('highlight.js') // https://highlightjs.org/ + +// This values are default +var md = new Remarkable({ + highlight: function (str, lang) { + if (lang && hljs.getLanguage(lang)) { + try { + return hljs.highlight(lang, str).value; + } catch (__) {} + } + + try { + return hljs.highlightAuto(str).value; + } catch (__) {} + + return ''; // use external default escaping + } +}); +``` + ### Typorgapher Though full weigh typograpic replacements are language specific, `remarkable` @@ -88,6 +115,7 @@ provides the most common and universal case coverage: var Remarkable = require('remarkable'); var md = new Remarkable({ typographer: true }); +// This values are default md.typographer.set({ singleQuotes: '‘’', doubleQuotes: '“”', // «» - russian, „“ - deutch @@ -96,12 +124,19 @@ md.typographer.set({ registered: true, // (r) (R) → ® plusminus: true, // +- → ± paragraph: true, // (p) (P) -> § - ellipsis: true, // ... → … + ellipsis: true, // ... → … (also ?.... → ?.., !.... → !..) dupes: true, // ???????? → ???, !!!!! → !!!, `,,` → `,` emDashes: true // -- → — }) ``` +### More extras + +This extentions are anabled by default + +- [Strike out](https://help.github.com/articles/github-flavored-markdown/#strikethrough) +- [tables](https://help.github.com/articles/github-flavored-markdown/#tables) + ## References / Thanks diff --git a/demo/assets/index.css b/demo/assets/index.css index 1aabf88..9037195 100644 --- a/demo/assets/index.css +++ b/demo/assets/index.css @@ -44,7 +44,6 @@ body { position: absolute; right: 15px; top: 0; - padding: 0 10px; border-radius: 0 4px; font-size: 12px; background-color: #666; @@ -57,9 +56,15 @@ body { opacity: 1; } .demo-control a { - margin: 0 20px; + padding: 0 20px; color: #fff !important; } +.demo-control a:first-child { + padding-left: 30px; +} +.demo-control a:last-child { + padding-right: 30px; +} .hljs { background: none; padding: 0; diff --git a/demo/assets/index.js b/demo/assets/index.js index b379282..b9c9dc3 100644 --- a/demo/assets/index.js +++ b/demo/assets/index.js @@ -23,12 +23,13 @@ var hljs = window.hljs; if (lang && hljs.getLanguage(lang)) { try { - //console.log(lang, hljs.highlight(lang, str)); return hljs.highlight(lang, str).value; } catch (__) {} } - try { return hljs.highlightAuto(str).value; } catch (__) {} + try { + return hljs.highlightAuto(str).value; + } catch (__) {} return ''; }; diff --git a/demo/assets/index.styl b/demo/assets/index.styl index 115d659..60cf215 100644 --- a/demo/assets/index.styl +++ b/demo/assets/index.styl @@ -42,7 +42,7 @@ body position absolute right 15px top 0 - padding 0 10px + //padding 0 10px border-radius 0 4px font-size 12px background-color #666 @@ -52,8 +52,12 @@ body &:hover opacity 1 a - margin 0 20px + padding 0 20px color #fff !important + a:first-child + padding-left 30px + a:last-child + padding-right 30px .hljs background none diff --git a/demo/index.html b/demo/index.html index 39fbfc7..da9b97c 100644 --- a/demo/index.html +++ b/demo/index.html @@ -17,18 +17,31 @@

Remarkable demo

code sample

var Remarkable = require('remarkable');
+var hljs       = require('highlight.js') // https://highlightjs.org/
 
 var md = new Remarkable({
   html:         false,        // Enable html tags in source
   xhtmlOut:     false,        // Use '/' to close single tags (<br />)
   breaks:       false,        // Convert '\n' in paragraphs into <br>
   langPrefix:   'language-',  // CSS language prefix for fenced blocks
-  linkify:      false,        // autoconvert url-like texts to links
-  typographer:  false,        // Enable smartypants and other sweet transforms
+  linkify:      true,         // autoconvert url-like texts to links
+  typographer:  true,         // Enable smartypants and other sweet transforms
 
   // Highlighter function. Should return escaped html,
   // or '' if input not changed
-  highlight: function (/*str, , lang*/) { return ''; }
+  highlight: function (/*str, lang*/) {
+    if (lang && hljs.getLanguage(lang)) {
+      try {
+        return hljs.highlight(lang, str).value;
+      } catch (__) {}
+    }
+
+    try {
+      return hljs.highlightAuto(str).value;
+    } catch (__) {}
+
+    return ''; // use external default escaping
+  }
 });
 
 console.log(md.parse('# Remarkable rulezz!'));
diff --git a/demo/sample.js b/demo/sample.js
index 7d6470e..ae75b64 100644
--- a/demo/sample.js
+++ b/demo/sample.js
@@ -1,16 +1,29 @@
 var Remarkable = require('remarkable');
+var hljs       = require('highlight.js') // https://highlightjs.org/
 
 var md = new Remarkable({
   html:         false,        // Enable html tags in source
   xhtmlOut:     false,        // Use '/' to close single tags (
) breaks: false, // Convert '\n' in paragraphs into
langPrefix: 'language-', // CSS language prefix for fenced blocks - linkify: false, // autoconvert url-like texts to links - typographer: false, // Enable smartypants and other sweet transforms + linkify: true, // autoconvert url-like texts to links + typographer: true, // Enable smartypants and other sweet transforms // Highlighter function. Should return escaped html, // or '' if input not changed - highlight: function (/*str, , lang*/) { return ''; } + highlight: function (str, lang) { + if (lang && hljs.getLanguage(lang)) { + try { + return hljs.highlight(lang, str).value; + } catch (__) {} + } + + try { + return hljs.highlightAuto(str).value; + } catch (__) {} + + return ''; // use external default escaping + } }); console.log(md.parse('# Remarkable rulezz!'));