Compare commits
No commits in common. "569bef32261189af20ab7ff2a94ef9bc680a0fec" and "d584fe8bf7256e6d7168c0e7ec59fba8f35baf3a" have entirely different histories.
569bef3226
...
d584fe8bf7
|
|
@ -24,7 +24,7 @@ Plugin.prototype.init = function (md) {
|
||||||
export function tagParser(id, state, silent) {
|
export function tagParser(id, state, silent) {
|
||||||
let input = state.src.slice(state.pos);
|
let input = state.src.slice(state.pos);
|
||||||
|
|
||||||
const match = /^#\S+/.exec(input)
|
const match = /^#[^ ]+/.exec(input)
|
||||||
if (!match) {
|
if (!match) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
105
editor/src/sr.js
105
editor/src/sr.js
|
|
@ -9,46 +9,6 @@ function fillResult($modal, result) {
|
||||||
$modal.find('.block-text').show().val(result.line)
|
$modal.find('.block-text').show().val(result.line)
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceBlock(id, oldText) {
|
|
||||||
return fetch('/api/block/replace', {
|
|
||||||
method: 'post',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
},
|
|
||||||
body: qs.encode({id, text: oldText}),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function appendBlock(id, newText) {
|
|
||||||
return fetch('/api/block/append', {
|
|
||||||
method: 'post',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
},
|
|
||||||
body: qs.encode({id, text: newText}),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetSRBox(text) {
|
|
||||||
let newText = text.replace(/#(?:\[\[)?sr\/(\d+)(?:\]\])?/, '#sr/1');
|
|
||||||
return newText;
|
|
||||||
}
|
|
||||||
|
|
||||||
function processSRBox(review, originalText) {
|
|
||||||
let oldText = originalText
|
|
||||||
.replace(/#(?:\[\[)?sr\/(\d+)(?:\]\])?/, function (text, srCount) {
|
|
||||||
if (review === 'never') return '';
|
|
||||||
let nextCount = 1;
|
|
||||||
const count = parseInt(srCount)
|
|
||||||
if (review === 'again') nextCount = 1
|
|
||||||
if (review === 'soon') nextCount = count
|
|
||||||
if (review === 'later') nextCount = count + 1
|
|
||||||
return '#sr/' + nextCount;
|
|
||||||
}).trim()
|
|
||||||
if (review === 'never') return oldText.replace(/#(?:\[\[)?review(?:\]\])?/, '')
|
|
||||||
return oldText
|
|
||||||
}
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
let reviewBlocks = [];
|
let reviewBlocks = [];
|
||||||
|
|
||||||
|
|
@ -90,13 +50,17 @@ $(function () {
|
||||||
let text = $modal.find('.block-text').val()
|
let text = $modal.find('.block-text').val()
|
||||||
let id = $modal.data('block-id')
|
let id = $modal.data('block-id')
|
||||||
|
|
||||||
|
// let oldText = text
|
||||||
|
// .replace(/#\[\[review\]\]/, '')
|
||||||
|
// .replace(/#\[\[sr\/(\d+)\]\]/g, '')
|
||||||
|
// .trim()
|
||||||
|
|
||||||
processText(review, text, originalText, id)
|
processText(review, text, originalText, id)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (reviewBlocks.length > 0) {
|
if (reviewBlocks.length > 0) {
|
||||||
const first = reviewBlocks.shift()
|
const first = reviewBlocks.shift()
|
||||||
// reload note with id
|
// reload note with id
|
||||||
search.startQuery('id:' + first.id, {internal: false})
|
search.startQuery('id:' + first.id, {internal: false}).then((results) => {
|
||||||
.then((results) => {
|
|
||||||
fillResult($modal, results[0])
|
fillResult($modal, results[0])
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -109,10 +73,59 @@ $(function () {
|
||||||
}).catch(e => console.log(e))
|
}).catch(e => console.log(e))
|
||||||
});
|
});
|
||||||
|
|
||||||
async function processText(review, text, originalText, id) {
|
function processText(review, text, originalText, id) {
|
||||||
if (text !== originalText) {
|
const changed = text !== originalText
|
||||||
await appendBlock(id, resetSRBox(text))
|
if (changed) {
|
||||||
|
let newText = text.replace(/#\[\[sr\/(\d+)\]\]/, '#[[sr/1]]');
|
||||||
|
return fetch('/api/block/append', {
|
||||||
|
method: 'post',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
body: qs.encode({id, text: newText}),
|
||||||
|
}).then(() => {
|
||||||
|
let oldText = originalText
|
||||||
|
.replace(/#\[\[sr\/(\d+)\]\]/, function (text, srCount) {
|
||||||
|
if (review === 'never') return '';
|
||||||
|
let nextCount = 1;
|
||||||
|
const count = parseInt(srCount)
|
||||||
|
if (review === 'again') nextCount = 1
|
||||||
|
if (review === 'soon') nextCount = count
|
||||||
|
if (review === 'later') nextCount = count + 1
|
||||||
|
return '#[[sr/' + nextCount + ']]';
|
||||||
|
}).trim()
|
||||||
|
if (review === 'never') oldText = oldText.replace(/#\[\[review\]\]/, '')
|
||||||
|
return fetch('/api/block/replace', {
|
||||||
|
method: 'post',
|
||||||
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||||
|
body: qs.encode({id, text: oldText}),
|
||||||
|
}).then(() => {
|
||||||
|
return text
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
let oldText = text
|
||||||
|
.replace(/#\[\[sr\/(\d+)\]\]/, function (text, srCount) {
|
||||||
|
if (review === 'never') return '';
|
||||||
|
|
||||||
|
let nextCount = 1;
|
||||||
|
const count = parseInt(srCount)
|
||||||
|
if (review === 'again') nextCount = 1
|
||||||
|
if (review === 'soon') nextCount = count
|
||||||
|
if (review === 'later') nextCount = count + 1
|
||||||
|
return '#[[sr/' + nextCount + ']]';
|
||||||
|
}).trim()
|
||||||
|
if (review === 'never') oldText = oldText.replace(/#\[\[review\]\]/, '')
|
||||||
|
|
||||||
|
return fetch('/api/block/replace', {
|
||||||
|
method: 'post',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
body: qs.encode({id, text: oldText}),
|
||||||
|
}).then(() => {
|
||||||
|
return text
|
||||||
|
})
|
||||||
}
|
}
|
||||||
await replaceBlock(id, processSRBox(review, originalText))
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
14
main.go
14
main.go
|
|
@ -922,7 +922,11 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderLinks(pageText string, edit bool) string {
|
func renderLinks(pageText string, edit bool) string {
|
||||||
hrefRE := regexp.MustCompile(`#?\[\[\s*([^\]]+)\s*\]\]`)
|
hrefRE, err := regexp.Compile(`#?\[\[\s*([^\]]+)\s*\]\]`)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
pageText = hrefRE.ReplaceAllStringFunc(pageText, func(s string) string {
|
pageText = hrefRE.ReplaceAllStringFunc(pageText, func(s string) string {
|
||||||
tag := false
|
tag := false
|
||||||
if s[0] == '#' {
|
if s[0] == '#' {
|
||||||
|
|
@ -951,14 +955,6 @@ func renderLinks(pageText string, edit bool) string {
|
||||||
|
|
||||||
return fmt.Sprintf("[%s](/%s%s)", s, editPart, cleanNameURL(s))
|
return fmt.Sprintf("[%s](/%s%s)", s, editPart, cleanNameURL(s))
|
||||||
})
|
})
|
||||||
|
|
||||||
tagRE := regexp.MustCompile(`#(\S+)`)
|
|
||||||
pageText = tagRE.ReplaceAllStringFunc(pageText, func(s string) string {
|
|
||||||
s = strings.TrimPrefix(s, "#")
|
|
||||||
s = strings.TrimSpace(s)
|
|
||||||
return fmt.Sprintf(`<a href="/%s" class="tag">%s</a>`, url.PathEscape(cleanNameURL(s)), s)
|
|
||||||
})
|
|
||||||
|
|
||||||
return pageText
|
return pageText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user