This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add readme-syntax-highlighter package and use in ApiExplorer
- Loading branch information
Dom Harrington
committed
Aug 11, 2017
1 parent
f770940
commit b70a72a
Showing
18 changed files
with
4,254 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
[*js] | ||
charset = utf-8 | ||
indent_style = space | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "airbnb-base", | ||
"rules": { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"threshold": 30, | ||
"identifiers": true, | ||
"ignore": "test", | ||
"reporter": "default", | ||
"suppress": 100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
sudo: false | ||
node_js: | ||
- 6.0 | ||
- 8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright (c) 2017, Dom Harrington <dom@harrington-mail.com> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose | ||
with or without fee is hereby granted, provided that the above copyright notice | ||
and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# readme-syntax-highlighter | ||
|
||
Syntax highlighter used on ReadMe.io | ||
|
||
[![build status](https://secure.travis-ci.org/readme/readme-syntax-highlighter.svg)](http://travis-ci.org/readme/readme-syntax-highlighter) | ||
[![dependency status](https://david-dm.org/readme/readme-syntax-highlighter.svg)](https://david-dm.org/readme/readme-syntax-highlighter) | ||
|
||
## Installation | ||
|
||
``` | ||
npm install --save readme-syntax-highlighter | ||
``` | ||
|
||
## Usage | ||
|
||
## Credits | ||
[Dom Harrington](https://github.com/readme/) | ||
|
||
## License | ||
|
||
ISC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const CodeMirror = require('codemirror'); | ||
require('codemirror/addon/runmode/runmode'); | ||
require('codemirror/mode/meta.js'); | ||
|
||
require('codemirror/mode/shell/shell'); | ||
require('codemirror/mode/javascript/javascript'); | ||
require('codemirror/mode/ruby/ruby'); | ||
require('codemirror/mode/python/python'); | ||
|
||
function esc(str) { | ||
return str.replace(/[<&]/g, ch => (ch === '&' ? '&' : '<')); | ||
} | ||
|
||
module.exports = (code, lang) => { | ||
let output = ''; | ||
|
||
// if (!CodeMirror.modes[lang]) { | ||
// require(`codemirror/mode/${lang}/${lang}.js`); | ||
// } | ||
|
||
let curStyle = null; | ||
let accum = ''; | ||
function flush() { | ||
accum = esc(accum); | ||
if (curStyle) { | ||
output += `<span class="${curStyle.replace(/(^|\s+)/g, '$1cm-')}">${accum}</span>`; | ||
} else { | ||
output += accum; | ||
} | ||
} | ||
|
||
CodeMirror.runMode(code, lang, (text, style) => { | ||
if (style !== curStyle) { | ||
flush(); | ||
curStyle = style; | ||
accum = text; | ||
} else { | ||
accum += text; | ||
} | ||
}); | ||
flush(); | ||
|
||
return output; | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const codemirror = require('./codemirror'); | ||
|
||
function sanitizeCode(code) { | ||
const entityMap = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
"'": ''', | ||
'/': '/', | ||
}; | ||
|
||
return String(code).replace(/[&<>"'/]/g, s => entityMap[s]); | ||
} | ||
|
||
module.exports = (code, lang/* , dark */) => { | ||
if (lang === 'text') { | ||
return sanitizeCode(code); | ||
} | ||
|
||
const theme = 'cm-s-tomorrow-night'; | ||
// let theme = 'cm-s-neo'; | ||
// if (dark) { | ||
// theme = 'cm-s-tomorrow-night'; | ||
// } | ||
|
||
// const modes = { | ||
// html: 'htmlmixed', | ||
// json: ['javascript', 'application/ld+json'], | ||
// text: ['null', 'text/plain'], | ||
// markdown: 'gfm', | ||
// stylus: 'scss', | ||
// bash: 'shell', | ||
// mysql: 'sql', | ||
// sql: ['sql', 'text/x-sql'], | ||
// curl: 'shell', | ||
// asp: 'clike', | ||
// csharp: ['clike', 'text/x-csharp'], | ||
// cplusplus: ['clike', 'text/x-c++src'], | ||
// c: 'clike', | ||
// java: ['clike', 'text/x-java'], | ||
// scala: ['clike', 'text/x-scala'], | ||
// objectivec: ['clike', 'text/x-objectivec'], | ||
// liquid: 'htmlmixed', | ||
// scss: 'css', | ||
// }; | ||
|
||
// let mode = lang; | ||
|
||
// if (mode in modes) { | ||
// mode = modes[mode]; | ||
// lang = mode; | ||
// if (_.isArray(mode)) { | ||
// lang = mode[0]; | ||
// mode = mode[1]; | ||
// } | ||
// } | ||
|
||
// let highlighted = ; | ||
|
||
// // Kind of a hack, but no other way to sanitize angular code | ||
// // Can't use ng-non-bindable because of jwt variables | ||
// highlighted = highlighted.replace(/{{/g, '{<span></span>{'); | ||
// highlighted = highlighted.replace(/}}/g, '}<span></span>}'); | ||
|
||
return `<span class="${theme}">${codemirror(code, lang)}</span>`; | ||
}; |
Oops, something went wrong.