diff --git a/package-lock.json b/package-lock.json index 4ef47797..747df778 100644 --- a/package-lock.json +++ b/package-lock.json @@ -739,11 +739,14 @@ "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" }, "abcjs": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/abcjs/-/abcjs-5.2.0.tgz", - "integrity": "sha512-VBTgtp2esnv6RR2N6Nsa+V7VE07H/TLtUju+Orh6anud5KDfUE6eEM8OWt2oKMwKR2zsrY8Y5KyH541uyV2DEw==", + "version": "git+https://git@github.com/flxwu/abcjs.git#5842d8efd7237c7e5c82077773de112695cf973c", "requires": { "midi": "git+https://github.com/paulrosen/MIDI.js.git#e593ffef81a0350f99448e3ab8111957145ff6b2" + }, + "dependencies": { + "midi": { + "version": "git+https://github.com/paulrosen/MIDI.js.git#e593ffef81a0350f99448e3ab8111957145ff6b2" + } } }, "accepts": { @@ -11559,9 +11562,6 @@ } } }, - "midi": { - "version": "git+https://github.com/paulrosen/MIDI.js.git#e593ffef81a0350f99448e3ab8111957145ff6b2" - }, "miller-rabin": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz", diff --git a/package.json b/package.json index e44e0fc7..afc1087b 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "dependencies": { "@vue/test-utils": "^1.0.0-beta.16", - "abcjs": "^5.2.0", + "abcjs": "git+https://git@github.com/flxwu/abcjs.git", "aws-sdk": "^2.133.0", "babel-runtime": "^6.26.0", "bezier-easing": "^1.1.0", diff --git a/src/data/presets.js b/src/data/presets.js index 90cc7d9c..394f0134 100644 --- a/src/data/presets.js +++ b/src/data/presets.js @@ -1,7 +1,7 @@ const zero = { // Markdown extensions markdown: { - abbr: false, + abbr: true, breaks: false, deflist: false, del: false, @@ -28,7 +28,7 @@ const zero = { See https://abcjs.net/ */ abc: { - enabled: false, + enabled: true, }, /* Katex extension @@ -98,7 +98,7 @@ export default { enabled: true, }, abc: { - enabled: false, + enabled: true, }, }], }; diff --git a/src/extensions/abcExtension.js b/src/extensions/abcExtension.js new file mode 100644 index 00000000..de78f927 --- /dev/null +++ b/src/extensions/abcExtension.js @@ -0,0 +1,19 @@ +/* eslint-disable */ +import abcjs from 'abcjs'; +import markdownItNotesSheet from './libs/markdownItNotesSheet'; +import extensionSvc from '../services/extensionSvc'; + +const render = (elt) => { + const abcContent = elt.textContent; + elt.parentNode.parentNode.id = 'abcSheetPaper'; + abcjs.renderAbc('abcSheetPaper', abcContent, {}); +} + +extensionSvc.onGetOptions((options, properties) => { + options.abc = properties.extensions.abc.enabled; +}); + +extensionSvc.onSectionPreview((elt) => { + elt.querySelectorAll('.prism.language-abc') + .cl_each(notationElt => render(notationElt)); +}); diff --git a/src/extensions/abcNotationExtension.js b/src/extensions/abcNotationExtension.js deleted file mode 100644 index 9ae49c2b..00000000 --- a/src/extensions/abcNotationExtension.js +++ /dev/null @@ -1,23 +0,0 @@ -import abcjs from 'abcjs'; -import markdownItNotesSheet from './libs/markdownItNotesSheet'; -import extensionSvc from '../services/extensionSvc'; - -let abc; - -extensionSvc.onGetOptions((options, properties) => { - options.abc = properties.extensions.abc.enabled; -}); - -extensionSvc.onInitConverter(2, (markdown, options) => { - if (options.abc) { - markdown.use(markdownItNotesSheet, (val) => { - abc = val; - }); - } -}); - -extensionSvc.onSectionPreview(() => { - if (document.querySelector('#abcSheetPaper') != null && abc != null) { - abcjs.renderAbc('abcSheetPaper', abc, {}); - } -}); diff --git a/src/extensions/index.js b/src/extensions/index.js index 6262ce20..347b3967 100644 --- a/src/extensions/index.js +++ b/src/extensions/index.js @@ -1,5 +1,5 @@ import './emojiExtension'; -import './abcNotationExtension'; +import './abcExtension'; import './katexExtension'; import './markdownExtension'; import './mermaidExtension'; diff --git a/src/extensions/libs/markdownItNotesSheet.js b/src/extensions/libs/markdownItNotesSheet.js deleted file mode 100644 index dd324c57..00000000 --- a/src/extensions/libs/markdownItNotesSheet.js +++ /dev/null @@ -1,124 +0,0 @@ -/* eslint-disable no-continue */ - -// a constant to hold the abc string -const abc = []; -// the callBack given from abcNotationExtension.js -// to pass the abc string up to a point -// where the DOM is already rendered -let callbackFunc; - -function abcNotation(state, startLine, endLine, silent) { - const validateParams = params => params.trim().match(/^abc$/); - let nextLine; - let autoClosed = false; - - let start = state.bMarks[startLine] + state.tShift[startLine]; - let max = state.eMarks[startLine]; - - // Check out the first character quickly, - // this filters out all non-codeblocks - const marker = state.src.charCodeAt(start); - if (marker !== 0x7e /* ~ */ && marker !== 0x60 /* ` */) { - return false; - } - - // Check out the rest of the marker string - const markerStart = start; - start = state.skipChars(start, marker); - const markerLength = start - markerStart; - if (markerLength < 3) { - return false; - } - - const markup = state.src.slice(markerLength, start); - const params = state.src.slice(start, max); - if (!validateParams(params)) { - return false; - } - - // Since start is found, we can report success here in validation mode - if (silent) { - return true; - } - - // Search for the end of the block - nextLine = startLine; - - for (;;) { - nextLine += 1; - if (nextLine >= endLine) { - // unclosed block should be autoclosed by end of document. - // also block seems to be autoclosed by end of parent - break; - } - - start = state.bMarks[nextLine] + state.tShift[nextLine]; - max = state.eMarks[nextLine]; - - if (start < max && state.sCount[nextLine] < state.blkIndent) { - // non-empty line with negative indent should stop the list: - // - ``` - // test - break; - } - - if (marker !== state.src.charCodeAt(start)) { - continue; - } - - if (state.sCount[nextLine] - state.blkIndent >= 4) { - // closing fence should be indented less than 4 spaces - continue; - } - - start = state.skipChars(start, marker); - // closing fence must be at least as long as the opening one - if (start - markerStart < markerLength) { - continue; - } - - // make sure tail has spaces only - start = state.skipSpaces(start); - if (start < max) { - continue; - } - - autoClosed = true; - // found! - break; - } - - const oldParent = state.parentType; - const oldLineMax = state.lineMax; - state.parentType = 'container'; - - // If a fence has heading spaces, they should be removed from its inner block - // markerLength = state.sCount[startLine]; - - // this will prevent lazy continuations from ever going past our end marker - state.lineMax = nextLine; - - const token = state.push('fence_abc_open', 'div', 1); - token.info = params; - token.markup = markup; - token.block = true; - token.map = [startLine, nextLine]; - - abc.push(state.getLines(startLine + 1, nextLine, markerLength, true)); - - state.parentType = oldParent; - state.lineMax = oldLineMax; - state.line = nextLine + (autoClosed ? 1 : 0); - - callbackFunc(abc[0]); - return true; -} - -export default (md, callback) => { - callbackFunc = callback; - md.block.ruler.before('fence', 'fence_abc', abcNotation); - md.renderer.rules.fence_abc_open = (tokens, idx, _options, env, self) => { - tokens[idx].attrPush(['id', 'abcSheetPaper']); - return self.renderToken(tokens, idx, _options, env, self); - }; -};