Last active
December 5, 2017 19:08
-
-
Save mhkeller/05d6fb19071feab5b3dbff488a8ecc8e to your computer and use it in GitHub Desktop.
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
var fs = require('fs') | |
var codeBlockOne = fs.readFileSync('code-block-1.txt', 'utf-8') | |
var codeBlockTwo = fs.readFileSync('code-block-2.txt', 'utf-8') | |
var blocks = [codeBlockOne, codeBlockTwo] | |
blocks.forEach((block, i) => { | |
fs.writeFileSync('highlighted-block-' + i + '.txt', highlight(block)) | |
}) | |
function highlight (block) { | |
return block | |
.replace(/class="at"/g, 'style="color: #005cc5;"') | |
.replace(/class="co"/g, 'style="color: #6a737d;"') | |
.replace(/class="kw"/g, 'style="color: #d73a49;"') | |
.replace(/class="st"/g, 'style="color: #22863a;"') | |
.replace(/ class="op"/g, '') | |
.replace(/ class="va"/g, '') | |
.replace(/ class="dt"/g, '') | |
.replace(/ class="sourceCode js"/g, '') | |
.replace(/ class="sourceCode javascript"/g, '') | |
} |
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
<pre><code><span style="color: #6a737d;">// onChange.js</span> | |
<span style="color: #d73a49;">var</span> notify <span>=</span> <span style="color: #005cc5;">require</span>(<span style="color: #22863a;">'wsk'</span>).<span style="color: #005cc5;">notify</span><span>;</span> | |
<span>module</span>.<span style="color: #005cc5;">exports</span> <span>=</span> <span style="color: #d73a49;">function</span> (eventType<span>,</span> filePath<span>,</span> options) <span>{</span> | |
<span style="color: #6a737d;">// Put library transform here</span> | |
<span style="color: #6a737d;">// Write the transformed file with `fs.writeFile`, for example</span> | |
<span style="color: #6a737d;">// Notify user the file was written</span> | |
<span style="color: #005cc5;">notify</span>(<span>{</span> | |
<span>message</span><span>:</span> <span style="color: #22863a;">'Compiled CSS file...'</span> <span>,</span> | |
<span>value</span><span>:</span> <span>filePath</span>.<span style="color: #005cc5;">replace</span>(<span style="color: #22863a;">'src'</span><span>,</span> <span style="color: #22863a;">'public'</span>)<span>,</span> | |
<span>display</span><span>:</span> <span style="color: #22863a;">'compile'</span> | |
<span>}</span>)<span>;</span> | |
<span>};</span></code></pre> |
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
<pre><code><span style="color: #6a737d;">// sass-watch.js</span> | |
<span style="color: #d73a49;">var</span> watcher <span>=</span> <span style="color: #005cc5;">require</span>(<span style="color: #22863a;">'wsk'</span>).<span style="color: #005cc5;">watcher</span><span>;</span> | |
<span style="color: #d73a49;">var</span> watchGroup <span>=</span> <span>{</span> | |
<span>serviceName</span><span>:</span> <span style="color: #22863a;">'sass'</span><span>,</span> | |
<span>path</span><span>:</span> <span style="color: #22863a;">'src/css/*.scss'</span><span>,</span> | |
<span>events</span><span>:</span> [ | |
<span>{</span> | |
<span>type</span><span>:</span> <span style="color: #22863a;">'change'</span><span>,</span> | |
<span>taskFiles</span><span>:</span> <span style="color: #22863a;">'build/tasks/sass/onChange.js'</span><span>,</span> | |
<span>options</span><span>:</span> <span>{</span> | |
<span>foo</span><span>:</span> <span style="color: #d73a49;">true</span> | |
<span>}</span> | |
<span>},</span> | |
<span>{</span> | |
<span>type</span><span>:</span> <span style="color: #22863a;">'change'</span><span>,</span> | |
<span>taskFiles</span><span>:</span> <span style="color: #22863a;">'build/tasks/sass/onAdd.js'</span> | |
<span>},</span> | |
<span>{</span> | |
<span>type</span><span>:</span> <span style="color: #22863a;">'unlink'</span><span>,</span> | |
<span>taskFiles</span><span>:</span> <span style="color: #22863a;">'build/tasks/sass/onUnlink.js'</span> | |
<span>}</span> | |
] | |
<span>};</span> | |
<span>watcher</span>.<span style="color: #005cc5;">add</span>(watchGroup)<span>;</span></code></pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment