1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

Merge branch 'master' into fix-autocomplete-codeblock

This commit is contained in:
Baptiste Augrain
2020-06-26 02:40:37 +02:00
322 changed files with 21618 additions and 12667 deletions

View File

@@ -44,9 +44,46 @@
? match[2].replace('x', ' ')
: (parseInt(match[3], 10) + 1) + match[4]
replacements[i] = '\n' + indent + bullet + after
if (bullet) incrementRemainingMarkdownListNumbers(cm, pos)
}
}
cm.replaceSelections(replacements)
}
// Auto-updating Markdown list numbers when a new item is added to the
// middle of a list
function incrementRemainingMarkdownListNumbers(cm, pos) {
var startLine = pos.line, lookAhead = 0, skipCount = 0
var startItem = listRE.exec(cm.getLine(startLine)), startIndent = startItem[1]
do {
lookAhead += 1
var nextLineNumber = startLine + lookAhead
var nextLine = cm.getLine(nextLineNumber), nextItem = listRE.exec(nextLine)
if (nextItem) {
var nextIndent = nextItem[1]
var newNumber = (parseInt(startItem[3], 10) + lookAhead - skipCount)
var nextNumber = (parseInt(nextItem[3], 10)), itemNumber = nextNumber
if (startIndent === nextIndent && !isNaN(nextNumber)) {
if (newNumber === nextNumber) itemNumber = nextNumber + 1
if (newNumber > nextNumber) itemNumber = newNumber + 1
cm.replaceRange(
nextLine.replace(listRE, nextIndent + itemNumber + nextItem[4] + nextItem[5]),
{
line: nextLineNumber, ch: 0
}, {
line: nextLineNumber, ch: nextLine.length
})
} else {
if (startIndent.length > nextIndent.length) return
// This doesn't run if the next line immediatley indents, as it is
// not clear of the users intention (new indented item or same level)
if ((startIndent.length < nextIndent.length) && (lookAhead === 1)) return
skipCount += 1
}
}
} while (nextItem)
}
})

View File

@@ -11,6 +11,7 @@
})(function(CodeMirror) {
var defaults = {
pairs: "()[]{}''\"\"",
closeBefore: ")]}'\":;>",
triples: "",
explode: "[]{}"
};
@@ -114,6 +115,9 @@
var pairs = getOption(conf, "pairs");
var pos = pairs.indexOf(ch);
if (pos == -1) return CodeMirror.Pass;
var closeBefore = getOption(conf,"closeBefore");
var triples = getOption(conf, "triples");
var identical = pairs.charAt(pos + 1) == ch;
@@ -141,7 +145,7 @@
var prev = cur.ch == 0 ? " " : cm.getRange(Pos(cur.line, cur.ch - 1), cur)
if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = "both";
else return CodeMirror.Pass;
} else if (opening) {
} else if (opening && (next.length === 0 || /\s/.test(next) || closeBefore.indexOf(next) > -1)) {
curType = "both";
} else {
return CodeMirror.Pass;
@@ -189,4 +193,4 @@
return /\bstring/.test(token.type) && token.start == pos.ch &&
(pos.ch == 0 || !/\bstring/.test(cm.getTokenTypeAt(pos)))
}
});
});

View File

