mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
Detail
This commit is contained in:
@@ -149,16 +149,16 @@ class Repository {
|
||||
let fetchNotes = () => {
|
||||
let noteNames = fs.readdirSync(dataPath)
|
||||
let notes = noteNames
|
||||
.map((noteName) => {
|
||||
let notePath = path.join(dataPath, noteName)
|
||||
|
||||
.map((noteName) => path.join(dataPath, noteName))
|
||||
.filter((notePath) => CSON.isObjectPath(notePath))
|
||||
.map((notePath) => {
|
||||
return new Promise(function (resolve, reject) {
|
||||
CSON.readFile(notePath, function (err, obj) {
|
||||
if (err != null) {
|
||||
console.log(err)
|
||||
return resolve(null)
|
||||
}
|
||||
obj.key = path.basename(noteName, '.cson')
|
||||
obj.key = path.basename(notePath, '.cson')
|
||||
return resolve(obj)
|
||||
})
|
||||
})
|
||||
@@ -427,24 +427,16 @@ class Repository {
|
||||
}
|
||||
|
||||
updateNote (noteKey, override) {
|
||||
let note = _.find(this.notes, {key: noteKey})
|
||||
let isNew = false
|
||||
if (note == null) {
|
||||
note = override
|
||||
isNew = true
|
||||
}
|
||||
|
||||
if (!this.constructor.validateNote(note)) {
|
||||
if (!this.constructor.validateNote(override)) {
|
||||
return Promise.reject(new Error('Invalid input'))
|
||||
}
|
||||
|
||||
if (isNew) this.notes.push(note)
|
||||
note.updatedAt = new Date()
|
||||
|
||||
override.updatedAt = new Date()
|
||||
return new Promise((resolve, reject) => {
|
||||
CSON.writeFile(path.join(this.cached.path, 'data', note.key + '.cson'), _.omit(note, ['key']), function (err) {
|
||||
CSON.writeFile(path.join(this.cached.path, 'data', noteKey + '.cson'), _.omit(override, ['key']), function (err) {
|
||||
if (err != null) return reject(err)
|
||||
resolve(note)
|
||||
override.key = noteKey
|
||||
resolve(override)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import emoji from 'markdown-it-emoji'
|
||||
import math from '@rokt33r/markdown-it-math'
|
||||
import hljs from 'highlight.js'
|
||||
|
||||
const katex = window.katex
|
||||
|
||||
function createGutter (str) {
|
||||
let lc = (str.match(/\n/g) || []).length
|
||||
let lines = []
|
||||
@@ -39,10 +41,22 @@ md.use(emoji, {
|
||||
})
|
||||
md.use(math, {
|
||||
inlineRenderer: function (str) {
|
||||
return `<span class='math'>${str}</span>`
|
||||
let output = ''
|
||||
try {
|
||||
output = katex.renderToString(str.trim())
|
||||
} catch (err) {
|
||||
output = `<span class="katex-error">${err.message}</span>`
|
||||
}
|
||||
return output
|
||||
},
|
||||
blockRenderer: function (str) {
|
||||
return `<div class='math'>${str}</div>`
|
||||
let output = ''
|
||||
try {
|
||||
output = katex.renderToString(str.trim(), {displayMode: true})
|
||||
} catch (err) {
|
||||
output = `<div class="katex-error">${err.message}</div>`
|
||||
}
|
||||
return output
|
||||
}
|
||||
})
|
||||
md.use(require('markdown-it-checkbox'))
|
||||
|
||||
Reference in New Issue
Block a user