mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 01:53:11 +08:00
Fix issue 1378 (#1405)
* Feat: add trimUnnecessaryEmptyLine setting option * remove debug code * Fix: tpro and remove debug codes * rename trimUnnecessaryEmptyLine to trimUnnecessaryCodeBlockEmptyLines
This commit is contained in:
parent
b791fd2371
commit
fab1c62fde
@ -19,20 +19,21 @@ Preferences can be controlled and modified in the settings window or via the `pr
|
|||||||
|
|
||||||
#### Editor
|
#### Editor
|
||||||
|
|
||||||
| Key | Type | Defaut | Description |
|
| Key | Type | Defaut | Description |
|
||||||
| ---------------------- | ------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------------ | ------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| fontSize | Number | 16 | Font size in pixels. 12 ~ 32 |
|
| fontSize | Number | 16 | Font size in pixels. 12 ~ 32 |
|
||||||
| editorFontFamily | String | Open Sans | Font Family |
|
| editorFontFamily | String | Open Sans | Font Family |
|
||||||
| lineHeight | Number | 1.6 | Line Height |
|
| lineHeight | Number | 1.6 | Line Height |
|
||||||
| autoPairBracket | Boolean | true | Automatically brackets when editing |
|
| autoPairBracket | Boolean | true | Automatically brackets when editing |
|
||||||
| autoPairMarkdownSyntax | Boolean | true | Autocomplete markdown syntax |
|
| autoPairMarkdownSyntax | Boolean | true | Autocomplete markdown syntax |
|
||||||
| autoPairQuote | Boolean | true | Automatic completion of quotes |
|
| autoPairQuote | Boolean | true | Automatic completion of quotes |
|
||||||
| endOfLine | String | default | The newline character used at the end of each line. The default value is default, which will be selected according to your system intelligence. `lf` `crlf` `default` |
|
| endOfLine | String | default | The newline character used at the end of each line. The default value is default, which will be selected according to your system intelligence. `lf` `crlf` `default` |
|
||||||
| textDirection | String | ltr | The writing text direction, optional value: `ltr` or `rtl` |
|
| textDirection | String | ltr | The writing text direction, optional value: `ltr` or `rtl` |
|
||||||
| codeFontSize | Number | 14 | Font size on code block, the range is 12 ~ 28 |
|
| codeFontSize | Number | 14 | Font size on code block, the range is 12 ~ 28 |
|
||||||
| codeFontFamily | String | `DejaVu Sans Mono` | Code font family |
|
| codeFontFamily | String | `DejaVu Sans Mono` | Code font family |
|
||||||
| hideQuickInsertHint | Boolean | false | Hide hint for quickly creating paragraphs |
|
| trimUnnecessaryCodeBlockEmptyLines | Boolean | true | Whether to trim the beginning and end empty line in Code block |
|
||||||
| imageDropAction | String | folder | The default behavior after paste or drag the image to Mark Text, upload it to the image cloud (if configured), move to the specified folder, insert the path |
|
| hideQuickInsertHint | Boolean | false | Hide hint for quickly creating paragraphs |
|
||||||
|
| imageDropAction | String | folder | The default behavior after paste or drag the image to Mark Text, upload it to the image cloud (if configured), move to the specified folder, insert the path |
|
||||||
|
|
||||||
#### Markdown
|
#### Markdown
|
||||||
|
|
||||||
|
@ -92,7 +92,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"pattern": "^[_A-z0-9]+((-|\\s)*[_A-z0-9])*$"
|
"pattern": "^[_A-z0-9]+((-|\\s)*[_A-z0-9])*$"
|
||||||
},
|
},
|
||||||
|
"trimUnnecessaryCodeBlockEmptyLines": {
|
||||||
|
"description": "Editor--Trim the beginning and ending empty lines in code block",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"autoPairBracket": {
|
"autoPairBracket": {
|
||||||
"description": "Editor--Automatically brackets when editing",
|
"description": "Editor--Automatically brackets when editing",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
@ -242,6 +242,8 @@ export const EXPORT_DOMPURIFY_CONFIG = {
|
|||||||
export const MUYA_DEFAULT_OPTION = {
|
export const MUYA_DEFAULT_OPTION = {
|
||||||
focusMode: false,
|
focusMode: false,
|
||||||
markdown: '',
|
markdown: '',
|
||||||
|
// Whether to trim the beginning and ending empty line in code block when open markdown.
|
||||||
|
trimUnnecessaryCodeBlockEmptyLines: false,
|
||||||
preferLooseListItem: true,
|
preferLooseListItem: true,
|
||||||
autoPairBracket: true,
|
autoPairBracket: true,
|
||||||
autoPairMarkdownSyntax: true,
|
autoPairMarkdownSyntax: true,
|
||||||
|
@ -76,6 +76,7 @@ const importRegister = ContentState => {
|
|||||||
nextSibling: null,
|
nextSibling: null,
|
||||||
children: []
|
children: []
|
||||||
}
|
}
|
||||||
|
const { trimUnnecessaryCodeBlockEmptyLines } = this.muya.options
|
||||||
const tokens = new Lexer({ disableInline: true }).lex(markdown)
|
const tokens = new Lexer({ disableInline: true }).lex(markdown)
|
||||||
let token
|
let token
|
||||||
let block
|
let block
|
||||||
@ -158,10 +159,11 @@ const importRegister = ContentState => {
|
|||||||
const lang = (infostring || '').match(/\S*/)[0]
|
const lang = (infostring || '').match(/\S*/)[0]
|
||||||
|
|
||||||
value = text
|
value = text
|
||||||
// Fix: #1265 and remove codes bellow.
|
// Fix: #1265.
|
||||||
// if (value.endsWith('\n')) {
|
if (trimUnnecessaryCodeBlockEmptyLines && (value.endsWith('\n') || value.startsWith('\n'))) {
|
||||||
// value = value.replace(/\n+$/, '')
|
value = value.replace(/\n+$/, '')
|
||||||
// }
|
.replace(/^\n+/, '')
|
||||||
|
}
|
||||||
if (/mermaid|flowchart|vega-lite|sequence/.test(lang)) {
|
if (/mermaid|flowchart|vega-lite|sequence/.test(lang)) {
|
||||||
block = this.createContainerBlock(lang, value)
|
block = this.createContainerBlock(lang, value)
|
||||||
this.appendChild(parentList[0], block)
|
this.appendChild(parentList[0], block)
|
||||||
|
@ -138,6 +138,7 @@ export default {
|
|||||||
fontSize: state => state.preferences.fontSize,
|
fontSize: state => state.preferences.fontSize,
|
||||||
codeFontSize: state => state.preferences.codeFontSize,
|
codeFontSize: state => state.preferences.codeFontSize,
|
||||||
codeFontFamily: state => state.preferences.codeFontFamily,
|
codeFontFamily: state => state.preferences.codeFontFamily,
|
||||||
|
trimUnnecessaryCodeBlockEmptyLines: state => state.preferences.trimUnnecessaryCodeBlockEmptyLines,
|
||||||
editorFontFamily: state => state.preferences.editorFontFamily,
|
editorFontFamily: state => state.preferences.editorFontFamily,
|
||||||
hideQuickInsertHint: state => state.preferences.hideQuickInsertHint,
|
hideQuickInsertHint: state => state.preferences.hideQuickInsertHint,
|
||||||
editorLineWidth: state => state.preferences.editorLineWidth,
|
editorLineWidth: state => state.preferences.editorLineWidth,
|
||||||
@ -262,6 +263,12 @@ export default {
|
|||||||
editor.setOptions({ autoPairQuote: value })
|
editor.setOptions({ autoPairQuote: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
trimUnnecessaryCodeBlockEmptyLines: function (value, oldValue) {
|
||||||
|
const { editor } = this
|
||||||
|
if (value !== oldValue && editor) {
|
||||||
|
editor.setOptions({ trimUnnecessaryCodeBlockEmptyLines: value })
|
||||||
|
}
|
||||||
|
},
|
||||||
bulletListMarker: function (value, oldValue) {
|
bulletListMarker: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
@ -326,6 +333,7 @@ export default {
|
|||||||
autoPairBracket,
|
autoPairBracket,
|
||||||
autoPairMarkdownSyntax,
|
autoPairMarkdownSyntax,
|
||||||
autoPairQuote,
|
autoPairQuote,
|
||||||
|
trimUnnecessaryCodeBlockEmptyLines,
|
||||||
bulletListMarker,
|
bulletListMarker,
|
||||||
orderListDelimiter,
|
orderListDelimiter,
|
||||||
tabSize,
|
tabSize,
|
||||||
@ -361,6 +369,7 @@ export default {
|
|||||||
preferLooseListItem,
|
preferLooseListItem,
|
||||||
autoPairBracket,
|
autoPairBracket,
|
||||||
autoPairMarkdownSyntax,
|
autoPairMarkdownSyntax,
|
||||||
|
trimUnnecessaryCodeBlockEmptyLines,
|
||||||
autoPairQuote,
|
autoPairQuote,
|
||||||
bulletListMarker,
|
bulletListMarker,
|
||||||
orderListDelimiter,
|
orderListDelimiter,
|
||||||
|
@ -10,11 +10,20 @@
|
|||||||
:step="1"
|
:step="1"
|
||||||
:onChange="value => onSelectChange('fontSize', value)"
|
:onChange="value => onSelectChange('fontSize', value)"
|
||||||
></range>
|
></range>
|
||||||
|
<range
|
||||||
|
description="Line height of editor lines."
|
||||||
|
:value="lineHeight"
|
||||||
|
:min="1.2"
|
||||||
|
:max="2.0"
|
||||||
|
:step="0.1"
|
||||||
|
:onChange="value => onSelectChange('lineHeight', value)"
|
||||||
|
></range>
|
||||||
<font-text-box
|
<font-text-box
|
||||||
description="The used font in the editor."
|
description="The used font in the editor."
|
||||||
:value="editorFontFamily"
|
:value="editorFontFamily"
|
||||||
:onChange="value => onSelectChange('editorFontFamily', value)"
|
:onChange="value => onSelectChange('editorFontFamily', value)"
|
||||||
></font-text-box>
|
></font-text-box>
|
||||||
|
<separator></separator>
|
||||||
<range
|
<range
|
||||||
description="The code block font size in editor."
|
description="The code block font size in editor."
|
||||||
:value="codeFontSize"
|
:value="codeFontSize"
|
||||||
@ -30,14 +39,11 @@
|
|||||||
:value="codeFontFamily"
|
:value="codeFontFamily"
|
||||||
:onChange="value => onSelectChange('codeFontFamily', value)"
|
:onChange="value => onSelectChange('codeFontFamily', value)"
|
||||||
></font-text-box>
|
></font-text-box>
|
||||||
<range
|
<bool
|
||||||
description="Line height of editor lines."
|
description="Trim the beginning and ending empty lines in code block when open markdown."
|
||||||
:value="lineHeight"
|
:bool="trimUnnecessaryCodeBlockEmptyLines"
|
||||||
:min="1.2"
|
:onChange="value => onSelectChange('trimUnnecessaryCodeBlockEmptyLines', value)"
|
||||||
:max="2.0"
|
></bool>
|
||||||
:step="0.1"
|
|
||||||
:onChange="value => onSelectChange('lineHeight', value)"
|
|
||||||
></range>
|
|
||||||
<separator></separator>
|
<separator></separator>
|
||||||
<bool
|
<bool
|
||||||
description="Automatically brackets when editing."
|
description="Automatically brackets when editing."
|
||||||
@ -68,7 +74,6 @@
|
|||||||
:onChange="value => onSelectChange('textDirection', value)"
|
:onChange="value => onSelectChange('textDirection', value)"
|
||||||
></cur-select>
|
></cur-select>
|
||||||
<separator></separator>
|
<separator></separator>
|
||||||
<separator></separator>
|
|
||||||
<bool
|
<bool
|
||||||
description="Hide hint for quickly creating paragraphs."
|
description="Hide hint for quickly creating paragraphs."
|
||||||
:input="hideQuickInsertHint"
|
:input="hideQuickInsertHint"
|
||||||
@ -124,6 +129,7 @@ export default {
|
|||||||
textDirection: state => state.preferences.textDirection,
|
textDirection: state => state.preferences.textDirection,
|
||||||
codeFontSize: state => state.preferences.codeFontSize,
|
codeFontSize: state => state.preferences.codeFontSize,
|
||||||
codeFontFamily: state => state.preferences.codeFontFamily,
|
codeFontFamily: state => state.preferences.codeFontFamily,
|
||||||
|
trimUnnecessaryCodeBlockEmptyLines: state => state.preferences.trimUnnecessaryCodeBlockEmptyLines,
|
||||||
hideQuickInsertHint: state => state.preferences.hideQuickInsertHint,
|
hideQuickInsertHint: state => state.preferences.hideQuickInsertHint,
|
||||||
editorLineWidth: state => state.preferences.editorLineWidth
|
editorLineWidth: state => state.preferences.editorLineWidth
|
||||||
})
|
})
|
||||||
|
@ -19,6 +19,7 @@ const state = {
|
|||||||
lineHeight: 1.6,
|
lineHeight: 1.6,
|
||||||
codeFontSize: 14,
|
codeFontSize: 14,
|
||||||
codeFontFamily: 'DejaVu Sans Mono',
|
codeFontFamily: 'DejaVu Sans Mono',
|
||||||
|
trimUnnecessaryCodeBlockEmptyLines: true,
|
||||||
editorLineWidth: '',
|
editorLineWidth: '',
|
||||||
|
|
||||||
autoPairBracket: true,
|
autoPairBracket: true,
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"lineHeight": 1.6,
|
"lineHeight": 1.6,
|
||||||
"codeFontSize": 14,
|
"codeFontSize": 14,
|
||||||
"codeFontFamily": "DejaVu Sans Mono",
|
"codeFontFamily": "DejaVu Sans Mono",
|
||||||
|
"trimUnnecessaryCodeBlockEmptyLines": true,
|
||||||
"editorLineWidth": "",
|
"editorLineWidth": "",
|
||||||
|
|
||||||
"autoPairBracket": true,
|
"autoPairBracket": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user