@@ -1,15 +1,24 @@
(function (mod) {
if (typeof exports === 'object' && typeof module === 'object') { // Common JS
;(function(mod) {
if (typeof exports === 'object' && typeof module === 'object') {
// Common JS
mod(require('../codemirror/lib/codemirror'))
} else if (typeof define === 'function' && define.amd) { // AMD
} else if (typeof define === 'function' && define.amd) {
// AMD
define(['../codemirror/lib/codemirror'], mod)
} else { // Plain browser env
} else {
// Plain browser env
mod(CodeMirror)
}
})(function (CodeMirror) {
})(function(CodeMirror) {
'use strict'
const shell = require('electron').shell
const remote = require('electron').remote
const eventEmitter = {
emit: function() {
remote.getCurrentWindow().webContents.send.apply(null, arguments)
}
}
const yOffset = 2
const macOS = global.process.platform === 'darwin'
@@ -28,11 +37,16 @@
this.tooltip = document.createElement('div')
this.tooltipContent = document.createElement('div')
this.tooltipIndicator = document.createElement('div')
this.tooltip.setAttribute('class', 'CodeMirror-hover CodeMirror-matchingbracket CodeMirror-selected')
this.tooltip.setAttribute(
'class',
'CodeMirror-hover CodeMirror-matchingbracket CodeMirror-selected'
)
this.tooltip.setAttribute('cm-ignore-events', 'true')
this.tooltip.appendChild(this.tooltipContent)
this.tooltip.appendChild(this.tooltipIndicator)
this.tooltipContent.textContent = `${macOS ? 'Cmd(⌘)' : 'Ctrl(^)'} + click to follow link`
this.tooltipContent.textContent = `${
macOS ? 'Cmd(⌘)' : 'Ctrl(^)'
} + click to follow link`
this.lineDiv.addEventListener('mousedown', this.onMouseDown)
this.lineDiv.addEventListener('mouseenter', this.onMouseEnter, {
@@ -51,7 +65,16 @@
const className = el.className.split(' ')
if (className.indexOf('cm-url') !== -1) {
const match = /^\((.*)\)|\[(.*)\]|(.*)$/.exec(el.textContent)
// multiple cm-url because of search term
const cmUrlSpans = Array.from(
el.parentNode.getElementsByClassName('cm-url')
)
const textContent =
cmUrlSpans.length > 1
? cmUrlSpans.map(span => span.textContent).join('')
: el.textContent
const match = /^\((.*)\)|\[(.*)\]|(.*)$/.exec(textContent)
const url = match[1] || match[2] || match[3]
// `:storage` is the value of the variable `STORAGE_FOLDER_PLACEHOLDER` defined in `browser/main/lib/dataApi/attachmentManagement`
@@ -60,13 +83,90 @@
return null
}
specialLinkHandler(e, rawHref, linkHash) {
const isStartWithHash = rawHref[0] === '#'
const extractIdRegex = /file:\/\/.*main.?\w*.html#/ // file://path/to/main(.development.)html
const regexNoteInternalLink = new RegExp(`${extractIdRegex.source}(.+)`)
if (isStartWithHash || regexNoteInternalLink.test(rawHref)) {
const posOfHash = linkHash.indexOf('#')
if (posOfHash > -1) {
const extractedId = linkHash.slice(posOfHash + 1)
const targetId = mdurl.encode(extractedId)
const targetElement = document.getElementById(targetId) // this.getWindow().document.getElementById(targetId)
if (targetElement != null) {
this.scrollTo(0, targetElement.offsetTop)
}
return
}
}
// this will match the new uuid v4 hash and the old hash
// e.g.
// :note:1c211eb7dcb463de6490 and
// :note:7dd23275-f2b4-49cb-9e93-3454daf1af9c
const regexIsNoteLink = /^:note:([a-zA-Z0-9-]{20,36})$/
if (regexIsNoteLink.test(linkHash)) {
eventEmitter.emit('list:jump', linkHash.replace(':note:', ''))
return
}
const regexIsLine = /^:line:[0-9]/
if (regexIsLine.test(linkHash)) {
const numberPattern = /\d+/g
const lineNumber = parseInt(linkHash.match(numberPattern)[0])
eventEmitter.emit('line:jump', lineNumber)
return
}
// this will match the old link format storage.key-note.key
// e.g.
// 877f99c3268608328037-1c211eb7dcb463de6490
const regexIsLegacyNoteLink = /^(.{20})-(.{20})$/
if (regexIsLegacyNoteLink.test(linkHash)) {
eventEmitter.emit('list:jump', linkHash.split('-')[1])
return
}
const regexIsTagLink = /^:tag:([\w]+)$/
if (regexIsTagLink.test(rawHref)) {
const tag = rawHref.match(regexIsTagLink)[1]
eventEmitter.emit('dispatch:push', `/tags/${encodeURIComponent(tag)}`)
return
}
}
onMouseDown(e) {
const { target } = e
if (!e[modifier]) {
return
}
// Create URL spans array used for special case "search term is hitting a link".
const cmUrlSpans = Array.from(
e.target.parentNode.getElementsByClassName('cm-url')
)
const innerText =
cmUrlSpans.length > 1
? cmUrlSpans.map(span => span.textContent).join('')
: e.target.innerText
const rawHref = innerText.trim().slice(1, -1) // get link text from markdown text
if (!rawHref) return // not checked href because parser will create file://... string for [empty link]()
const parser = document.createElement('a')
parser.href = rawHref
const { href, hash } = parser
const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
this.specialLinkHandler(target, rawHref, linkHash)
const url = this.getUrl(target)
// all special cases handled --> other case
if (url) {
e.preventDefault()
@@ -79,9 +179,11 @@
const url = this.getUrl(target)
if (url) {
if (e[modifier]) {
target.classList.add('CodeMirror-activeline-background', 'CodeMirror-hyperlink')
}
else {
target.classList.add(
'CodeMirror-activeline-background',
'CodeMirror-hyperlink'
)
} else {
target.classList.add('CodeMirror-activeline-background')
}
@@ -90,7 +192,10 @@
}
onMouseLeave(e) {
if (this.tooltip.parentElement === this.lineDiv) {
e.target.classList.remove('CodeMirror-activeline-background', 'CodeMirror-hyperlink')
e.target.classList.remove(
'CodeMirror-activeline-background',
'CodeMirror-hyperlink'
)
this.lineDiv.removeChild(this.tooltip)
}
@@ -99,8 +204,7 @@
if (this.tooltip.parentElement === this.lineDiv) {
if (e[modifier]) {
e.target.classList.add('CodeMirror-hyperlink')
}
else {
} else {
e.target.classList.remove('CodeMirror-hyperlink')
}
}
@@ -110,21 +214,20 @@
const b2 = this.lineDiv.getBoundingClientRect()
const tdiv = this.tooltip
tdiv.style.left = (b1.left - b2.left) + 'px'
tdiv.style.left = b1.left - b2.left + 'px'
this.lineDiv.appendChild(tdiv)
const b3 = tdiv.getBoundingClientRect()
const top = b1.top - b2.top - b3.height - yOffset
if (top < 0) {
tdiv.style.top = (b1.top - b2.top + b1.height + yOffset) + 'px'
}
else {
tdiv.style.top = b1.top - b2.top + b1.height + yOffset + 'px'
} else {
tdiv.style.top = top + 'px'
}
}
}
CodeMirror.defineOption('hyperlink', true, (cm) => {
CodeMirror.defineOption('hyperlink', true, cm => {
const addon = new HyperLink(cm)
})
})
})

View File

@@ -1,10 +1,20 @@
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../codemirror/lib/codemirror"), require("../codemirror/mode/gfm/gfm"), require("../codemirror/mode/yaml-frontmatter/yaml-frontmatter"))
else if (typeof define == "function" && define.amd) // AMD
define(["../codemirror/lib/codemirror", "../codemirror/mode/gfm/gfm", "../codemirror/mode/yaml-frontmatter/yaml-frontmatter"], mod)
else // Plain browser env
mod(CodeMirror)
;(function(mod) {
if (typeof exports == 'object' && typeof module == 'object')
// CommonJS
mod(
require('../codemirror/lib/codemirror'),
require('../codemirror/mode/gfm/gfm'),
require('../codemirror/mode/yaml-frontmatter/yaml-frontmatter')
)
else if (typeof define == 'function' && define.amd)
// AMD
define([
'../codemirror/lib/codemirror',
'../codemirror/mode/gfm/gfm',
'../codemirror/mode/yaml-frontmatter/yaml-frontmatter'
], mod)
// Plain browser env
else mod(CodeMirror)
})(function(CodeMirror) {
'use strict'
@@ -211,8 +221,8 @@
CodeMirror.defineMIME('text/x-bfm', 'bfm')
CodeMirror.modeInfo.push({
name: "Boost Flavored Markdown",
mime: "text/x-bfm",
mode: "bfm"
name: 'Boost Flavored Markdown',
mime: 'text/x-bfm',
mode: 'bfm'
})
})

157
extra_scripts/codemirror/mode/gfm/gfm.js vendored Normal file
View File

@@ -0,0 +1,157 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/LICENSE
;(function(mod) {
if (typeof exports == 'object' && typeof module == 'object')
// CommonJS
mod(
require('../codemirror/lib/codemirror'),
require('../codemirror/mode/markdown/markdown'),
require('../codemirror/addon/mode/overlay')
)
else if (typeof define == 'function' && define.amd)
// AMD
define([
'../codemirror/lib/codemirror',
'../codemirror/mode/markdown/markdown',
'../codemirror/addon/mode/overlay'
], mod)
// Plain browser env
else mod(CodeMirror)
})(function(CodeMirror) {
'use strict'
var urlRE = /^((?:(?:aaas?|about|acap|adiumxtra|af[ps]|aim|apt|attachment|aw|beshare|bitcoin|bolo|callto|cap|chrome(?:-extension)?|cid|coap|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-(?:playcontainer|playsingle)|dns|doi|dtn|dvb|ed2k|facetime|feed|file|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|hcp|https?|iax|icap|icon|im|imap|info|ipn|ipp|irc[6s]?|iris(?:\.beep|\.lwz|\.xpc|\.xpcs)?|itms|jar|javascript|jms|keyparc|lastfm|ldaps?|magnet|mailto|maps|market|message|mid|mms|ms-help|msnim|msrps?|mtqp|mumble|mupdate|mvn|news|nfs|nih?|nntp|notes|oid|opaquelocktoken|palm|paparazzi|platform|pop|pres|proxy|psyc|query|res(?:ource)?|rmi|rsync|rtmp|rtsp|secondlife|service|session|sftp|sgn|shttp|sieve|sips?|skype|sm[bs]|snmp|soap\.beeps?|soldat|spotify|ssh|steam|svn|teamspeak|tel(?:net)?|tftp|things|thismessage|tip|tn3270|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|view-source|webcal|wss?|wtai|wyciwyg|xcon(?:-userid)?|xfire|xmlrpc\.beeps?|xmpp|xri|ymsgr|z39\.50[rs]?):(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i
CodeMirror.defineMode(
'gfm',
function(config, modeConfig) {
var codeDepth = 0
function blankLine(state) {
state.code = false
return null
}
var gfmOverlay = {
startState: function() {
return {
code: false,
codeBlock: false,
ateSpace: false
}
},
copyState: function(s) {
return {
code: s.code,
codeBlock: s.codeBlock,
ateSpace: s.ateSpace
}
},
token: function(stream, state) {
state.combineTokens = null
// Hack to prevent formatting override inside code blocks (block and inline)
if (state.codeBlock) {
if (stream.match(/^```+/)) {
state.codeBlock = false
return null
}
stream.skipToEnd()
return null
}
if (stream.sol()) {
state.code = false
}
if (stream.sol() && stream.match(/^```+/)) {
stream.skipToEnd()
state.codeBlock = true
return null
}
// If this block is changed, it may need to be updated in Markdown mode
if (stream.peek() === '`') {
stream.next()
var before = stream.pos
stream.eatWhile('`')
var difference = 1 + stream.pos - before
if (!state.code) {
codeDepth = difference
state.code = true
} else {
if (difference === codeDepth) {
// Must be exact
state.code = false
}
}
return null
} else if (state.code) {
stream.next()
return null
}
// Check if space. If so, links can be formatted later on
if (stream.eatSpace()) {
state.ateSpace = true
return null
}
if (stream.sol() || state.ateSpace) {
state.ateSpace = false
if (modeConfig.gitHubSpice !== false) {
if (
stream.match(
/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?=.{0,6}\d)(?:[a-f0-9]{7,40}\b)/
)
) {
// User/Project@SHA
// User@SHA
// SHA
state.combineTokens = true
return 'link'
} else if (
stream.match(
/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/
)
) {
// User/Project#Num
// User#Num
// #Num
state.combineTokens = true
return 'link'
}
}
}
if (
stream.match(urlRE) &&
stream.string.slice(stream.start - 2, stream.start) != '](' &&
(stream.start == 0 ||
/\W/.test(stream.string.charAt(stream.start - 1)))
) {
// URLs
// Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
// And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
// And then limited url schemes to the CommonMark list, so foo:bar isn't matched as a URL
state.combineTokens = true
return 'link'
}
stream.next()
return null
},
blankLine: blankLine
}
var markdownConfig = {
taskLists: true,
strikethrough: true,
emoji: true
}
for (var attr in modeConfig) {
markdownConfig[attr] = modeConfig[attr]
}
markdownConfig.name = 'markdown'
return CodeMirror.overlayMode(
CodeMirror.getMode(config, markdownConfig),
gfmOverlay
)
},
'markdown'
)
CodeMirror.defineMIME('text/x-gfm', 'gfm')
})

25
extra_scripts/codemirror/theme/nord.css vendored Normal file
View File

@@ -0,0 +1,25 @@
/* Theme: nord */
.cm-s-nord.CodeMirror { color: #d8dee9; }
.cm-s-nord.CodeMirror { background: #2e3440; }
.cm-s-nord .CodeMirror-cursor { color: #d8dee9; border-color: #d8dee9; }
.cm-s-nord .CodeMirror-activeline-background { background: #434c5e52 !important; }
.cm-s-nord .CodeMirror-selected { background: undefined; }
.cm-s-nord .cm-comment { color: #4c566a; }
.cm-s-nord .cm-string { color: #a3be8c; }
.cm-s-nord .cm-string-2 { color: #8fbcbb; }
.cm-s-nord .cm-property { color: #8fbcbb; }
.cm-s-nord .cm-qualifier { color: #8fbcbb; }
.cm-s-nord .cm-tag { color: #81a1c1; }
.cm-s-nord .cm-attribute { color: #8fbcbb; }
.cm-s-nord .cm-number { color: #b48ead; }
.cm-s-nord .cm-keyword { color: #81a1c1; }
.cm-s-nord .cm-operator { color: #81a1c1; }
.cm-s-nord .cm-error { background: #bf616a; color: #d8dee9; }
.cm-s-nord .cm-invalidchar { background: #bf616a; color: #d8dee9; }
.cm-s-nord .cm-variable { color: #d8dee9; }
.cm-s-nord .cm-variable-2 { color: #8fbcbb; }
.cm-s-nord .CodeMirror-gutters {
background: #3b4252;
color: #d8dee9;
}