-
Notifications
You must be signed in to change notification settings - Fork 996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added syntax highlighting for markdown codes #716
Merged
Merged
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3031436
added syntax highlighting for markdown codes
mtxr 9be463f
Added highlight to markdown renderer
mtxr c21db1c
Markdown code change test
mtxr 9005551
Logging marked errors
mtxr 69568ad
Using sanitize
mtxr 057589e
highlight styles
mtxr 43d4725
Removed unsed consoles
mtxr 7e125d9
Using monokai as highlight theme
mtxr 57dc581
Using monokai for all markdown code, syntax highlight working on deta…
mtxr fff0d9b
Surounded with pre code tags
mtxr 51fad1e
Disable hljs and using rouge for builds
mtxr d57ea43
fied broken detail page
mtxr 0de3e19
Added minified highlight.js with common languages
mtxr abc9705
Fixed build script
mtxr 5225bba
Fixed build script to use yarn
mtxr d46f8d2
Using spreading
mtxr c1fa4b4
Fixed build script to use yarn
mtxr e1e4718
Removed submodule
mtxr 93f4e38
Using hightlight statically
mtxr 08e49b0
Using built highlight.js
mtxr 48bf36c
Static highlight.js
mtxr 8d244ae
removed unnecessary changes
mtxr 9693228
style(markdown): simplify css config
Haroenv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
[submodule "_sass/bootstrap"] | ||
path = _sass/bootstrap | ||
url = https://github.com/twbs/bootstrap.git | ||
|
||
[submodule "_js/highlight"] | ||
path = _js/highlight | ||
url = https://github.com/isagalaev/highlight.js.git |
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 |
---|---|---|
|
@@ -40,6 +40,7 @@ exclude: | |
- .sass-cache | ||
- node_modules | ||
- js/src | ||
- "_js" | ||
|
||
include: | ||
- _redirects | ||
|
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,76 @@ | ||
/* | ||
Monokai style - ported by Luigi Maselli - http://grigio.org | ||
*/ | ||
|
||
.hljs { | ||
background: #292b2c; | ||
-webkit-font-smoothing: antialiased; | ||
border-left: 4px solid #2C8EBB; | ||
color: #ddd; | ||
max-width: 100%; | ||
margin-bottom: 1.2rem; | ||
border-radius: 3px; | ||
padding: .6rem 1.2rem; | ||
overflow-x: auto; | ||
-webkit-overflow-scrolling: touch; | ||
} | ||
|
||
.hljs-tag, | ||
.hljs-keyword, | ||
.hljs-selector-tag, | ||
.hljs-literal, | ||
.hljs-strong, | ||
.hljs-name { | ||
color: #f92672; | ||
} | ||
|
||
.hljs-code { | ||
color: #66d9ef; | ||
} | ||
|
||
.hljs-class .hljs-title { | ||
color: white; | ||
} | ||
|
||
.hljs-attribute, | ||
.hljs-symbol, | ||
.hljs-regexp, | ||
.hljs-link { | ||
color: #bf79db; | ||
} | ||
|
||
.hljs-string, | ||
.hljs-bullet, | ||
.hljs-subst, | ||
.hljs-title, | ||
.hljs-section, | ||
.hljs-emphasis, | ||
.hljs-type, | ||
.hljs-built_in, | ||
.hljs-builtin-name, | ||
.hljs-selector-attr, | ||
.hljs-selector-pseudo, | ||
.hljs-addition, | ||
.hljs-variable, | ||
.hljs-template-tag, | ||
.hljs-template-variable { | ||
color: #a6e22e; | ||
} | ||
|
||
.hljs-comment, | ||
.hljs-quote, | ||
.hljs-deletion, | ||
.hljs-meta { | ||
color: #75715e; | ||
} | ||
|
||
.hljs-keyword, | ||
.hljs-selector-tag, | ||
.hljs-literal, | ||
.hljs-doctag, | ||
.hljs-title, | ||
.hljs-section, | ||
.hljs-type, | ||
.hljs-selector-id { | ||
font-weight: bold; | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import React from 'react'; | ||
import marked from 'marked'; | ||
import xss from 'xss'; | ||
import hljs from '../../../../_js/highlight/build/highlight.pack'; | ||
|
||
import { prefixURL } from '../util'; | ||
|
||
|
@@ -69,9 +70,28 @@ const renderAndEscapeMarkdown = ({ source, githubRepo }) => { | |
}; | ||
} | ||
|
||
const html = marked(source, { renderer, mangle: false }); | ||
const escaped = xss(html); | ||
return escaped; | ||
renderer.code = function(code, lang) { | ||
if (lang && hljs.getLanguage(lang)) { | ||
try { | ||
const prepared = hljs.highlight(lang, code); | ||
return `<pre><code class="${prepared.language}">${prepared.value}</code></pre>`; | ||
} catch (err) {} | ||
} | ||
|
||
try { | ||
const prepared = hljs.highlightAuto(code); | ||
return `<pre><code class="${prepared.language}">${prepared.value}</code></pre>`; | ||
} catch (err) {} | ||
|
||
return `<pre><code>${code}</code></pre>`; | ||
}; | ||
|
||
return xss(marked(source, { renderer, mangle: false }), { | ||
whiteList: Object.assign({}, xss.getDefaultWhiteList(), { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use spreading here if you want, it's supported by our babel config 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! just changed. |
||
code: ['class'], | ||
span: ['class'], | ||
}), | ||
}); | ||
}; | ||
|
||
const Markdown = ({ source, githubRepo }) => ( | ||
|
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,10 @@ | ||
#!/bin/bash | ||
|
||
ROOT_PATH=$(python -c "import os,sys;print(os.path.dirname(os.path.realpath(sys.argv[1])))" $0) | ||
ROOT_PATH=$(dirname $ROOT_PATH) | ||
npm --prefix $ROOT_PATH/_js/highlight install | ||
OLD_CWD=$(pwd) | ||
cd $ROOT_PATH/_js/highlight | ||
rm -rf build/ &> /dev/null | ||
node tools/build.js css javascript markdown bash shell xml typescript scss | ||
cd $OLD_CWD |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably simpler if we just include this file, WDYT @Daniel15 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to split the code later, but I didn't understand really why to do that