Browse Source

Worked on getting code highlighting for markdown working

pull/4/head
jrtechs 7 years ago
parent
commit
66bb63b5a5
10 changed files with 198 additions and 10 deletions
  1. +2
    -0
      README.md
  2. +129
    -0
      css/code.css
  3. +29
    -2
      entries/testing-my-server.md
  4. +2
    -0
      includes/footer.html
  5. +6
    -0
      includes/header.html
  6. +13
    -0
      includes/includes.js
  7. +12
    -3
      posts/singlePost.js
  8. +4
    -0
      server.js
  9. +0
    -4
      utils/sql.js
  10. +1
    -1
      utils/utils.js

+ 2
- 0
README.md View File

@ -52,4 +52,6 @@ npm install mysql
npm install sanitizer
npm install promise
npm install markdown
npm install markdown-to-html -g
npm install highlight
```

+ 129
- 0
css/code.css View File

@ -0,0 +1,129 @@
/*
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
*/
pre code {
display: block; padding: 0.5em;
color: #000;
background: #f8f8ff
}
pre .comment,
pre .template_comment,
pre .diff .header,
pre .javadoc {
color: #998;
font-style: italic
}
pre .keyword,
pre .css .rule .keyword,
pre .winutils,
pre .javascript .title,
pre .lisp .title,
pre .subst {
color: #000;
font-weight: bold
}
pre .number,
pre .hexcolor {
color: #40a070
}
pre .string,
pre .tag .value,
pre .phpdoc,
pre .tex .formula {
color: #d14
}
pre .title,
pre .id {
color: #900;
font-weight: bold
}
pre .javascript .title,
pre .lisp .title,
pre .subst {
font-weight: normal
}
pre .class .title,
pre .haskell .label,
pre .tex .command {
color: #458;
font-weight: bold
}
pre .tag,
pre .tag .title,
pre .rules .property,
pre .django .tag .keyword {
color: #000080;
font-weight: normal
}
pre .attribute,
pre .variable,
pre .instancevar,
pre .lisp .body {
color: #008080
}
pre .regexp {
color: #009926
}
pre .class {
color: #458;
font-weight: bold
}
pre .symbol,
pre .ruby .symbol .string,
pre .ruby .symbol .keyword,
pre .ruby .symbol .keymethods,
pre .lisp .keyword,
pre .tex .special,
pre .input_number {
color: #990073
}
pre .builtin,
pre .built_in,
pre .lisp .title {
color: #0086b3
}
pre .preprocessor,
pre .pi,
pre .doctype,
pre .shebang,
pre .cdata {
color: #999;
font-weight: bold
}
pre .deletion {
background: #fdd
}
pre .addition {
background: #dfd
}
pre .diff .change {
background: #0086b3
}
pre .chunk {
color: #aaa
}
pre .tex .formula {
opacity: 0.5;
}

+ 29
- 2
entries/testing-my-server.md View File

@ -2,7 +2,34 @@
This page is merely for testing -- go away
```
include <stdio.h>
void main(int argc, char * argv[])
{
int vals[1000];
```javascript
var i = 1;
//value will overflow a 32 bit int!!!
long int max = 0;
char * data = argv[1];
for(int i = 0; i < 1000; i++)
{
vals[i] = (int)data[i] - 48;
}
for(int i = 0; i < 1000 - 13; i ++)
{
long int tempMax = 1;
for(int t = i; t < i + 13; t++)
{
tempMax *= vals[t];
}
if(tempMax > max)
{
max = tempMax;
}
}
printf("the max number is %ld", max);
}
```

+ 2
- 0
includes/footer.html View File

@ -19,6 +19,8 @@
</div>
<div class="w3-center">Copyright &copy; Jrtechs.net 2018</div>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad(); console.log("yikes");</script>
</body>

+ 6
- 0
includes/header.html View File

@ -13,6 +13,12 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="stylesheet"
href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.12.0/build/styles/default.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<style>
body,h1,h2,h3,h4,h5 {font-family: "Raleway", sans-serif}

+ 13
- 0
includes/includes.js View File

@ -41,5 +41,18 @@ module.exports =
})
})
},
/**Sends a css file to the user
*
* @param result
* @param path
* @return {*}
*/
sendCSS: function(result, path)
{
result.writeHead(200, {'Content-Type': 'text/css'});
utils.include(result, "./" + path);
result.end();
}
};

+ 12
- 3
posts/singlePost.js View File

@ -4,6 +4,10 @@ var Promise = require('promise');
var markdown = require( "markdown" ).markdown;
var Markdown = require('markdown-to-html').Markdown;
var md = new Markdown();
module.exports=
{
/**
@ -23,7 +27,7 @@ module.exports=
//title
res.write("<h3><b>" + post.name + "</b></h3>");
//date
res.write("<h5><span class=\"w3-opacity\">" + post.date + "</span></h5>");
res.write("<h5><span class=\"w3-opacity\">" + post.published.toDateString() + "</span></h5>");
res.write("</div>");
res.write("<div class=\"w3-container\">");
@ -31,11 +35,16 @@ module.exports=
var pathName = "entries/" + post.url + ".md";
try
{
res.write(markdown.toHTML(utils.getFileContents(pathName)));
var html = markdown.toHTML(utils.getFileContents(pathName).toString());
html = html.split("<code>").join("<pre><code>");
html = html.split("</code>").join("</code></pre>");
res.write(html);
console.log(html);
}
catch(ex)
{
console.log(ex);
//console.log(ex);
//utils.include(res, "includes/404.html");
}

+ 4
- 0
server.js View File

@ -21,6 +21,10 @@ http.createServer(function (request, res)
{
require("./img/image.js").main(res, filename);
}
else if(filename.includes("/css/"))
{
includes.sendCSS(res, filename)
}
else
{
var file = "";

+ 0
- 4
utils/sql.js View File

@ -24,17 +24,14 @@ con.connect(function(err) {
*/
var fetch = function(sqlStatement)
{
console.log("sql fetch method called with + " + sqlStatement);
return new Promise(function(resolve, reject)
{
con.query(sqlStatement, function (err, result)
{
if (err)
{
console.log(err);
reject();
}
console.log(result);
resolve(result);
});
});
@ -61,7 +58,6 @@ module.exports=
console.log(err);
resolve(0);
}
console.log(sqlStatement);
resolve(result.insertId);
});
})

+ 1
- 1
utils/utils.js View File

@ -36,7 +36,7 @@ module.exports=
{
try
{
return write(fs.readFileSync(fileName));
return fs.readFileSync(fileName);
}
catch (e)
{

Loading…
Cancel
Save