Skip to content

Commit

Permalink
Revert "Revert "Add syntax highlighting to debug error page" (vercel#197
Browse files Browse the repository at this point in the history
)"

This reverts commit f4ae99f.
  • Loading branch information
nkzawa committed Nov 5, 2016
1 parent 0c27e3a commit ef409af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"parser": "babel-eslint"
},
"dependencies": {
"ansi-html": "0.0.6",
"babel-core": "6.17.0",
"babel-generator": "6.17.0",
"babel-loader": "6.2.5",
Expand Down
25 changes: 20 additions & 5 deletions pages/_error-debug.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import stripAnsi from 'strip-ansi'
import ansiHTML from 'ansi-html'
import Head from 'next/head'
import style from 'next/css'

Expand All @@ -16,20 +16,24 @@ export default class ErrorDebug extends React.Component {
<Head>
<style dangerouslySetInnerHTML={{ __html: `
body {
background: #dc0067;
background: #a6004c;
margin: 0;
}
`}} />
</Head>
<div className={styles.heading}>Error in {path}</div>
<pre className={styles.message}>{stripAnsi(message)}</pre>
<pre className={styles.message} dangerouslySetInnerHTML={{ __html: ansiHTML(encodeHtml(message)) }} />
</div>
}
}

const encodeHtml = str => {
return str.replace(/</g, '&lt;').replace(/>/g, '&gt;')
}

const styles = {
body: style({
background: '#dc0067',
background: '#a6004c',
margin: 0
}),

Expand All @@ -50,7 +54,18 @@ const styles = {
fontFamily: '-apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", "Fira Sans", Avenir, "Helvetica Neue", "Lucida Grande", sans-serif',
fontSize: '13px',
fontWeight: 'bold',
color: '#ff90c6',
color: '#ff84bf',
marginBottom: '20px'
})
}

ansiHTML.setColors({
reset: ['fff', 'a6004c'],
darkgrey: '5a012b',
yellow: 'ffab07',
green: 'aeefba',
magenta: 'ff84bf',
blue: '3505a0',
cyan: '56eaec',
red: '4e053a'
})

0 comments on commit ef409af

Please sign in to comment.