1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00
This commit is contained in:
Dick Choi
2016-05-25 17:09:39 +09:00
parent 1a98afee92
commit 7f8733796e
17 changed files with 901 additions and 650 deletions

View File

@@ -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)
})
})
}

View File

@@ -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'))