Skip to content

Commit 6a5fde9

Browse files
Merge pull request #331 from denise-khuu/feature/tutorialTags
feature/tutorialTags
2 parents 83ce1c0 + 4ad5e0c commit 6a5fde9

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

documentation/Tutorials.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Every tutorial has three main parts
99
* at least one step
1010
Additionally, there are optional parts
1111
* a subtitle
12+
* tags
1213
* a conclusion of the tutorial. This will be shown at the last page and can be used to summarize the learned, to foreshadow the next steps on the learning path or to mention useful sources.
1314

1415
The tutorials are written in asciidoc files.
@@ -100,6 +101,16 @@ To display images within a step, you can use either the [displayContent](https:/
100101
```
101102
The image must be in a folder called `images` in the folder of the playbook (see [Structure](https://github.com/devonfw-tutorials/tutorial-compiler/wiki/Structure)).
102103

104+
There is the option to add tags to your tutorials. To do that, you have to add the following syntax after the title or if you have specified a subtitle, after the subtitle.
105+
106+
````
107+
[tags]
108+
--
109+
tagType=tag0;tag1
110+
tagType=tag0;tag1;tag2
111+
--
112+
```
113+
103114
You can also add an optional conclusion text, which is shown on completion of the tutorial. Use this to summarize the important content of the tutorial, to point out what to learn next or to mention other useful informations.
104115
105116
To do that, you have to provide the conclusion at the end of the tutorial (after the last step) surrounded by ```====```.
@@ -116,6 +127,11 @@ These blocks are combined to a complete tutorial.
116127
```
117128
= Title
118129
== Subtitle
130+
[tags]
131+
--
132+
tagType=tag0;tag1
133+
tagType=tag0;tag1;tag2
134+
--
119135
====
120136
Description of the tutorial
121137
====

engine/parser.def

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
start
22
= headline
33
subtitle?
4+
tags?
45
description
56
steps
67
conclusion?
7-
8+
89
headline "headline starting with ="
910
= "=" _ string ___
1011

@@ -83,6 +84,18 @@ conclusionlines
8384
conclusionline
8485
= !blockmarker string __
8586

87+
tags
88+
= "[tags]" ___
89+
"--" ___
90+
taglines
91+
"--" __
92+
93+
taglines
94+
= tagline+ { return { "taglines": text()}; }
95+
96+
tagline
97+
= !"--" string __
98+
8699
string "string"
87100
= [^\r\n]+ { return text(); }
88101

engine/parser.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ export class Parser {
2020
let result = new Playbook();
2121
result.title = parseResult[0][2];
2222
result.subtitle = parseResult[1]? parseResult[1][3]: "";
23-
result.description = this.insertNewlineIntoDescription(parseResult[2][2].descriptionlines);
24-
result.conclusion = this.insertNewlineIntoDescription(parseResult[4]? parseResult[4][2].conclusionlines: "");
25-
for(let index in parseResult[3]){
23+
result.tags = this.getTags(parseResult);
24+
result.description = this.insertNewlineIntoDescription(parseResult[3][2].descriptionlines);
25+
result.conclusion = this.insertNewlineIntoDescription(parseResult[5]? parseResult[5][2].conclusionlines: "");
26+
for(let index in parseResult[4]){
2627
let step = new Step();
2728
step.text = this.getText(parseResult, index);
2829
step.lines = this.getLines(parseResult, index);
@@ -35,26 +36,26 @@ export class Parser {
3536

3637
getText(parseResult, index){
3738
try {
38-
return parseResult[3][index][1].steptextlines || parseResult[3][index][2][1].steptextlines;
39+
return parseResult[4][index][1].steptextlines || parseResult[4][index][2][1].steptextlines;
3940
} catch (error) {
40-
return parseResult[3][index][2][1].steptextlines;
41+
return parseResult[4][index][2][1].steptextlines;
4142
}
4243
}
4344

4445
getLines(parseResult, index):Command[]{
4546
let linebreak = process.platform=="win32" ? "\r\n" : "\n";
4647
try {
47-
return (parseResult[3][index][7].steplines || parseResult[3][index][2][7].steplines).split(linebreak).filter(e => e.trim() != '').map(e => this.createCommand(e));
48+
return (parseResult[4][index][7].steplines || parseResult[4][index][2][7].steplines).split(linebreak).filter(e => e.trim() != '').map(e => this.createCommand(e));
4849
} catch (error) {
49-
return parseResult[3][index][2][7].steplines.split(linebreak).filter(e => e.trim() != '').map(e => this.createCommand(e));
50+
return parseResult[4][index][2][7].steplines.split(linebreak).filter(e => e.trim() != '').map(e => this.createCommand(e));
5051
}
5152
}
5253

5354
getTitle(parseResult, index) {
5455
try {
5556
// parseResult[3][index][4][2] step without block
5657
// parseResult[3][index][2][4][2] step inside a block
57-
return (parseResult[3][index][4][2].steptitle || parseResult[3][index][2][4][2].steptitle);
58+
return (parseResult[4][index][4][2].steptitle || parseResult[4][index][2][4][2].steptitle);
5859
} catch(error) {
5960
return null;
6061
}
@@ -76,12 +77,30 @@ export class Parser {
7677

7778
getTextAfter(parseResult, index){
7879
try {
79-
return parseResult[3][index][3].steptextafterlines || "";
80+
return parseResult[4][index][3].steptextafterlines || "";
8081
} catch (error) {
8182
return "";
8283
}
8384
}
8485

86+
getTags(parseResult){
87+
let tagDict = {};
88+
try{
89+
let results = parseResult[2] ? parseResult[2][4].taglines.split(/\r?\n/) : Array();
90+
for (let result of results){
91+
if(result){
92+
result = result.split("=")
93+
let type = result[0];
94+
let tags = result[1].includes(";") ? result[1].split(";") : Array(result[1]);
95+
tagDict[type] = tags;
96+
}
97+
}
98+
}catch (error) {
99+
throw error;
100+
}
101+
return tagDict;
102+
}
103+
85104
insertNewlineIntoDescription(description: string): string{
86105
let result = description;
87106
let offset = 0;

engine/playbook.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export class Playbook{
88
public description: string;
99
public conclusion: string;
1010
public steps: Step[] = [];
11+
public tags: Record<string, string[]>;
1112
}

0 commit comments

Comments
 (0)