mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 10:25:32 +08:00
FEATURE: rename cronos bbcode element to date
This commit is contained in:
parent
3d6dc764be
commit
741898a106
|
@ -73,12 +73,11 @@ export default Ember.Component.extend({
|
|||
},
|
||||
|
||||
getTextConfig(config) {
|
||||
let text = "[discourse-cronos ";
|
||||
if (config.recurring) text += `recurring=${config.recurring};`;
|
||||
text += `time=${config.time};`;
|
||||
text += `date=${config.date};`;
|
||||
text += `format=${config.format};`;
|
||||
text += `timezones=${config.timezones.join("|")};`;
|
||||
let text = `[date=${config.date} `;
|
||||
if (config.recurring) text += `recurring=${config.recurring} `;
|
||||
text += `time=${config.time} `;
|
||||
text += `format=${config.format} `;
|
||||
text += `timezones="${config.timezones.join("|")}"`;
|
||||
text += `]`;
|
||||
return text;
|
||||
},
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
import { registerOption } from 'pretty-text/pretty-text';
|
||||
|
||||
registerOption((siteSettings, opts) => {
|
||||
opts.features['discourse-cronos'] = !!siteSettings.discourse_cronos_enabled;
|
||||
});
|
||||
import { parseBBCodeTag } from 'pretty-text/engines/discourse-markdown/bbcode-block';
|
||||
|
||||
function addcronos(buffer, matches, state) {
|
||||
let token;
|
||||
|
@ -14,11 +10,12 @@ function addcronos(buffer, matches, state) {
|
|||
timezones: ""
|
||||
};
|
||||
|
||||
const options = matches[1].split(";");
|
||||
options.forEach((option) => {
|
||||
let o = option.split("=");
|
||||
config[o[0]] = o[1];
|
||||
});
|
||||
let parsed = parseBBCodeTag("[date date" + matches[1] + "]", 0, matches[1].length + 11);
|
||||
|
||||
config.date = parsed.attrs.date;
|
||||
config.time = parsed.attrs.time;
|
||||
config.format = parsed.attrs.format || config.format;
|
||||
config.timezones = parsed.attrs.timezones || config.timezones;
|
||||
|
||||
token = new state.Token('a_open', 'a', 1);
|
||||
token.attrs = [
|
||||
|
@ -67,7 +64,7 @@ export function setup(helper) {
|
|||
|
||||
helper.registerPlugin(md => {
|
||||
const rule = {
|
||||
matcher: /\[discourse-cronos (.*?)\]/,
|
||||
matcher: /\[date(.*?)\]/,
|
||||
onMatch: addcronos
|
||||
};
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ describe PrettyText do
|
|||
it 'supports inserting date' do
|
||||
freeze_time
|
||||
cooked = PrettyText.cook <<~MD
|
||||
[discourse-cronos time=22:00;date=2018-05-08;format=LLL;timezones=Europe/Paris|America/Los_Angeles;][/discourse-cronos]
|
||||
[date=2018-05-08 time=22:00 format=LLL timezones="Europe/Paris|America/Los_Angeles"]
|
||||
MD
|
||||
|
||||
expect(cooked).to include('class="discourse-cronos"')
|
||||
|
|
Loading…
Reference in New Issue
Block a user