mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 15:21:33 +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
@ -20,7 +20,7 @@ Preferences can be controlled and modified in the settings window or via the `pr
|
||||
#### Editor
|
||||
|
||||
| Key | Type | Defaut | Description |
|
||||
| ---------------------- | ------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| ------------------------ | ------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| fontSize | Number | 16 | Font size in pixels. 12 ~ 32 |
|
||||
| editorFontFamily | String | Open Sans | Font Family |
|
||||
| lineHeight | Number | 1.6 | Line Height |
|
||||
@ -31,6 +31,7 @@ Preferences can be controlled and modified in the settings window or via the `pr
|
||||
| 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 |
|
||||
| codeFontFamily | String | `DejaVu Sans Mono` | Code font family |
|
||||
| trimUnnecessaryCodeBlockEmptyLines | Boolean | true | Whether to trim the beginning and end empty line in Code block |
|
||||
| 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 |
|
||||
|
||||
|
@ -92,7 +92,10 @@
|
||||
"type": "string",
|
||||
"pattern": "^[_A-z0-9]+((-|\\s)*[_A-z0-9])*$"
|
||||
},
|
||||
|
||||
"trimUnnecessaryCodeBlockEmptyLines": {
|
||||
"description": "Editor--Trim the beginning and ending empty lines in code block",
|
||||
"type": "boolean"
|
||||
},
|
||||
"autoPairBracket": {
|
||||
"description": "Editor--Automatically brackets when editing",
|
||||
"type": "boolean"
|
||||
|
@ -242,6 +242,8 @@ export const EXPORT_DOMPURIFY_CONFIG = {
|
||||
export const MUYA_DEFAULT_OPTION = {
|
||||
focusMode: false,
|
||||
markdown: '',
|
||||
// Whether to trim the beginning and ending empty line in code block when open markdown.
|
||||
trimUnnecessaryCodeBlockEmptyLines: false,
|
||||
preferLooseListItem: true,
|
||||
autoPairBracket: true,
|
||||
autoPairMarkdownSyntax: true,
|
||||
|
@ -76,6 +76,7 @@ const importRegister = ContentState => {
|
||||
nextSibling: null,
|
||||
children: []
|
||||
}
|
||||
const { trimUnnecessaryCodeBlockEmptyLines } = this.muya.options
|
||||
const tokens = new Lexer({ disableInline: true }).lex(markdown)
|
||||
let token
|
||||
let block
|
||||
@ -158,10 +159,11 @@ const importRegister = ContentState => {
|
||||
const lang = (infostring || '').match(/\S*/)[0]
|
||||
|
||||
value = text
|
||||
// Fix: #1265 and remove codes bellow.
|
||||
// if (value.endsWith('\n')) {
|
||||
// value = value.replace(/\n+$/, '')
|
||||
// }
|
||||
// Fix: #1265.
|
||||
if (trimUnnecessaryCodeBlockEmptyLines && (value.endsWith('\n') || value.startsWith('\n'))) {
|
||||
value = value.replace(/\n+$/, '')
|
||||
.replace(/^\n+/, '')
|
||||
}
|
||||
if (/mermaid|flowchart|vega-lite|sequence/.test(lang)) {
|
||||
block = this.createContainerBlock(lang, value)
|
||||
this.appendChild(parentList[0], block)
|
||||
|
@ -138,6 +138,7 @@ export default {
|
||||
fontSize: state => state.preferences.fontSize,
|
||||
codeFontSize: state => state.preferences.codeFontSize,
|
||||
codeFontFamily: state => state.preferences.codeFontFamily,
|
||||
trimUnnecessaryCodeBlockEmptyLines: state => state.preferences.trimUnnecessaryCodeBlockEmptyLines,
|
||||
editorFontFamily: state => state.preferences.editorFontFamily,
|
||||
hideQuickInsertHint: state => state.preferences.hideQuickInsertHint,
|
||||
editorLineWidth: state => state.preferences.editorLineWidth,
|
||||
@ -262,6 +263,12 @@ export default {
|
||||
editor.setOptions({ autoPairQuote: value })
|
||||
}
|
||||
},
|
||||
trimUnnecessaryCodeBlockEmptyLines: function (value, oldValue) {
|
||||
const { editor } = this
|
||||
if (value !== oldValue && editor) {
|
||||
editor.setOptions({ trimUnnecessaryCodeBlockEmptyLines: value })
|
||||
}
|
||||
},
|
||||
bulletListMarker: function (value, oldValue) {
|
||||
const { editor } = this
|
||||
if (value !== oldValue && editor) {
|
||||
@ -326,6 +333,7 @@ export default {
|
||||
autoPairBracket,
|
||||
autoPairMarkdownSyntax,
|
||||
autoPairQuote,
|
||||
trimUnnecessaryCodeBlockEmptyLines,
|
||||
bulletListMarker,
|
||||
orderListDelimiter,
|
||||
tabSize,
|
||||
@ -361,6 +369,7 @@ export default {
|
||||
preferLooseListItem,
|
||||
autoPairBracket,
|
||||
autoPairMarkdownSyntax,
|
||||
trimUnnecessaryCodeBlockEmptyLines,
|
||||
autoPairQuote,
|
||||
bulletListMarker,
|
||||
orderListDelimiter,
|
||||
|
@ -10,11 +10,20 @@
|
||||
:step="1"
|
||||
:onChange="value => onSelectChange('fontSize', value)"
|
||||
></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
|
||||
description="The used font in the editor."
|
||||
:value="editorFontFamily"
|
||||
:onChange="value => onSelectChange('editorFontFamily', value)"
|
||||
></font-text-box>
|
||||
<separator></separator>
|
||||
<range
|
||||
description="The code block font size in editor."
|
||||
:value="codeFontSize"
|
||||
@ -30,14 +39,11 @@
|
||||
:value="codeFontFamily"
|
||||
:onChange="value => onSelectChange('codeFontFamily', value)"
|
||||
></font-text-box>
|
||||
<range
|
||||
description="Line height of editor lines."
|
||||
:value="lineHeight"
|
||||
:min="1.2"
|
||||
:max="2.0"
|
||||
:step="0.1"
|
||||
:onChange="value => onSelectChange('lineHeight', value)"
|
||||
></range>
|
||||
<bool
|
||||
description="Trim the beginning and ending empty lines in code block when open markdown."
|
||||
:bool="trimUnnecessaryCodeBlockEmptyLines"
|
||||
:onChange="value => onSelectChange('trimUnnecessaryCodeBlockEmptyLines', value)"
|
||||
></bool>
|
||||
<separator></separator>
|
||||
<bool
|
||||
description="Automatically brackets when editing."
|
||||
@ -68,7 +74,6 @@
|
||||
:onChange="value => onSelectChange('textDirection', value)"
|
||||
></cur-select>
|
||||
<separator></separator>
|
||||
<separator></separator>
|
||||
<bool
|
||||
description="Hide hint for quickly creating paragraphs."
|
||||
:input="hideQuickInsertHint"
|
||||
@ -124,6 +129,7 @@ export default {
|
||||
textDirection: state => state.preferences.textDirection,
|
||||
codeFontSize: state => state.preferences.codeFontSize,
|
||||
codeFontFamily: state => state.preferences.codeFontFamily,
|
||||
trimUnnecessaryCodeBlockEmptyLines: state => state.preferences.trimUnnecessaryCodeBlockEmptyLines,
|
||||
hideQuickInsertHint: state => state.preferences.hideQuickInsertHint,
|
||||
editorLineWidth: state => state.preferences.editorLineWidth
|
||||
})
|
||||
|
@ -19,6 +19,7 @@ const state = {
|
||||
lineHeight: 1.6,
|
||||
codeFontSize: 14,
|
||||
codeFontFamily: 'DejaVu Sans Mono',
|
||||
trimUnnecessaryCodeBlockEmptyLines: true,
|
||||
editorLineWidth: '',
|
||||
|
||||
autoPairBracket: true,
|
||||
|
@ -16,6 +16,7 @@
|
||||
"lineHeight": 1.6,
|
||||
"codeFontSize": 14,
|
||||
"codeFontFamily": "DejaVu Sans Mono",
|
||||
"trimUnnecessaryCodeBlockEmptyLines": true,
|
||||
"editorLineWidth": "",
|
||||
|
||||
"autoPairBracket": true,
|
||||
|
Loading…
Reference in New Issue
Block a user