Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48b92ac
commit 268aa9d
Showing
7 changed files
with
1,012 additions
and
52 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Neat! | ||
|
||
You've solved this problem! |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const fs = require('fs'); | ||
const HTMLParser = require('fast-html-parser'); | ||
|
||
module.exports = filename => new Promise((resolve, reject) => { | ||
fs.readFile(filename, 'utf8', (err, content) => { | ||
if (err) return reject(err); | ||
const tree = HTMLParser.parse(content); | ||
return resolve(tree.firstChild.structure); | ||
}); | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,42 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const diff = require('./diff'); | ||
|
||
module.exports = function troubleshooting(path, data) { | ||
return fs.readFileSync(path, 'utf8') | ||
// Replace breaking characters | ||
.replace(/'/g, "'") | ||
.replace(/"/g, '"') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
// Inject data | ||
.replace(/%solution%/g, data.solution) | ||
.replace(/%attempt%/g, data.attempt) | ||
.replace(/%diff%/g, diff(data.attempt, data.solution)) | ||
.replace(/%filename%/, data.filename); | ||
/** | ||
* Format troubleshooting message | ||
* This function reads the troubleshooting file and replaces kewords | ||
* by data providen in `data` object | ||
* | ||
* @param {String} file Path to troubleshooting file: | ||
* @see ../i18n/troubleshooting/ | ||
* @param {Object} data Object with corresponding data | ||
* @return {String} | ||
*/ | ||
const format = (file, data) => fs.readFileSync(file, 'utf8') | ||
// Replace breaking characters | ||
.replace(/'/g, "'") | ||
.replace(/"/g, '"') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
// Inject data | ||
.replace(/%solution%/g, data.solution) | ||
.replace(/%attempt%/g, data.attempt) | ||
.replace(/%diff%/g, diff(data.attempt, data.solution)) | ||
.replace(/%filename%/, data.filename); | ||
|
||
/** | ||
* Compose fail message | ||
* @param {Object} data Object with data that's needed for formating | ||
* @return {Array} | ||
*/ | ||
module.exports = function troubleshooting(data) { | ||
return [{ | ||
text: format(data.file, data), | ||
type: 'md', | ||
}, { | ||
text: '---', | ||
type: 'md', | ||
}, { | ||
file: path.join(__dirname, '..', 'i18n', 'footer', '{lang}.md'), | ||
}]; | ||
}; |
Oops, something went wrong.