mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 02:10:29 +08:00
* Fix #1879: Add .md extension to files created in sidebar if no extension given. * Use hasMarkdownExtension function everywhere an extension has to be checked. Allowed markdown extensions are handeled in several places in different ways. Use the hasMarkdownFunction from common/filesystem/paths.js to allow to easily update the allowed extensions when needed.
This commit is contained in:
parent
622ff90d58
commit
862324387c
@ -15,6 +15,8 @@ export const MARKDOWN_EXTENSIONS = [
|
|||||||
'txt'
|
'txt'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const MARKDOWN_INCLUSIONS = MARKDOWN_EXTENSIONS.map(x => '*.' + x)
|
||||||
|
|
||||||
export const IMAGE_EXTENSIONS = [
|
export const IMAGE_EXTENSIONS = [
|
||||||
'jpeg',
|
'jpeg',
|
||||||
'jpg',
|
'jpg',
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { ipcRenderer } from 'electron'
|
import { ipcRenderer } from 'electron'
|
||||||
import { isChildOfDirectory } from 'common/filesystem/paths'
|
import { isChildOfDirectory, hasMarkdownExtension, MARKDOWN_INCLUSIONS } from '../../common/filesystem/paths'
|
||||||
import bus from '../bus'
|
import bus from '../bus'
|
||||||
import { delay } from '@/util'
|
import { delay } from '@/util'
|
||||||
import FileSearcher from '@/node/fileSearcher'
|
import FileSearcher from '@/node/fileSearcher'
|
||||||
|
|
||||||
const MD_EXTENSION = /\.(?:markdown|mdown|mkdn|md|mkd|mdwn|mdtxt|mdtext|text|txt)$/i
|
|
||||||
const SPECIAL_CHARS = /[\[\]\\^$.\|\?\*\+\(\)\/]{1}/g // eslint-disable-line no-useless-escape
|
const SPECIAL_CHARS = /[\[\]\\^$.\|\?\*\+\(\)\/]{1}/g // eslint-disable-line no-useless-escape
|
||||||
|
|
||||||
// The quick open command
|
// The quick open command
|
||||||
@ -174,11 +173,11 @@ class QuickOpenCommand {
|
|||||||
|
|
||||||
_getInclusions = query => {
|
_getInclusions = query => {
|
||||||
// NOTE: This will fail on `foo.m` because we search for `foo.m.md`.
|
// NOTE: This will fail on `foo.m` because we search for `foo.m.md`.
|
||||||
if (MD_EXTENSION.test(query)) {
|
if (hasMarkdownExtension(query)) {
|
||||||
return [`*${query}`]
|
return [`*${query}`]
|
||||||
}
|
}
|
||||||
|
|
||||||
const inclusions = ['*.markdown', '*.mdown', '*.mkdn', '*.md', '*.mkd', '*.mdwn', '*.mdtxt', '*.mdtext', '*.text', '*.txt']
|
const inclusions = MARKDOWN_INCLUSIONS
|
||||||
for (let i = 0; i < inclusions.length; ++i) {
|
for (let i = 0; i < inclusions.length; ++i) {
|
||||||
inclusions[i] = `*${query}` + inclusions[i]
|
inclusions[i] = `*${query}` + inclusions[i]
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,7 @@ import EmptyIcon from '@/assets/icons/undraw_empty.svg'
|
|||||||
import FindCaseIcon from '@/assets/icons/searchIcons/iconCase.svg'
|
import FindCaseIcon from '@/assets/icons/searchIcons/iconCase.svg'
|
||||||
import FindWordIcon from '@/assets/icons/searchIcons/iconWord.svg'
|
import FindWordIcon from '@/assets/icons/searchIcons/iconWord.svg'
|
||||||
import FindRegexIcon from '@/assets/icons/searchIcons/iconRegex.svg'
|
import FindRegexIcon from '@/assets/icons/searchIcons/iconRegex.svg'
|
||||||
|
import { MARKDOWN_INCLUSIONS } from '../../../common/filesystem/paths'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
@ -232,7 +233,7 @@ export default {
|
|||||||
followSymlinks: this.searchFollowSymlinks,
|
followSymlinks: this.searchFollowSymlinks,
|
||||||
|
|
||||||
// Only search markdown files
|
// Only search markdown files
|
||||||
inclusions: ['*.markdown', '*.mdown', '*.mkdn', '*.md', '*.mkd', '*.mdwn', '*.mdtxt', '*.mdtext', '*.text', '*.txt']
|
inclusions: MARKDOWN_INCLUSIONS
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.searchResult = newSearchResult
|
this.searchResult = newSearchResult
|
||||||
|
@ -6,6 +6,7 @@ import { create, paste, rename } from '../util/fileSystem'
|
|||||||
import { PATH_SEPARATOR } from '../config'
|
import { PATH_SEPARATOR } from '../config'
|
||||||
import notice from '../services/notification'
|
import notice from '../services/notification'
|
||||||
import { getFileStateFromData } from './help'
|
import { getFileStateFromData } from './help'
|
||||||
|
import { hasMarkdownExtension } from '../../common/filesystem/paths'
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
activeItem: {},
|
activeItem: {},
|
||||||
@ -173,7 +174,13 @@ const actions = {
|
|||||||
|
|
||||||
CREATE_FILE_DIRECTORY ({ commit, state }, name) {
|
CREATE_FILE_DIRECTORY ({ commit, state }, name) {
|
||||||
const { dirname, type } = state.createCache
|
const { dirname, type } = state.createCache
|
||||||
|
|
||||||
|
if (type === 'file' && !hasMarkdownExtension(name)) {
|
||||||
|
name += '.md'
|
||||||
|
}
|
||||||
|
|
||||||
const fullName = `${dirname}/${name}`
|
const fullName = `${dirname}/${name}`
|
||||||
|
|
||||||
create(fullName, type)
|
create(fullName, type)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
commit('CREATE_PATH', {})
|
commit('CREATE_PATH', {})
|
||||||
|
Loading…
Reference in New Issue
Block a user