Skip to content

Commit 5b48fbf

Browse files
committed
feat: support lightdown syntax in option descriptions
closes #5
1 parent 539081f commit 5b48fbf

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Options can all have the following properties,
6565

6666
* `string` - `type` - What type of option this is, more info below. Defaults to "checkbox".
6767
* `string` - `name` - Required. What to save the key as. Also used as class name to add to field containers, in case you'd like to style it further.
68-
* `string` - `desc`
68+
* `string` - `desc` - Description of option, supports syntax from [lightdown](https://github.com/WebReflection/lightdown), a markdown-like language.
6969
* `string` - `preview` - A preview image. Represents the extension of the image, example "png". If this is used, the image must be placed in a `previews` folder where `options.html` is, and named the name as this option's key, which is its name prepended by tab name if any.
7070
* `Object` - `default` - Default value.
7171
* `boolean` - `disabled` - The field can be disabled.
@@ -143,7 +143,7 @@ Similar to checkbox with `options`, but without the checkbox. Not just for aesth
143143
![list](images/complex_list.png)
144144

145145
* `Array.<Object>` - `fields` - Required. List of fields for this list.
146-
* `string` - `type` - Only basic field types listed above and custom fields supported.
146+
* `string` - `type` - Only basic fields, layout types, and custom fields supported.
147147
* `string` - `name` - Required for non-layout types.
148148
* `boolean` - `required` - Set to true if you require this particular field to be a truthy value for this row to be saved.
149149
* `Object` - `bindTo` - Will only display this field if another field with name matching `bindTo.field` has the value `bindTo.value`, which can be be a string or an array of strings.

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"css-loader": "^1.0.0",
3333
"dragula": "^3.7.2",
3434
"file-loader": "^2.0.0",
35+
"lightdown": "^0.5.3",
3536
"style-loader": "^0.23.0",
3637
"url-loader": "^1.1.1",
3738
"webpack": "^4.20.2",

src/js/base.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ import * as dom from './dom.js';
55
import dragula from 'dragula';
66
require('dragula/dist/dragula.css');
77

8+
import lightdown from 'lightdown';
9+
810
chrome.options = {};
911
chrome.options.base = {};
1012
chrome.options.fields = {};
1113

1214
const addH3 = (option) => h('h3', option.desc);
1315
const addHtml = (option) => h('', { innerHTML: option.html });
16+
const parseDesc = (desc) => ({
17+
innerHTML: lightdown(
18+
desc.replace(/[<>]/g, m => ({'<': '&lt;', '>': '&gt;'}[m]))
19+
)
20+
});
1421

1522
chrome.options.addOption = (key, value, save, option) => {
1623
if (value === undefined && option.default != null) {
@@ -133,7 +140,7 @@ chrome.options.base.checkbox = (value, save, option, key) => {
133140
});
134141
}
135142

136-
$label.append(h('span', option.desc));
143+
$label.append(h('span', parseDesc(option.desc)));
137144
return $container;
138145
};
139146

@@ -173,13 +180,13 @@ chrome.options.base.checkboxNField = (value, save, option, type) => {
173180
}, option));
174181

175182
if (option.desc) {
176-
$container.append(h('label', option.desc));
183+
$container.append(h('label', parseDesc(option.desc)));
177184
}
178185
return $container;
179186
};
180187

181188
chrome.options.base.object = (value, save, option, key) => {
182-
const $container = h('.object', h('label', option.desc));
189+
const $container = h('.object', h('label', parseDesc(option.desc)));
183190
$container.append(addOptions(value, save, option, key));
184191
return $container;
185192
};
@@ -204,9 +211,7 @@ const addOptions = (value, save, option, key) => {
204211
};
205212

206213
chrome.options.addLabelNField = (value, save, option) => {
207-
const $label = h('label');
208-
$label.innerHTML = option.desc || '';
209-
const $container = h('.suboption', $label);
214+
const $container = h('.suboption', h('label', parseDesc(option.desc)));
210215
const $field = chrome.options.addField(value, save, option);
211216
$container.append(h('.field-container', $field));
212217
$container.classList.add(option.singleline ? 'singleline' : 'multiline');
@@ -218,7 +223,8 @@ chrome.options.base.list = (list, save, options, key) => {
218223
let $wrapper, shown = true;
219224

220225
if (options.desc) {
221-
const $label = $container.appendChild(h('label', options.desc));
226+
const $label =
227+
$container.appendChild(h('label', parseDesc(options.desc)));
222228
if (options.collapsible) {
223229
shown = false;
224230
const $triangle = h('span.triangle', {
@@ -251,7 +257,7 @@ chrome.options.base.list = (list, save, options, key) => {
251257
let prevfield;
252258
options.fields.forEach((field) => {
253259
if (!field.bindTo || !prevfield.bindTo) {
254-
const $container = heads[field.name] = h('div', field.desc);
260+
const $container = heads[field.name] = h('div', parseDesc(field.desc));
255261
$thead.append(h('th', $container));
256262
} else {
257263
heads[field.name] = heads[prevfield.name];

0 commit comments

Comments
 (0)