forked from catc/react-timekeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode-loader.js
21 lines (19 loc) · 820 Bytes
/
code-loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const blockLoader = require('block-loader');
const options = {
start: '<pre><code className="javascript">',
end: '</code></pre>',
process: function fixPreBlocks(pre) {
const replaced = pre
.replace(options.start,'') // first, remove the start/end delimiters, then:
.replace(options.end,'') //
.replace(/&/g,'&') // 1. use html entity equivalent,
.replace(/</g,'<') // 2. use html entity equivalent,
.replace(/>/g,'>') // 3. use html entity equivalent,
.replace(/\t/g, ' ')
.replace(/([{}])/g,"{'$1'}") // 4. JSX-safify curly braces,
.replace(/\n/g,"{'\\n'}"); // 5. and preserve line endings, thanks.
// done! return with the delimiters put back in place
return options.start + replaced + options.end
}
};
module.exports = blockLoader(options)