Skip to content

Commit

Permalink
feat(convert-markdown): Convert markdown inline code blocks to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Dec 17, 2017
1 parent 419fc39 commit 5169517
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/convertMarkdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const chalk = require('chalk');
const resolve = require('../resolve');
const convertMarkdownCodeToCli = require('../convertMarkdownCodeToCli');
const convertMarkdownInlineCodeToCli = require('../convertMarkdownInlineCodeToCli');

/*
readmeData
Expand Down Expand Up @@ -79,7 +80,7 @@ const extractLinksFromReadme = readmeData => {
}

return {
text: convertMarkdownCodeToCli(text),
text: convertMarkdownInlineCodeToCli(convertMarkdownCodeToCli(text)),
links,
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/convertMarkdownCodeToCli/__mocks__/default.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```html
// Key and Value
react.impulsCoach.components.teaserOverview.title = This is an <a href="#">example</a>
react.components.title = This is an <a href="#">example</a>
```;
2 changes: 1 addition & 1 deletion src/convertMarkdownCodeToCli/__mocks__/no-title.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```
// Key and Value
react.impulsCoach.components.teaserOverview.title = This is an <a href="#">example</a>
react.components.title = This is an <a href="#">example</a>
```;
6 changes: 6 additions & 0 deletions src/convertMarkdownInlineCodeToCli/__mocks__/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Contribute buddy collect all readme files in the project and split them into sections and topics by using the `h1` and `h2` headlines. These sections and topics will be displayed in the cli before start (and after install) if you didn't read them before and nothing had changed. The reading history will be stored in your filesystem (user directory).

```html
// Key and Value
react.components.title = This is an <a href="#">example</a>
```
22 changes: 22 additions & 0 deletions src/convertMarkdownInlineCodeToCli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const symbols = require('../symbols');

/**
* @param {string} markdown - the readme files data
* @param {Object} di - dependency injection
* @returns {string} markdown - replaced readme file data
**/
function convertMarkdownInlineCodeToCli(markdown) {
const reg = /(`)([^`]*)(`)/g;
let results;

// eslint-disable-next-line
while ((results = reg.exec(markdown)) !== null) {
if (results[0] !== '``' && results[0].indexOf('\n') < 0) {
markdown = markdown.replace(results[0], symbols.codeInline.msg(results[2]));
}
}

return markdown;
}

module.exports = convertMarkdownInlineCodeToCli;
10 changes: 10 additions & 0 deletions src/convertMarkdownInlineCodeToCli/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint quote-props: 0*/
const fs = require('fs');
const convertMarkdownInlineCodeToCli = require('./index');

describe('convertMarkdownInlineCodeToCli', () => {
it('default', () => {
const data = fs.readFileSync('./src/convertMarkdownInlineCodeToCli/__mocks__/default.md', 'utf8');
expect(typeof convertMarkdownInlineCodeToCli(data)).toBe('string');
});
});
3 changes: 3 additions & 0 deletions src/symbols/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const symbols = {
bottomLeft: ` ${chalk.gray.bgWhite(' │')}`,
bottomRight: `${chalk.bgWhite(' ')} `,
},
codeInline: {
msg: text => chalk.black.bgWhite(text),
},
};

module.exports = symbols;

0 comments on commit 5169517

Please sign in to comment.