Compare commits
3 Commits
67af38f785
...
74b1220710
Author | SHA1 | Date | |
---|---|---|---|
74b1220710 | |||
001e4748dd | |||
760eb11694 |
|
@ -1,6 +1,8 @@
|
||||||
import $ from 'jquery'
|
import $ from 'jquery'
|
||||||
import 'jquery-contextmenu'
|
import 'jquery-contextmenu'
|
||||||
import copy from 'copy-text-to-clipboard'
|
import copy from 'copy-text-to-clipboard'
|
||||||
|
import axios from "axios";
|
||||||
|
import qs from "querystring";
|
||||||
|
|
||||||
function renderTree(tree) {
|
function renderTree(tree) {
|
||||||
if (!tree) return []
|
if (!tree) return []
|
||||||
|
@ -22,7 +24,17 @@ function connectContextMenu(editor) {
|
||||||
createNewPage: {
|
createNewPage: {
|
||||||
name: 'Create page from item',
|
name: 'Create page from item',
|
||||||
callback: function (key, opt) {
|
callback: function (key, opt) {
|
||||||
console.log('Create page from item', key, opt)
|
console.log('Create page from item')
|
||||||
|
editor.flat(this, {base: true}).then(result => {
|
||||||
|
let data = {
|
||||||
|
'json': 1,
|
||||||
|
'p': result.title,
|
||||||
|
'summary': "",
|
||||||
|
'content': JSON.stringify(result.children),
|
||||||
|
};
|
||||||
|
console.log(data)
|
||||||
|
return axios.post('/save/', qs.encode(data))
|
||||||
|
}).then()
|
||||||
},
|
},
|
||||||
className: 'action-new-page'
|
className: 'action-new-page'
|
||||||
},
|
},
|
||||||
|
|
|
@ -69,7 +69,7 @@ Plugin.prototype.render = function (tokens, id, options, env) {
|
||||||
return '<input type="checkbox" class="checkbox" checked>';
|
return '<input type="checkbox" class="checkbox" checked>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return '<a href="'+this.options.relativeBaseURL+encodeURIComponent(link.replace(' ', '_')) + '" class="wiki-link">' + (tag ? '#' : '') + link + '</a>';
|
return '<a href="'+this.options.relativeBaseURL+encodeURIComponent(link.replace(/ +/g, '_')) + '" class="wiki-link">' + (tag ? '#' : '') + link + '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (options) => {
|
export default (options) => {
|
||||||
|
|
|
@ -65,6 +65,6 @@ describe('MD', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('parseLinks double url', function () {
|
it('parseLinks double url', function () {
|
||||||
assert.deepStrictEqual(MD.renderInline("[[test [[link]] test2]]"), '<a href="/edit/test_%5B%5Blink%5D%5D%20test2" class="wiki-link">test [[link]] test2</a>')
|
assert.deepStrictEqual(MD.renderInline("[[test [[link]] test2]]"), '<a href="/edit/test_%5B%5Blink%5D%5D_test2" class="wiki-link">test [[link]] test2</a>')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -111,12 +111,13 @@ function editor(root, inputData, options) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function flat(element) {
|
function flat(element, opt) {
|
||||||
|
opt = opt || {}
|
||||||
let item = $(element).parents('.list-item')
|
let item = $(element).parents('.list-item')
|
||||||
let id = item.attr('data-id')
|
let id = item.attr('data-id')
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
resolve(store.flat(id));
|
resolve(store.flat(id, opt));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -365,8 +365,23 @@ function Store(inputData) {
|
||||||
return [values[from], ..._.takeWhile(items, item => item.indented > values[from].indented)]
|
return [values[from], ..._.takeWhile(items, item => item.indented > values[from].indented)]
|
||||||
}
|
}
|
||||||
|
|
||||||
function flat(from) {
|
function flat(from, opt) {
|
||||||
return selectItemsFrom(from)
|
opt = opt || {}
|
||||||
|
let result = selectItemsFrom(from)
|
||||||
|
if (opt.base && result.length > 0) {
|
||||||
|
const first = result[0]
|
||||||
|
let children = _.map(result.slice(1), (item) => {
|
||||||
|
let newItem = _.clone(item)
|
||||||
|
newItem.indented -= first.indented+1
|
||||||
|
newItem.id = ID()
|
||||||
|
return newItem
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
title: first.text,
|
||||||
|
children
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
2
main.go
2
main.go
|
@ -28,6 +28,7 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -44,6 +45,7 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(log.Lshortfile)
|
log.SetFlags(log.Lshortfile)
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
type authorizedKey string
|
type authorizedKey string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user