Skip to content

Commit fdb41c0

Browse files
committed
added alternative-lists plugin + updated packages
1 parent af5134c commit fdb41c0

File tree

6 files changed

+169
-11
lines changed

6 files changed

+169
-11
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ module.exports = (grunt) => {
158158
'dist/sceditor.min.js',
159159
'src/formats/bbcode.js',
160160
'src/icons/fontawesome.js',
161+
'src/plugins/alternative-lists.js',
161162
'src/plugins/dragdrop.js',
162163
'src/plugins/undo.js',
163164
'src/plugins/plaintext.js',

dist/sceditor.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sceditor.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ <h1>SCEditor example</h1>
6363
autofocus: true,
6464
//locale: 'de',
6565
maxLength: 32767,
66-
plugins: 'emojis,undo,mentions,dragdrop',
66+
plugins: 'emojis,undo,mentions,dragdrop,alternative-lists',
6767

6868
//emojis: ['😊', '❤️', '😄', '😄', '😄', '😄', '😄', '😄', '😄', '😄', '😄', '😄'],
6969
styles: ['https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css', 'https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism.min.css'],

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
"@lodder/time-grunt": "^4.0.0",
4646
"@rollup/plugin-node-resolve": "^16.0.3",
4747
"@w8tcha/grunt-dev-update": "^2.3.4",
48-
"autoprefixer": "^10.4.24",
49-
"cssnano": "^7.1.2",
48+
"autoprefixer": "^10.4.27",
49+
"cssnano": "^7.1.3",
5050
"grunt": "~1.6.1",
5151
"grunt-contrib-clean": "^2.0.1",
5252
"grunt-contrib-concat": "~2.1.0",
@@ -61,16 +61,16 @@
6161
"istanbul-lib-report": "^3.0.1",
6262
"istanbul-reports": "^3.2.0",
6363
"loader-utils": "^3.3.1",
64-
"postcss": "^8.5.6",
64+
"postcss": "^8.5.8",
6565
"postcss-header": "^3.0.3",
6666
"qunit": "^2.25.0",
6767
"rangy": "^1.3.2",
68-
"sass": "^1.97.3",
69-
"sinon": "^21.0.1",
70-
"webpack": "^5.105.1",
68+
"sass": "^1.98.0",
69+
"sinon": "^21.0.3",
70+
"webpack": "^5.105.4",
7171
"webpack-dev-server": "^5.2.3"
7272
},
7373
"dependencies": {
74-
"dompurify": "^3.3.1"
74+
"dompurify": "^3.3.3"
7575
}
7676
}

src/plugins/alternative-lists.js

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/**
2+
* SCEditor Inline-Code Plugin for BBCode format
3+
* http://www.sceditor.com/
4+
*
5+
* Copyright (C) 2011-2026, Sam Clarke (samclarke.com)
6+
*
7+
* SCEditor is licensed under the MIT license:
8+
* http://www.opensource.org/licenses/mit-license.php
9+
*
10+
* @fileoverview SCEditor alternative lists plugin
11+
* This plugin implements phpBB style of the lists:
12+
* [list]
13+
* [*]item
14+
* [*]item
15+
* [/list]
16+
* @author Alex Betis
17+
*/
18+
19+
(function (sceditor) {
20+
'use strict';
21+
22+
var utils = sceditor.utils;
23+
24+
function isFunction(fn) {
25+
return typeof fn === 'function';
26+
}
27+
28+
sceditor.plugins['alternative-lists'] = function () {
29+
var base = this;
30+
31+
/**
32+
* Private functions
33+
* @private
34+
*/
35+
var bulletHandler;
36+
var orderedHandler;
37+
var insertListTag;
38+
39+
base.init = function () {
40+
var opts = this.opts;
41+
42+
// Enable for BBCode only
43+
if (opts.format && opts.format !== 'bbcode') {
44+
return;
45+
}
46+
47+
// Override only txtExec implementation
48+
sceditor.command.get('orderedlist').txtExec = orderedHandler;
49+
sceditor.command.get('bulletlist').txtExec = bulletHandler;
50+
51+
// Override current implementation
52+
sceditor.formats.bbcode.set('list', {
53+
breakStart: true,
54+
isInline: false,
55+
skipLastLineBreak: true,
56+
html: function (token, attrs, content) {
57+
var listType = 'disc';
58+
var toHtml = null;
59+
60+
if (attrs.defaultattr) {
61+
listType = attrs.defaultattr;
62+
}
63+
64+
if (listType === '1') {
65+
// This listType belongs to orderedList (OL)
66+
toHtml = sceditor.formats.bbcode.get('ol').html;
67+
} else {
68+
// unknown listType, use default bullet list behavior
69+
toHtml = sceditor.formats.bbcode.get('ul').html;
70+
}
71+
72+
if (isFunction(toHtml)) {
73+
return toHtml.call(this, token, attrs, content);
74+
} else {
75+
token.attrs['0'] = content;
76+
return sceditor.formats.bbcode.formatBBCodeString(
77+
toHtml, token.attrs);
78+
}
79+
}
80+
});
81+
82+
sceditor.formats.bbcode.set('ul', {
83+
tags: {
84+
ul: null
85+
},
86+
breakStart: true,
87+
isInline: false,
88+
skipLastLineBreak: true,
89+
format: '[list]{0}[/list]',
90+
html: '<ul>{0}</ul>'
91+
});
92+
93+
sceditor.formats.bbcode.set('ol', {
94+
tags: {
95+
ol: null
96+
},
97+
breakStart: true,
98+
isInline: false,
99+
skipLastLineBreak: true,
100+
format: '[list=1]{0}[/list]',
101+
html: '<ol>{0}</ol>'
102+
});
103+
104+
sceditor.formats.bbcode.set('li', {
105+
tags: {
106+
li: null
107+
},
108+
isInline: false,
109+
closedBy: ['/ul', '/ol', '/list', '*', 'li'],
110+
format: '[*]{0}',
111+
html: '<li>{0}</li>'
112+
});
113+
114+
sceditor.formats.bbcode.set('*', {
115+
isInline: false,
116+
excludeClosing: true,
117+
closedBy: ['/ul', '/ol', '/list', '*', 'li'],
118+
html: '<li>{0}</li>'
119+
});
120+
};
121+
122+
insertListTag = function (editor, listType, selected) {
123+
var content = '';
124+
125+
utils.each(selected.split(/\r?\n/), function (item) {
126+
content += (content ? '\n' : '') +
127+
'[*]' + item;
128+
});
129+
130+
if (listType === '') {
131+
editor.insertText('[list]\n' + content + '\n[/list]');
132+
} else {
133+
editor.insertText('[list=' + listType + ']\n' + content +
134+
'\n[/list]');
135+
}
136+
};
137+
138+
/**
139+
* Function for the txtExec and exec properties
140+
*
141+
* @param {node} caller
142+
* @private
143+
*/
144+
orderedHandler = function (caller, selected) {
145+
var editor = this;
146+
147+
insertListTag(editor, '1', selected);
148+
};
149+
150+
bulletHandler = function (caller, selected) {
151+
var editor = this;
152+
153+
insertListTag(editor, '', selected);
154+
};
155+
156+
};
157+
})(sceditor);

0 commit comments

Comments
 (0)