diff --git a/docs/Development/plugin creation.md b/docs/Development/plugin creation.md index a64e60d8..f036c7d2 100644 --- a/docs/Development/plugin creation.md +++ b/docs/Development/plugin creation.md @@ -42,4 +42,7 @@ A plugin should refuse to activate on a platform that does not support key funct - Colors - Links - Images - - Spoilers \ No newline at end of file + - Spoilers + - Preformat + - Strikethrough + - List \ No newline at end of file diff --git a/docs/api/providers/nodebb/format.md b/docs/api/providers/nodebb/format.md index 8209f4b9..e55cfa77 100644 --- a/docs/api/providers/nodebb/format.md +++ b/docs/api/providers/nodebb/format.md @@ -46,6 +46,15 @@
header6(text)string

Format text as a sixth level header.

+
preformat(text)string
+

Format text as a preformatted block

+
+
strikethrough(text)string
+

Format text with a strikethrough effect

+
+
list(items)string
+

Format text as a list of items

+
@@ -236,3 +245,39 @@ Format text as a sixth level header. | --- | --- | --- | | text | string | Header text | + + +## preformat(text) ⇒ string +Format text as a preformatted block + +**Kind**: global function +**Returns**: string - Text in a preformat block + +| Param | Type | Description | +| --- | --- | --- | +| text | string | The text | + + + +## strikethrough(text) ⇒ string +Format text with a strikethrough effect + +**Kind**: global function +**Returns**: string - The stricken text + +| Param | Type | Description | +| --- | --- | --- | +| text | string | The text to strike out | + + + +## list(items) ⇒ string +Format text as a list of items + +**Kind**: global function +**Returns**: string - The list + +| Param | Type | Description | +| --- | --- | --- | +| items | string | An array of strings to format as a list | + diff --git a/docs/api/providers/nodebb/index.md b/docs/api/providers/nodebb/index.md index 77699e8d..b5388303 100644 --- a/docs/api/providers/nodebb/index.md +++ b/docs/api/providers/nodebb/index.md @@ -170,14 +170,16 @@ Deactivate forum and plugins #### forum.supports(supportString) ⇒ boolean -Documentation for foo. +Supports: does the provider support a given feature? **Kind**: instance method of [Forum](#sockbot.providers.module_nodebb..Forum) -**Returns**: boolean - it's a value? +**Returns**: boolean - 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 | string | Array.<strng> | it's a string? | +| supportString | string | Array.<strng> | The feature string. Feature strings consist of one or more features connected by dots. May also be an array of such strings | diff --git a/providers/nodebb/format.js b/providers/nodebb/format.js index dc1529f1..6dfbe8ed 100644 --- a/providers/nodebb/format.js +++ b/providers/nodebb/format.js @@ -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(''); +}; diff --git a/providers/nodebb/index.js b/providers/nodebb/index.js index b41db0d5..d8a65e34 100644 --- a/providers/nodebb/index.js +++ b/providers/nodebb/index.js @@ -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; diff --git a/test/providers/nodebb/formatTest.js b/test/providers/nodebb/formatTest.js index 600305dd..fe616440 100644 --- a/test/providers/nodebb/formatTest.js +++ b/test/providers/nodebb/formatTest.js @@ -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}()'`, () => { @@ -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); + }); + }); });