mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
FEATURE: new site setting 'code formatting style'
This commit is contained in:
parent
800081f606
commit
83309752ae
|
@ -63,18 +63,7 @@ class Toolbar {
|
|||
perform: e => e.applySurround('> ', '', 'code_text')
|
||||
});
|
||||
|
||||
this.addButton({
|
||||
id: 'code',
|
||||
group: 'insertions',
|
||||
shortcut: 'Shift+C',
|
||||
perform(e) {
|
||||
if (e.selected.value.indexOf("\n") !== -1) {
|
||||
e.applySurround(' ', '', 'code_text');
|
||||
} else {
|
||||
e.applySurround('`', '`', 'code_text');
|
||||
}
|
||||
},
|
||||
});
|
||||
this.addButton({id: 'code', group: 'insertions', shortcut: 'Shift+C', action: 'formatCode'});
|
||||
|
||||
this.addButton({
|
||||
id: 'bullet',
|
||||
|
@ -530,6 +519,19 @@ export default Ember.Component.extend({
|
|||
this.set('insertLinkHidden', false);
|
||||
},
|
||||
|
||||
formatCode() {
|
||||
const sel = this._getSelected();
|
||||
if (sel.value.indexOf("\n") !== -1) {
|
||||
return (this.siteSettings.code_formatting_style == "4-spaces-indent") ?
|
||||
this._applySurround(sel, ' ', '', 'code_text') :
|
||||
this._addText(sel, '```\n' + sel.value + '\n```');
|
||||
} else {
|
||||
return (this.siteSettings.code_formatting_style == "4-spaces-indent") ?
|
||||
this._applySurround(sel, '`', '`', 'code_text') :
|
||||
this._applySurround(sel, '```\n', '\n```', 'paste_code_text');
|
||||
}
|
||||
},
|
||||
|
||||
insertLink() {
|
||||
const origLink = this.get('linkUrl');
|
||||
const linkUrl = (origLink.indexOf('://') === -1) ? `http://${origLink}` : origLink;
|
||||
|
|
|
@ -1055,6 +1055,7 @@ en:
|
|||
quote_text: "Blockquote"
|
||||
code_title: "Preformatted text"
|
||||
code_text: "indent preformatted text by 4 spaces"
|
||||
paste_code_text: "type or paste code here"
|
||||
upload_title: "Upload"
|
||||
upload_description: "enter upload description here"
|
||||
olist_title: "Numbered List"
|
||||
|
|
|
@ -1315,6 +1315,8 @@ en:
|
|||
auto_close_messages_post_count: "Maximum number of posts allowed in a message before it is automatically closed (0 to disable)"
|
||||
auto_close_topics_post_count: "Maximum number of posts allowed in a topic before it is automatically closed (0 to disable)"
|
||||
|
||||
code_formatting_style: "Code button in composer will default to this code formatting style"
|
||||
|
||||
default_email_digest_frequency: "How often users receive summary emails by default."
|
||||
default_include_tl0_in_digests: "Include posts from new users in summary emails by default. Users can change this in their preferences."
|
||||
default_email_private_messages: "Send an email when someone messages the user by default."
|
||||
|
|
|
@ -511,6 +511,13 @@ posting:
|
|||
min: 0
|
||||
auto_close_messages_post_count: 500
|
||||
auto_close_topics_post_count: 10000
|
||||
code_formatting_style:
|
||||
client: true
|
||||
type: enum
|
||||
default: '4-spaces-indent'
|
||||
choices:
|
||||
- 4-spaces-indent
|
||||
- code-fences
|
||||
|
||||
email:
|
||||
email_time_window_mins:
|
||||
|
|
|
@ -257,6 +257,7 @@ testCase('link modal (link with description)', function(assert) {
|
|||
componentTest('advanced code', {
|
||||
template: '{{d-editor value=value}}',
|
||||
setup() {
|
||||
this.siteSettings.code_formatting_style = '4-spaces-indent';
|
||||
this.set('value',
|
||||
`function xyz(x, y, z) {
|
||||
if (y === z) {
|
||||
|
@ -286,6 +287,7 @@ componentTest('advanced code', {
|
|||
componentTest('code button', {
|
||||
template: '{{d-editor value=value}}',
|
||||
setup() {
|
||||
this.siteSettings.code_formatting_style = '4-spaces-indent';
|
||||
this.set('value', "first line\n\nsecond line\n\nthird line");
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user