Skip to content

Commit e5b40c1

Browse files
committedMay 21, 2018
Add markt
1 parent 79461d0 commit e5b40c1

12 files changed

+262
-2
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
| --- | ---
77
| [`@(._.)/assign`](https://www.npmjs.com/package/@(._.)/assign) | [Deep assign](./packages/assign/README.md)
88
| [`boxt`](https://www.npmjs.com/package/boxt) | [Create boxes around text](./packages/boxt/README.md)
9+
| [`markt`](https://www.npmjs.com/package/markt) | [Generate pages from markdown](./packages/markt/README.md)
910
| [`paraphrase`](https://www.npmjs.com/package/paraphrase) | [Create flavoured string phraser](./packages/paraphrase/README.md)

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "git+https://github.com/omrilotan/mono.git"
1111
},
1212
"scripts": {
13-
"test": "mocha spec.js **/spec.js --full-trace",
13+
"test": "find . | grep spec.js | grep -v node_modules | xargs mocha --full-trace",
1414
"lint": "eslint -c .eslintrc *.js **/*.js --quiet",
1515
"postinstall": "./scripts/foreach.sh \"npm i\"",
1616
"prepublish-packages": "npm t; npm run lint",

‎packages/markt/.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.*
2+
*.log
3+
test.js
4+
docs

‎packages/markt/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

‎packages/markt/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# markt [![](https://nodei.co/npm/markt.png?compact=true)](https://www.npmjs.com/package/markt) [![](https://user-images.githubusercontent.com/516342/38551453-17b7e8ca-3cb1-11e8-9754-b70c6e0f316c.png)](https://github.com/omrilotan/markt)
2+
3+
Generate pages from markdown
4+
5+
## CI-CD use
6+
7+
```sh
8+
npx markt README.md ./docs/index.html ./scripts/docs.template.html
9+
```
10+
11+
#### arguments
12+
13+
| Order | Role | Default
14+
| --- | --- | ---
15+
| 1 | Source | `./README.md`
16+
| 2 | Destination | `./index.html`
17+
| 3 | Template | None
18+
19+
## Template is optional
20+
21+
```html
22+
<!DOCTYPE html>
23+
<html>
24+
<head>
25+
<meta charset="utf-8">
26+
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
27+
<title>My document</title>
28+
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
29+
<link rel="stylesheet" href="https://omrilotan.github.io/markt/styles.css">
30+
</head>
31+
<body>
32+
{{ content }}
33+
</body>
34+
</html>
35+
```
36+
37+
---
38+
39+
from the desk of [omrilotan <img style="height:32px; vertical-align:middle;" src="https://user-images.githubusercontent.com/516342/37675827-f3016264-2c7e-11e8-9806-46341bec1d6c.png">](https://omrilotan.com)

‎packages/markt/bin/markt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
3+
const args = process.argv;
4+
args.splice(0, 2);
5+
6+
const [
7+
source = 'README.md',
8+
destination = 'index.html',
9+
template = null,
10+
] = args;
11+
12+
const {promisify} = require('util');
13+
const fse = require('fs-extra');
14+
const read = promisify(require('fs').readFile);
15+
const markt = require('../');
16+
17+
(async() => {
18+
try {
19+
const args = [
20+
await read(source),
21+
];
22+
template && args.push(await read(template));
23+
24+
const output = await markt(
25+
...args.map(arg => arg.toString())
26+
);
27+
28+
await fse.outputFile(destination, output);
29+
30+
console.info(`written in ${process.cwd()}/${destination}`);
31+
} catch (error) {
32+
console.error(error);
33+
}
34+
35+
})();

‎packages/markt/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const {promisify} = require('util');
2+
const marked = promisify(require('marked'));
3+
4+
module.exports = async function(markdown, template = '{{content}}') {
5+
const content = await marked(markdown, {});
6+
7+
return template.replace(/{{(\s*?)content(\s*?)}}/i, content.trim());
8+
}

‎packages/markt/package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "markt",
3+
"version": "1.0.1",
4+
"description": "Generate pages from markdown",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+ssh://git@github.com/omrilotan/markt.git"
8+
},
9+
"homepage": "https://omrilotan.github.io/markt",
10+
"author": "omri",
11+
"license": "MIT",
12+
"bin": {
13+
"markt": "./bin/markt"
14+
},
15+
"main": "index.js",
16+
"scripts": {
17+
"start": "mkdir -p docs; npm run html; npm run css",
18+
"html": "./bin/markt README.md ./docs/index.html ./src/docs.template.html",
19+
"css": "cat ./src/styles.scss | node-sass --output-style compressed > ./docs/styles.css",
20+
"test": "mocha test.js",
21+
"prepublishOnly": "npm t"
22+
},
23+
"publishConfig": {
24+
"tag": "latest",
25+
"tag-version-prefix": ""
26+
},
27+
"preferGlobal": true,
28+
"dependencies": {
29+
"fs-extra": "^5.0.0",
30+
"marked": "^0.3.19"
31+
},
32+
"devDependencies": {
33+
"node-sass": "^4.8.3"
34+
}
35+
}

‎packages/markt/spec.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const markt = require('./');
2+
const assert = require('assert');
3+
4+
describe('markt', async () => {
5+
it('without a template, converts to markdown', async () => {
6+
const res = await markt('*Hello*');
7+
8+
assert.strictEqual(
9+
res,
10+
'<p><em>Hello</em></p>'
11+
);
12+
});
13+
14+
it('fills pattern in template', async () => {
15+
const res = await markt('*Hello*', '{{content}}');
16+
17+
assert(
18+
res.includes('<p><em>Hello</em></p>')
19+
);
20+
});
21+
22+
it('pattern is a bit loose', async () => {
23+
[
24+
'{{ content }}',
25+
'{{Content }}',
26+
'{{ CONTENT }}',
27+
].forEach(async template => {
28+
const res = await markt('*Hello*', template);
29+
30+
assert.strictEqual(
31+
res,
32+
'<p><em>Hello</em></p>'
33+
);
34+
})
35+
});
36+
37+
it('fills just first pattern in template', async () => {
38+
const res = await markt('*Hello*', '{{content}} {{content}}');
39+
40+
assert(res.includes('{{content}}'));
41+
assert(res.includes('<p><em>Hello</em></p>'));
42+
});
43+
});

‎packages/markt/src/docs.template.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
6+
<title>markt</title>
7+
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
8+
<link rel="stylesheet" href="styles.css">
9+
</head>
10+
<body>
11+
{{ content }}
12+
</body>
13+
</html>

‎packages/markt/src/styles.scss

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
$text-color: #000;
2+
$background-alt: #f6f8fa;
3+
$borders: #dfe2e5;
4+
5+
* { margin: 0; padding: 0; }
6+
7+
body {
8+
color: $text-color;
9+
font: 100 100%/1.4 -apple-system, "BlinkMacSystemFont", "Helvetica Neue", "Helvetica", "Lucida Grande", "Arial", sans-serif;
10+
max-width: 900px;
11+
padding: 2em;
12+
margin: 0 auto;
13+
}
14+
15+
h1 {
16+
font-size: 4em;
17+
margin: 0 0 .5em;
18+
19+
figure {
20+
width: 1.25em;
21+
height: 1.25em;
22+
display: inline-block;
23+
vertical-align: text-top;
24+
}
25+
}
26+
27+
h2, h3, h4, th {
28+
font-weight: 100;
29+
}
30+
31+
h2 { font-size: 2em; }
32+
h3 { font-size: 1.6em; }
33+
h4 { font-size: 1.2em; }
34+
h2, h3, h4 { margin: 0 0 .25em; }
35+
36+
p, pre, ul, table, blockquote { margin: 0 0 1em; }
37+
38+
a {
39+
color: #2980b9;
40+
&:visited { color: #8e44ad; }
41+
&:active { color: #27ae60; }
42+
}
43+
44+
table {
45+
border-collapse: collapse;
46+
}
47+
48+
table, th, td {
49+
border: 1px solid $borders;
50+
}
51+
52+
th, td, pre, code {
53+
padding: .2em .5em;
54+
}
55+
56+
pre > code {
57+
padding: 0;
58+
}
59+
60+
pre, code {
61+
color: #454545;
62+
}
63+
64+
tbody tr:nth-child(odd),
65+
pre, code {
66+
background: $background-alt;
67+
}
68+
69+
blockquote {
70+
padding-left: .5em;
71+
border-left: 4px solid $background-alt;
72+
}
73+
74+
img, pre, code, table {
75+
max-width: 100%;
76+
overflow-x: auto;
77+
}
78+
79+
@media only screen and (max-width: 768px) {
80+
body { padding: 1em; }
81+
}

‎scripts/foreach.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function search {
1212
}
1313

1414
function execute {
15-
echo -e '\033[1mExecuting ${1}\033[0m\n'
15+
echo -e "\033[1mExecuting ${1}\033[0m\n"
1616
cd $1
1717
eval $ACTION
1818
cd -

0 commit comments

Comments
 (0)
Please sign in to comment.