Skip to content

Commit 401c347

Browse files
committed
feat: add md
1 parent 530a1b7 commit 401c347

11 files changed

Lines changed: 349 additions & 51 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Asciidoc Codelab 🎉
1+
# Codelab Generator 🎉
22

3-
📦 This project give the possibility to generate a Google codelab with asciidoc files.
3+
📦 This project give the possibility to generate a Google codelab with asciidoc or markdown files.
44

55
You can use this module directly from the command line
66

77
```shell
8-
npx @dxdeveloperexperience/adoc-codelab ./index.adoc ./target
8+
npx @dxdeveloperexperience/codelab-generator ./index.adoc ./target
9+
10+
npx @dxdeveloperexperience/codelab-generator ./index.md ./target
911
```
1012

1113
## Contributors

package-lock.json

Lines changed: 211 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
2-
"name": "@dxdeveloperexperience/adoc-codelab",
3-
"version": "1.0.6",
2+
"name": "@dxdeveloperexperience/codelab-generator",
3+
"version": "1.0.7",
44
"description": "",
55
"main": "src/index.js",
66
"dependencies": {
77
"asciidoctor": "^2.0.3",
88
"jsdom": "^15.2.0",
9+
"markdown": "^0.5.0",
910
"mustache": "^3.1.0",
1011
"rimraf": "^3.0.0",
12+
"showdown": "^1.9.0",
1113
"simple-git": "^1.126.0"
1214
},
1315
"devDependencies": {

sample/index.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
= Codelab
2+
3+
== Step1
4+
5+
This is the first step of this codelab. You should do :
6+
7+
- Do that
8+
- Do this
9+
- And finish with this other thing
10+
11+
[source,javascript]
12+
----
13+
function test() {
14+
console.log("JavaScript Snippet");
15+
}
16+
----
17+
18+
Congrats. You finish the first step
19+
20+
== Step 2
21+
22+
This is the second step of this codelab.

sample/index.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Codelab
2+
3+
## Step1
4+
5+
This is the first step of this codelab. You should do :
6+
7+
- Do that
8+
- Do this
9+
- And finish with this other thing
10+
11+
```javascript
12+
function test() {
13+
console.log("JavaScript Snippet");
14+
}
15+
```
16+
17+
Congrats. You finish the first step
18+
19+
## Step 2
20+
21+
This is the second step of this codelab.

src/convert.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
module.exports = function(dom) {
2-
let steps = [];
1+
module.exports = function(input) {
2+
const fs = require("fs");
3+
const path = require("path");
4+
const Mustache = require("mustache");
35

4-
const sections = dom.window.document.querySelectorAll(".sect1");
6+
const template = fs.readFileSync(
7+
path.resolve(__dirname, "./template.html"),
8+
"utf8"
9+
);
510

6-
for (let i = 0; i < sections.length; i++) {
7-
const title = sections[i].querySelector("h2").innerHTML;
8-
const body = sections[i].querySelector(".sectionbody").innerHTML;
9-
steps.push(`
10-
<google-codelab-step label="${title}" duration="0">
11-
${body}
12-
</google-codelab-step>
13-
`);
14-
}
11+
const body = fs.readFileSync(input);
1512

16-
return {
17-
content: steps.join("\n"),
18-
title: dom.window.document.querySelector("h1").innerHTML
19-
};
13+
const convert = input.endsWith(".adoc")
14+
? require("./converter/adoc")
15+
: require("./converter/markdown");
16+
return Mustache.render(template, convert(body));
2017
};

src/convert.spec.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)