Skip to content

Commit

Permalink
Merge pull request #391 from SockDrawer/formatter-updates
Browse files Browse the repository at this point in the history
Formatter updates
  • Loading branch information
AccaliaDeElementia authored Nov 29, 2016
2 parents 827b92a + cc414dc commit 7436514
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
5 changes: 4 additions & 1 deletion docs/Development/plugin creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ A plugin should refuse to activate on a platform that does not support key funct
- Colors
- Links
- Images
- Spoilers
- Spoilers
- Preformat
- Strikethrough
- List
45 changes: 45 additions & 0 deletions docs/api/providers/nodebb/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
<dt><a href="#header6">header6(text)</a> ⇒ <code>string</code></dt>
<dd><p>Format text as a sixth level header.</p>
</dd>
<dt><a href="#preformat">preformat(text)</a> ⇒ <code>string</code></dt>
<dd><p>Format text as a preformatted block</p>
</dd>
<dt><a href="#strikethrough">strikethrough(text)</a> ⇒ <code>string</code></dt>
<dd><p>Format text with a strikethrough effect</p>
</dd>
<dt><a href="#list">list(items)</a> ⇒ <code>string</code></dt>
<dd><p>Format text as a list of items</p>
</dd>
</dl>

<a name="urlForPost"></a>
Expand Down Expand Up @@ -236,3 +245,39 @@ Format text as a sixth level header.
| --- | --- | --- |
| text | <code>string</code> | Header text |

<a name="preformat"></a>

## preformat(text) ⇒ <code>string</code>
Format text as a preformatted block

**Kind**: global function
**Returns**: <code>string</code> - Text in a preformat block

| Param | Type | Description |
| --- | --- | --- |
| text | <code>string</code> | The text |

<a name="strikethrough"></a>

## strikethrough(text) ⇒ <code>string</code>
Format text with a strikethrough effect

**Kind**: global function
**Returns**: <code>string</code> - The stricken text

| Param | Type | Description |
| --- | --- | --- |
| text | <code>string</code> | The text to strike out |

<a name="list"></a>

## list(items) ⇒ <code>string</code>
Format text as a list of items

**Kind**: global function
**Returns**: <code>string</code> - The list

| Param | Type | Description |
| --- | --- | --- |
| items | <code>string</code> | An array of strings to format as a list |

8 changes: 5 additions & 3 deletions docs/api/providers/nodebb/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,16 @@ Deactivate forum and plugins
<a name="sockbot.providers.module_nodebb..Forum+supports"></a>

#### forum.supports(supportString) ⇒ <code>boolean</code>
Documentation for foo.
Supports: does the provider support a given feature?

**Kind**: instance method of <code>[Forum](#sockbot.providers.module_nodebb..Forum)</code>
**Returns**: <code>boolean</code> - it's a value?
**Returns**: <code>boolean</code> - True if all levels of feature supplied are supported,
false if not. In the case of an array, will only be true if all
strings are supported

| Param | Type | Description |
| --- | --- | --- |
| supportString | <code>string</code> &#124; <code>Array.&lt;strng&gt;</code> | it's a string? |
| supportString | <code>string</code> &#124; <code>Array.&lt;strng&gt;</code> | The feature string. Feature strings consist of one or more features connected by dots. May also be an array of such strings |

<a name="sockbot.providers.module_nodebb..Forum+fetchObject"></a>

Expand Down
35 changes: 35 additions & 0 deletions providers/nodebb/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,38 @@ exports.header5 = function header5(text) {
exports.header6 = function header6(text) {
return prefixifier('###### ', text);
};

/**
* Format text as a preformatted block
*
* @param {!string} text The text
* @returns {string} Text in a preformat block
*/
/* eslint-disable prefer-template */
exports.preformat = function preformat(text) {
if (text.indexOf('\n') > -1) {
return '```\n' + text + '\n```';
}
return '`' + text + '`';
};
/* eslint-enable prefer-template */

/**
* Format text with a strikethrough effect
*
* @param {!string} text The text to strike out
* @returns {string} The stricken text
*/
exports.strikethrough = function strikethrough(text) {
return prefixifier('~~', text, '~~');
};

/**
* Format text as a list of items
*
* @param {!string} items An array of strings to format as a list
* @returns {string} The list
*/
exports.list = function list(items) {
return items.map((item) => `\n- ${item}`).join('');
};
3 changes: 2 additions & 1 deletion providers/nodebb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ class Forum extends EventEmitter {
'Categories',
'Notifications', 'Notifications.URL',
'Formatting', 'Formatting.Markup', 'Formatting.Markup.Markdown',
'Formatting.Multiline', 'Formatting.Links', 'Formatting.Images', 'Formatting.Spoilers'
'Formatting.Multiline', 'Formatting.Links', 'Formatting.Images', 'Formatting.Spoilers',
'Formatting.Preformat', 'Formatting.Strikethrough', 'Formatting.List'
];

let support = false;
Expand Down
28 changes: 27 additions & 1 deletion test/providers/nodebb/formatTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('providers/nodebb/format', () => {
describe('exports', () => {
const fns = ['urlForPost', 'urlForTopic', 'quoteText', 'link', 'image', 'spoiler',
'italic', 'bold', 'bolditalic', 'header1', 'header2', 'header3', 'header4',
'header5', 'header6'
'header5', 'header6', 'preformat', 'strikethrough', 'list'
];
fns.forEach((fn) => {
it(`should export '${fn}()'`, () => {
Expand Down Expand Up @@ -588,4 +588,30 @@ describe('providers/nodebb/format', () => {
});
});
});
describe('preformat', () => {
it('should generate preformatted text in markdown', () => {
const expected = '`text`';
testModule.preformat('text').should.equal(expected);
});
it('should generate preformatted text with multiple lines', () => {
const expected = '```\nline1\nline2\n```';
testModule.preformat('line1\nline2').should.equal(expected);
});
it('should retain existing whitespace', () => {
const expected = '```\n line1\n line2\n```';
testModule.preformat(' line1\n line2').should.equal(expected);
});
});
describe('strikethrough', () => {
it('should generate preformatted text in markdown', () => {
const expected = '~~text~~';
testModule.strikethrough('text').should.equal(expected);
});
});
describe('list', () => {
it('should generate a list in markdwn', () => {
const expected = '\n- item1\n- item2\n- item3';
testModule.list(['item1', 'item2', 'item3']).should.equal(expected);
});
});
});

0 comments on commit 7436514

Please sign in to comment.