From aba2aec0d0d8ac87f312d39f600e3ec7bbf1c7c9 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Fri, 22 Sep 2017 10:07:10 +0800 Subject: [PATCH] chore: prettier code --- app.js | 20 +- build/build-cover.js | 5 +- build/build-css.js | 27 +- build/build-ssr.js | 2 +- packages/docsify-server-renderer/index.js | 22 +- src/core/config.js | 57 +- src/core/event/scroll.js | 31 +- src/core/event/sidebar.js | 31 +- src/core/fetch/ajax.js | 14 +- src/core/init/lifecycle.js | 2 +- src/core/render/slugify.js | 6 +- src/core/render/tpl.js | 52 +- src/core/router/history/base.js | 12 +- src/core/router/history/hash.js | 8 +- src/core/router/history/html5.js | 4 +- src/core/router/util.js | 16 +- src/core/util/core.js | 22 +- src/core/util/env.js | 22 +- src/core/util/polyfill/css-vars.js | 11 +- src/plugins/emoji.js | 1039 ++++++++++++++++++--- src/plugins/front-matter/parser.js | 11 +- src/plugins/front-matter/yaml.js | 703 +++++++------- src/plugins/ga.js | 8 +- src/plugins/search/component.js | 10 +- src/themes/basic/_coverpage.css | 8 +- src/themes/basic/_layout.css | 75 +- src/themes/buble.css | 13 +- src/themes/dark.css | 17 +- src/themes/pure.css | 4 +- src/themes/vue.css | 15 +- 30 files changed, 1533 insertions(+), 734 deletions(-) diff --git a/app.js b/app.js index 7fe13919..63f80f7e 100644 --- a/app.js +++ b/app.js @@ -30,22 +30,24 @@ var renderer = new Renderer({ alias: { '/de-de/changelog': '/changelog', '/zh-cn/changelog': '/changelog', - '/changelog': 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG' + '/changelog': + 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG' } }, path: './' }) -http.createServer(function (req, res) { - serveStatic('.')(req, res, function () { - // TEST SSR - // renderer.renderToString(req.url) +http + .createServer(function (req, res) { + serveStatic('.')(req, res, function () { + // TEST SSR + // renderer.renderToString(req.url) // .then(html => res.end(html)) - res.writeHead(404, { 'Content-Type': 'text/html' }) - res.end(fs.readFileSync('dev.html')) + res.writeHead(404, { 'Content-Type': 'text/html' }) + res.end(fs.readFileSync('dev.html')) + }) }) -}).listen(3000, '0.0.0.0') + .listen(3000, '0.0.0.0') console.log(`\nListening at http://0.0.0.0:3000\n`) - diff --git a/build/build-cover.js b/build/build-cover.js index f66fa8d6..fbd27f74 100644 --- a/build/build-cover.js +++ b/build/build-cover.js @@ -7,5 +7,8 @@ var file = __dirname + '/../docs/_coverpage.md' var cover = read(file, 'utf8').toString() console.log('Replace version number in cover page...') -cover = cover.replace(/(\S+)?<\/small>/g, '' + version + '') +cover = cover.replace( + /(\S+)?<\/small>/g, + '' + version + '' +) write(file, cover) diff --git a/build/build-css.js b/build/build-css.js index 40672e05..b1b239e7 100644 --- a/build/build-css.js +++ b/build/build-css.js @@ -4,15 +4,17 @@ var resolve = require('path').resolve var postcss = require('postcss') var isProd = process.argv[process.argv.length - 1] !== '--dev' -var processor = postcss([require('postcss-salad')({ - features: { - precss: { - properties: { - preserve: true +var processor = postcss([ + require('postcss-salad')({ + features: { + precss: { + properties: { + preserve: true + } } } - } -})]) + }) +]) var saveMin = function (file, content) { fs.writeFileSync(resolve(__dirname, '../lib/themes/', file), content) @@ -31,17 +33,18 @@ var list = fs.readdirSync(resolve(__dirname, '../src/themes')) list.forEach(function (file) { if (!/\.css$/.test(file)) return - processor.process(load(file), { from: resolve(__dirname, '../src/themes/', file) }) + processor + .process(load(file), { from: resolve(__dirname, '../src/themes/', file) }) .then(function (result) { save(file, result.css) console.log('salad - ' + file) - isProd && cssnano(loadLib(file)) - .then(function (result) { + isProd && + cssnano(loadLib(file)).then(function (result) { saveMin(file, result.css) console.log('cssnao - ' + file) }) - }).catch(function (err) { + }) + .catch(function (err) { console.log(err) }) }) - diff --git a/build/build-ssr.js b/build/build-ssr.js index a470f656..1000582d 100644 --- a/build/build-ssr.js +++ b/build/build-ssr.js @@ -17,7 +17,7 @@ rollup } }) ], - onwarn: function() {} + onwarn: function () {} }) .then(function (bundle) { var dest = 'packages/docsify-server-renderer/build.js' diff --git a/packages/docsify-server-renderer/index.js b/packages/docsify-server-renderer/index.js index 3ee0a3d4..a885f9bf 100644 --- a/packages/docsify-server-renderer/index.js +++ b/packages/docsify-server-renderer/index.js @@ -13,7 +13,9 @@ function cwd (...args) { } function mainTpl (config) { - let html = `` + let html = `` if (config.repo) { html += tpl.corner(config.repo) @@ -28,11 +30,7 @@ function mainTpl (config) { } export default class Renderer { - constructor ({ - template, - config, - cache - }) { + constructor ({ template, config, cache }) { this.html = template this.config = config = Object.assign({}, config, { routerMode: 'history' @@ -43,7 +41,10 @@ export default class Renderer { this.compiler = new Compiler(config, this.router) this.router.getCurrentPath = () => this.url - this._renderHtml('inject-config', ``) + this._renderHtml( + 'inject-config', + `` + ) this._renderHtml('inject-app', mainTpl(config)) this.template = this.html @@ -52,9 +53,7 @@ export default class Renderer { _getPath (url) { const file = this.router.getFile(url) - return isAbsolutePath(file) - ? file - : cwd(`./${file}`) + return isAbsolutePath(file) ? file : cwd(`./${file}`) } async renderToString (url) { @@ -94,7 +93,8 @@ export default class Renderer { switch (type) { case 'sidebar': - html = this.compiler.sidebar(html, maxLevel) + + html = + this.compiler.sidebar(html, maxLevel) + `` diff --git a/src/core/config.js b/src/core/config.js index 0d0bc173..c4262577 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -1,32 +1,37 @@ import { merge, hyphenate, isPrimitive } from './util/core' -const config = merge({ - el: '#app', - repo: '', - maxLevel: 6, - subMaxLevel: 0, - loadSidebar: null, - loadNavbar: null, - homepage: 'README.md', - coverpage: '', - basePath: '', - auto2top: false, - name: '', - themeColor: '', - nameLink: window.location.pathname, - autoHeader: false, - executeScript: null, - noEmoji: false, - ga: '', - mergeNavbar: false, - formatUpdated: '', - externalLinkTarget: '_blank', - routerMode: 'hash', - noCompileLinks: [] -}, window.$docsify) +const config = merge( + { + el: '#app', + repo: '', + maxLevel: 6, + subMaxLevel: 0, + loadSidebar: null, + loadNavbar: null, + homepage: 'README.md', + coverpage: '', + basePath: '', + auto2top: false, + name: '', + themeColor: '', + nameLink: window.location.pathname, + autoHeader: false, + executeScript: null, + noEmoji: false, + ga: '', + mergeNavbar: false, + formatUpdated: '', + externalLinkTarget: '_blank', + routerMode: 'hash', + noCompileLinks: [] + }, + window.$docsify +) -const script = document.currentScript || - [].slice.call(document.getElementsByTagName('script')) +const script = + document.currentScript || + [].slice + .call(document.getElementsByTagName('script')) .filter(n => /docsify\./.test(n.src))[0] if (script) { diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index 2e326425..bba7aecb 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -16,9 +16,12 @@ function scrollTo (el) { end: el.getBoundingClientRect().top + window.scrollY, duration: 500 }) - .on('tick', v => window.scrollTo(0, v)) - .on('done', () => { enableScrollEvent = true; scroller = null }) - .begin() + .on('tick', v => window.scrollTo(0, v)) + .on('done', () => { + enableScrollEvent = true + scroller = null + }) + .begin() } function highlight () { @@ -28,7 +31,7 @@ function highlight () { const wrap = dom.find(sidebar, '.sidebar-nav') let active = dom.find(sidebar, 'li.active') const doc = document.documentElement - const top = (doc && doc.scrollTop || document.body.scrollTop) - coverHeight + const top = ((doc && doc.scrollTop) || document.body.scrollTop) - coverHeight let last for (let i = 0, len = anchors.length; i < len; i += 1) { @@ -56,16 +59,10 @@ function highlight () { const height = sidebar.clientHeight const curOffset = 0 const cur = active.offsetTop + active.clientHeight + 40 - const isInView = ( - active.offsetTop >= wrap.scrollTop && - cur <= wrap.scrollTop + height - ) + const isInView = + active.offsetTop >= wrap.scrollTop && cur <= wrap.scrollTop + height const notThan = cur - curOffset < height - const top = isInView - ? wrap.scrollTop - : notThan - ? curOffset - : cur - height + const top = isInView ? wrap.scrollTop : notThan ? curOffset : cur - height sidebar.scrollTop = top } @@ -95,8 +92,12 @@ export function scrollActiveSidebar (router) { dom.off('scroll', highlight) dom.on('scroll', highlight) - dom.on(sidebar, 'mouseover', () => { hoverOver = true }) - dom.on(sidebar, 'mouseleave', () => { hoverOver = false }) + dom.on(sidebar, 'mouseover', () => { + hoverOver = true + }) + dom.on(sidebar, 'mouseleave', () => { + hoverOver = false + }) } export function scrollIntoView (id) { diff --git a/src/core/event/sidebar.js b/src/core/event/sidebar.js index d977743e..7a20d7aa 100644 --- a/src/core/event/sidebar.js +++ b/src/core/event/sidebar.js @@ -16,9 +16,12 @@ export function btn (el, router) { const sidebar = dom.getNode('.sidebar') - isMobile && dom.on(dom.body, 'click', _ => - dom.body.classList.contains('close') && toggle() - ) + isMobile && + dom.on( + dom.body, + 'click', + _ => dom.body.classList.contains('close') && toggle() + ) dom.on(sidebar, 'click', _ => setTimeout((_ => getAndActive(router, sidebar, true, true), 0)) ) @@ -51,19 +54,17 @@ export function getAndActive (router, el, isParent, autoTitle) { const hash = router.toURL(router.getCurrentPath()) let target - links - .sort((a, b) => b.href.length - a.href.length) - .forEach(a => { - const href = a.getAttribute('href') - const node = isParent ? a.parentNode : a + links.sort((a, b) => b.href.length - a.href.length).forEach(a => { + const href = a.getAttribute('href') + const node = isParent ? a.parentNode : a - if (hash.indexOf(href) === 0 && !target) { - target = a - dom.toggleClass(node, 'add', 'active') - } else { - dom.toggleClass(node, 'remove', 'active') - } - }) + if (hash.indexOf(href) === 0 && !target) { + target = a + dom.toggleClass(node, 'add', 'active') + } else { + dom.toggleClass(node, 'remove', 'active') + } + }) if (autoTitle) { dom.$.title = target ? `${target.innerText} - ${title}` : title diff --git a/src/core/fetch/ajax.js b/src/core/fetch/ajax.js index 1824cc45..28d66444 100644 --- a/src/core/fetch/ajax.js +++ b/src/core/fetch/ajax.js @@ -26,9 +26,13 @@ export function get (url, hasBar = false) { return { then: function (success, error = noop) { if (hasBar) { - const id = setInterval(_ => progressbar({ - step: Math.floor(Math.random() * 5 + 1) - }), 500) + const id = setInterval( + _ => + progressbar({ + step: Math.floor(Math.random() * 5 + 1) + }), + 500 + ) on('progress', progressbar) on('loadend', evt => { @@ -42,12 +46,12 @@ export function get (url, hasBar = false) { if (target.status >= 400) { error(target) } else { - const result = cache[url] = { + const result = (cache[url] = { content: target.response, opt: { updatedAt: xhr.getResponseHeader('last-modified') } - } + }) success(result.content, result.opt) } diff --git a/src/core/init/lifecycle.js b/src/core/init/lifecycle.js index d8749619..93605f69 100644 --- a/src/core/init/lifecycle.js +++ b/src/core/init/lifecycle.js @@ -13,7 +13,7 @@ export function initLifecycle (vm) { vm._hooks = {} vm._lifecycle = {} hooks.forEach(hook => { - const arr = vm._hooks[hook] = [] + const arr = (vm._hooks[hook] = []) vm._lifecycle[hook] = fn => arr.push(fn) }) } diff --git a/src/core/render/slugify.js b/src/core/render/slugify.js index bb34758a..e37318f4 100644 --- a/src/core/render/slugify.js +++ b/src/core/render/slugify.js @@ -4,7 +4,9 @@ const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,.\/:;<=>?@\[\]^`{|}~]/g export function slugify (str) { if (typeof str !== 'string') return '' - let slug = str.toLowerCase().trim() + let slug = str + .toLowerCase() + .trim() .replace(/<[^>\d]+>/g, '') .replace(re, '') .replace(/\s/g, '-') @@ -12,7 +14,7 @@ export function slugify (str) { .replace(/^(\d)/, '_$1') let count = cache[slug] - count = cache.hasOwnProperty(slug) ? (count + 1) : 0 + count = cache.hasOwnProperty(slug) ? count + 1 : 0 cache[slug] = count if (count) { diff --git a/src/core/render/tpl.js b/src/core/render/tpl.js index cc24c7be..76bf14f9 100644 --- a/src/core/render/tpl.js +++ b/src/core/render/tpl.js @@ -10,37 +10,40 @@ export function corner (data) { data = data.replace(/^git\+/, '') return ( - `` + + `` + '' + - '') + '' + ) } /** * Render main content */ export function main (config) { - const aside = ( + const aside = '' + '') + (config.name + ? `

${config.name}

` + : '') + + '' + + '' - return (isMobile ? `${aside}
` : `
${aside}`) + - '
' + - '
' + - '
' + + return ( + (isMobile ? `${aside}
` : `
${aside}`) + + '
' + + '
' + + '
' + '
' + ) } /** @@ -48,14 +51,17 @@ export function main (config) { */ export function cover () { const SL = ', 100%, 85%' - const bgc = 'linear-gradient(to left bottom, ' + - `hsl(${Math.floor(Math.random() * 255) + SL}) 0%,` + - `hsl(${Math.floor(Math.random() * 255) + SL}) 100%)` + const bgc = + 'linear-gradient(to left bottom, ' + + `hsl(${Math.floor(Math.random() * 255) + SL}) 0%,` + + `hsl(${Math.floor(Math.random() * 255) + SL}) 100%)` - return `
` + + return ( + `
` + '
' + '
' + - '
' + '
' + ) } /** diff --git a/src/core/router/history/base.js b/src/core/router/history/base.js index 81cccf3f..055073b6 100644 --- a/src/core/router/history/base.js +++ b/src/core/router/history/base.js @@ -4,20 +4,20 @@ import { noop } from '../../util/core' const cached = {} function getAlias (path, alias, last) { - const match = Object.keys(alias).filter((key) => { + const match = Object.keys(alias).filter(key => { const re = cached[key] || (cached[key] = new RegExp(`^${key}$`)) return re.test(path) && path !== last })[0] - return match ? getAlias(path.replace(cached[match], alias[match]), alias, path) : path + return match + ? getAlias(path.replace(cached[match], alias[match]), alias, path) + : path } function getFileName (path) { return /\.(md|html)$/g.test(path) ? path - : /\/$/g.test(path) - ? `${path}README.md` - : `${path}.md` + : /\/$/g.test(path) ? `${path}README.md` : `${path}.md` } export class History { @@ -37,7 +37,7 @@ export class History { path = config.alias ? getAlias(path, config.alias) : path path = getFileName(path) - path = path === '/README.md' ? (config.homepage || path) : path + path = path === '/README.md' ? config.homepage || path : path path = isAbsolutePath(path) ? path : getPath(base, path) if (isRelative) { diff --git a/src/core/router/history/hash.js b/src/core/router/history/hash.js index 0130943d..ce8335a4 100644 --- a/src/core/router/history/hash.js +++ b/src/core/router/history/hash.js @@ -5,9 +5,7 @@ import { parseQuery, stringifyQuery, cleanPath } from '../util' function replaceHash (path) { const i = location.href.indexOf('#') - location.replace( - location.href.slice(0, i >= 0 ? i : 0) + '#' + path - ) + location.replace(location.href.slice(0, i >= 0 ? i : 0) + '#' + path) } const replaceSlug = cached(path => { @@ -24,9 +22,7 @@ export class HashHistory extends History { const path = window.location.pathname || '' const base = this.config.basePath - return /^(\/|https?:)/g.test(base) - ? base - : cleanPath(path + '/' + base) + return /^(\/|https?:)/g.test(base) ? base : cleanPath(path + '/' + base) } getCurrentPath () { diff --git a/src/core/router/history/html5.js b/src/core/router/history/html5.js index 89cc7000..7747a447 100644 --- a/src/core/router/history/html5.js +++ b/src/core/router/history/html5.js @@ -22,9 +22,7 @@ export class HTML5History extends History { onchange (cb = noop) { on('click', e => { - const el = e.target.tagName === 'A' - ? e.target - : e.target.parentNode + const el = e.target.tagName === 'A' ? e.target : e.target.parentNode if (el.tagName === 'A' && !/_blank/.test(el.target)) { e.preventDefault() diff --git a/src/core/router/util.js b/src/core/router/util.js index 80cc5070..141ebe2a 100644 --- a/src/core/router/util.js +++ b/src/core/router/util.js @@ -26,9 +26,11 @@ export function stringifyQuery (obj) { const qs = [] for (const key in obj) { - qs.push(obj[key] - ? `${encode(key)}=${encode(obj[key])}`.toLowerCase() - : encode(key)) + qs.push( + obj[key] + ? `${encode(key)}=${encode(obj[key])}`.toLowerCase() + : encode(key) + ) } return qs.length ? `?${qs.join('&')}` : '' @@ -45,13 +47,9 @@ export const isAbsolutePath = cached(path => { export const getParentPath = cached(path => { return /\/$/g.test(path) ? path - : (path = path.match(/(\S*\/)[^\/]+$/)) - ? path[1] - : '' + : (path = path.match(/(\S*\/)[^\/]+$/)) ? path[1] : '' }) export const cleanPath = cached(path => { - return path - .replace(/^\/+/, '/') - .replace(/([^:])\/{2,}/g, '$1/') + return path.replace(/^\/+/, '/').replace(/([^:])\/{2,}/g, '$1/') }) diff --git a/src/core/util/core.js b/src/core/util/core.js index 5a153b84..e3a520bc 100644 --- a/src/core/util/core.js +++ b/src/core/util/core.js @@ -19,21 +19,23 @@ export const hyphenate = cached(str => { /** * Simple Object.assign polyfill */ -export const merge = Object.assign || function (to) { - const hasOwn = Object.prototype.hasOwnProperty +export const merge = + Object.assign || + function (to) { + const hasOwn = Object.prototype.hasOwnProperty - for (let i = 1; i < arguments.length; i++) { - const from = Object(arguments[i]) + for (let i = 1; i < arguments.length; i++) { + const from = Object(arguments[i]) - for (const key in from) { - if (hasOwn.call(from, key)) { - to[key] = from[key] + for (const key in from) { + if (hasOwn.call(from, key)) { + to[key] = from[key] + } } } - } - return to -} + return to + } /** * Check if value is primitive diff --git a/src/core/util/env.js b/src/core/util/env.js index dbb8b3b8..a385edd5 100644 --- a/src/core/util/env.js +++ b/src/core/util/env.js @@ -5,11 +5,17 @@ export const isMobile = inBrowser && document.body.clientWidth <= 600 /** * @see https://github.com/MoOx/pjax/blob/master/lib/is-supported.js */ -export const supportsPushState = inBrowser && (function () { - // Borrowed wholesale from https://github.com/defunkt/jquery-pjax - return window.history && - window.history.pushState && - window.history.replaceState && - // pushState isn’t reliable on iOS until 5. - !navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]\D|WebApps\/.+CFNetwork)/) -})() +export const supportsPushState = + inBrowser && + (function () { + // Borrowed wholesale from https://github.com/defunkt/jquery-pjax + return ( + window.history && + window.history.pushState && + window.history.replaceState && + // pushState isn’t reliable on iOS until 5. + !navigator.userAgent.match( + /((iPod|iPhone|iPad).+\bOS\s+[1-4]\D|WebApps\/.+CFNetwork)/ + ) + ) + })() diff --git a/src/core/util/polyfill/css-vars.js b/src/core/util/polyfill/css-vars.js index bb8e4986..96fcb6e0 100644 --- a/src/core/util/polyfill/css-vars.js +++ b/src/core/util/polyfill/css-vars.js @@ -2,18 +2,17 @@ import * as dom from '../dom' import { get } from '../../fetch/ajax' function replaceVar (block, color) { - block.innerHTML = block.innerHTML - .replace(/var\(\s*--theme-color.*?\)/g, color) + block.innerHTML = block.innerHTML.replace( + /var\(\s*--theme-color.*?\)/g, + color + ) } export default function (color) { // Variable support - if (window.CSS && - window.CSS.supports && - window.CSS.supports('(--v:red)')) return + if (window.CSS && window.CSS.supports && window.CSS.supports('(--v:red)')) { return } const styleBlocks = dom.findAll('style:not(.inserted),link') - ;[].forEach.call(styleBlocks, block => { if (block.nodeName === 'STYLE') { replaceVar(block, color) diff --git a/src/plugins/emoji.js b/src/plugins/emoji.js index 9b71c65e..be4da547 100644 --- a/src/plugins/emoji.js +++ b/src/plugins/emoji.js @@ -1,153 +1,900 @@ -const AllGithubEmoji = ['+1', '100', '1234', '8ball', 'a', 'ab', 'abc', 'abcd', - 'accept', 'aerial_tramway', 'airplane', 'alarm_clock', 'alien', 'ambulance', - 'anchor', 'angel', 'anger', 'angry', 'anguished', 'ant', 'apple', 'aquarius', - 'aries', 'arrow_backward', 'arrow_double_down', 'arrow_double_up', 'arrow_down', - 'arrow_down_small', 'arrow_forward', 'arrow_heading_down', 'arrow_heading_up', - 'arrow_left', 'arrow_lower_left', 'arrow_lower_right', 'arrow_right', - 'arrow_right_hook', 'arrow_up', 'arrow_up_down', 'arrow_up_small', 'arrow_upper_left', - 'arrow_upper_right', 'arrows_clockwise', 'arrows_counterclockwise', 'art', - 'articulated_lorry', 'astonished', 'athletic_shoe', 'atm', 'b', 'baby', 'baby_bottle', - 'baby_chick', 'baby_symbol', 'back', 'baggage_claim', 'balloon', 'ballot_box_with_check', - 'bamboo', 'banana', 'bangbang', 'bank', 'bar_chart', 'barber', 'baseball', 'basketball', - 'bath', 'bathtub', 'battery', 'bear', 'bee', 'beer', 'beers', 'beetle', 'beginner', - 'bell', 'bento', 'bicyclist', 'bike', 'bikini', 'bird', 'birthday', 'black_circle', - 'black_joker', 'black_large_square', 'black_medium_small_square', 'black_medium_square', - 'black_nib', 'black_small_square', 'black_square_button', 'blossom', 'blowfish', - 'blue_book', 'blue_car', 'blue_heart', 'blush', 'boar', 'boat', 'bomb', 'book', - 'bookmark', 'bookmark_tabs', 'books', 'boom', 'boot', 'bouquet', 'bow', 'bowling', - 'bowtie', 'boy', 'bread', 'bride_with_veil', 'bridge_at_night', 'briefcase', - 'broken_heart', 'bug', 'bulb', 'bullettrain_front', 'bullettrain_side', 'bus', - 'busstop', 'bust_in_silhouette', 'busts_in_silhouette', 'cactus', 'cake', 'calendar', - 'calling', 'camel', 'camera', 'cancer', 'candy', 'capital_abcd', 'capricorn', 'car', - 'card_index', 'carousel_horse', 'cat', 'cat2', 'cd', 'chart', 'chart_with_downwards_trend', - 'chart_with_upwards_trend', 'checkered_flag', 'cherries', 'cherry_blossom', 'chestnut', - 'chicken', 'children_crossing', 'chocolate_bar', 'christmas_tree', 'church', 'cinema', - 'circus_tent', 'city_sunrise', 'city_sunset', 'cl', 'clap', 'clapper', 'clipboard', - 'clock1', 'clock10', 'clock1030', 'clock11', 'clock1130', 'clock12', 'clock1230', - 'clock130', 'clock2', 'clock230', 'clock3', 'clock330', 'clock4', 'clock430', - 'clock5', 'clock530', 'clock6', 'clock630', 'clock7', 'clock730', 'clock8', 'clock830', - 'clock9', 'clock930', 'closed_book', 'closed_lock_with_key', 'closed_umbrella', - 'cloud', 'clubs', 'cn', 'cocktail', 'coffee', 'cold_sweat', 'collision', 'computer', - 'confetti_ball', 'confounded', 'confused', 'congratulations', 'construction', - 'construction_worker', 'convenience_store', 'cookie', 'cool', 'cop', 'copyright', - 'corn', 'couple', 'couple_with_heart', 'couplekiss', 'cow', 'cow2', 'credit_card', - 'crescent_moon', 'crocodile', 'crossed_flags', 'crown', 'cry', 'crying_cat_face', - 'crystal_ball', 'cupid', 'curly_loop', 'currency_exchange', 'curry', 'custard', - 'customs', 'cyclone', 'dancer', 'dancers', 'dango', 'dart', 'dash', 'date', 'de', - 'deciduous_tree', 'department_store', 'diamond_shape_with_a_dot_inside', 'diamonds', - 'disappointed', 'disappointed_relieved', 'dizzy', 'dizzy_face', 'do_not_litter', - 'dog', 'dog2', 'dollar', 'dolls', 'dolphin', 'door', 'doughnut', 'dragon', - 'dragon_face', 'dress', 'dromedary_camel', 'droplet', 'dvd', 'e-mail', 'ear', - 'ear_of_rice', 'earth_africa', 'earth_americas', 'earth_asia', 'egg', 'eggplant', - 'eight', 'eight_pointed_black_star', 'eight_spoked_asterisk', 'electric_plug', - 'elephant', 'email', 'end', 'envelope', 'envelope_with_arrow', 'es', 'euro', - 'european_castle', 'european_post_office', 'evergreen_tree', 'exclamation', - 'expressionless', 'eyeglasses', 'eyes', 'facepunch', 'factory', 'fallen_leaf', - 'family', 'fast_forward', 'fax', 'fearful', 'feelsgood', 'feet', 'ferris_wheel', - 'file_folder', 'finnadie', 'fire', 'fire_engine', 'fireworks', 'first_quarter_moon', - 'first_quarter_moon_with_face', 'fish', 'fish_cake', 'fishing_pole_and_fish', - 'fist', 'five', 'flags', 'flashlight', 'flipper', 'floppy_disk', 'flower_playing_cards', - 'flushed', 'foggy', 'football', 'footprints', 'fork_and_knife', 'fountain', - 'four', 'four_leaf_clover', 'fr', 'free', 'fried_shrimp', 'fries', 'frog', - 'frowning', 'fu', 'fuelpump', 'full_moon', 'full_moon_with_face', 'game_die', - 'gb', 'gem', 'gemini', 'ghost', 'gift', 'gift_heart', 'girl', 'globe_with_meridians', - 'goat', 'goberserk', 'godmode', 'golf', 'grapes', 'green_apple', 'green_book', - 'green_heart', 'grey_exclamation', 'grey_question', 'grimacing', 'grin', - 'grinning', 'guardsman', 'guitar', 'gun', 'haircut', 'hamburger', 'hammer', - 'hamster', 'hand', 'handbag', 'hankey', 'hash', 'hatched_chick', 'hatching_chick', - 'headphones', 'hear_no_evil', 'heart', 'heart_decoration', 'heart_eyes', - 'heart_eyes_cat', 'heartbeat', 'heartpulse', 'hearts', 'heavy_check_mark', - 'heavy_division_sign', 'heavy_dollar_sign', 'heavy_exclamation_mark', 'heavy_minus_sign', - 'heavy_multiplication_x', 'heavy_plus_sign', 'helicopter', 'herb', 'hibiscus', - 'high_brightness', 'high_heel', 'hocho', 'honey_pot', 'honeybee', 'horse', - 'horse_racing', 'hospital', 'hotel', 'hotsprings', 'hourglass', 'hourglass_flowing_sand', - 'house', 'house_with_garden', 'hurtrealbad', 'hushed', 'ice_cream', 'icecream', - 'id', 'ideograph_advantage', 'imp', 'inbox_tray', 'incoming_envelope', - 'information_desk_person', 'information_source', 'innocent', 'interrobang', - 'iphone', 'it', 'izakaya_lantern', 'jack_o_lantern', 'japan', 'japanese_castle', - 'japanese_goblin', 'japanese_ogre', 'jeans', 'joy', 'joy_cat', 'jp', 'key', - 'keycap_ten', 'kimono', 'kiss', 'kissing', 'kissing_cat', 'kissing_closed_eyes', - 'kissing_heart', 'kissing_smiling_eyes', 'koala', 'koko', 'kr', 'lantern', - 'large_blue_circle', 'large_blue_diamond', 'large_orange_diamond', 'last_quarter_moon', - 'last_quarter_moon_with_face', 'laughing', 'leaves', 'ledger', 'left_luggage', - 'left_right_arrow', 'leftwards_arrow_with_hook', 'lemon', 'leo', 'leopard', - 'libra', 'light_rail', 'link', 'lips', 'lipstick', 'lock', 'lock_with_ink_pen', - 'lollipop', 'loop', 'loud_sound', 'loudspeaker', 'love_hotel', 'love_letter', - 'low_brightness', 'm', 'mag', 'mag_right', 'mahjong', 'mailbox', 'mailbox_closed', - 'mailbox_with_mail', 'mailbox_with_no_mail', 'man', 'man_with_gua_pi_mao', - 'man_with_turban', 'mans_shoe', 'maple_leaf', 'mask', 'massage', 'meat_on_bone', - 'mega', 'melon', 'memo', 'mens', 'metal', 'metro', 'microphone', 'microscope', - 'milky_way', 'minibus', 'minidisc', 'mobile_phone_off', 'money_with_wings', - 'moneybag', 'monkey', 'monkey_face', 'monorail', 'moon', 'mortar_board', 'mount_fuji', - 'mountain_bicyclist', 'mountain_cableway', 'mountain_railway', 'mouse', 'mouse2', - 'movie_camera', 'moyai', 'muscle', 'mushroom', 'musical_keyboard', 'musical_note', - 'musical_score', 'mute', 'nail_care', 'name_badge', 'neckbeard', 'necktie', - 'negative_squared_cross_mark', 'neutral_face', 'new', 'new_moon', 'new_moon_with_face', - 'newspaper', 'ng', 'night_with_stars', 'nine', 'no_bell', 'no_bicycles', 'no_entry', - 'no_entry_sign', 'no_good', 'no_mobile_phones', 'no_mouth', 'no_pedestrians', - 'no_smoking', 'non-potable_water', 'nose', 'notebook', 'notebook_with_decorative_cover', - 'notes', 'nut_and_bolt', 'o', 'o2', 'ocean', 'octocat', 'octopus', 'oden', 'office', - 'ok', 'ok_hand', 'ok_woman', 'older_man', 'older_woman', 'on', 'oncoming_automobile', - 'oncoming_bus', 'oncoming_police_car', 'oncoming_taxi', 'one', 'open_book', - 'open_file_folder', 'open_hands', 'open_mouth', 'ophiuchus', 'orange_book', - 'outbox_tray', 'ox', 'package', 'page_facing_up', 'page_with_curl', 'pager', - 'palm_tree', 'panda_face', 'paperclip', 'parking', 'part_alternation_mark', - 'partly_sunny', 'passport_control', 'paw_prints', 'peach', 'pear', 'pencil', - 'pencil2', 'penguin', 'pensive', 'performing_arts', 'persevere', 'person_frowning', - 'person_with_blond_hair', 'person_with_pouting_face', 'phone', 'pig', 'pig2', - 'pig_nose', 'pill', 'pineapple', 'pisces', 'pizza', 'point_down', 'point_left', - 'point_right', 'point_up', 'point_up_2', 'police_car', 'poodle', 'poop', - 'post_office', 'postal_horn', 'postbox', 'potable_water', 'pouch', 'poultry_leg', - 'pound', 'pouting_cat', 'pray', 'princess', 'punch', 'purple_heart', 'purse', - 'pushpin', 'put_litter_in_its_place', 'question', 'rabbit', 'rabbit2', 'racehorse', - 'radio', 'radio_button', 'rage', 'rage1', 'rage2', 'rage3', 'rage4', 'railway_car', - 'rainbow', 'raised_hand', 'raised_hands', 'raising_hand', 'ram', 'ramen', 'rat', - 'recycle', 'red_car', 'red_circle', 'registered', 'relaxed', 'relieved', 'repeat', - 'repeat_one', 'restroom', 'revolving_hearts', 'rewind', 'ribbon', 'rice', - 'rice_ball', 'rice_cracker', 'rice_scene', 'ring', 'rocket', 'roller_coaster', - 'rooster', 'rose', 'rotating_light', 'round_pushpin', 'rowboat', 'ru', 'rugby_football', - 'runner', 'running', 'running_shirt_with_sash', 'sa', 'sagittarius', 'sailboat', - 'sake', 'sandal', 'santa', 'satellite', 'satisfied', 'saxophone', 'school', - 'school_satchel', 'scissors', 'scorpius', 'scream', 'scream_cat', 'scroll', - 'seat', 'secret', 'see_no_evil', 'seedling', 'seven', 'shaved_ice', 'sheep', - 'shell', 'ship', 'shipit', 'shirt', 'shit', 'shoe', 'shower', 'signal_strength', - 'six', 'six_pointed_star', 'ski', 'skull', 'sleeping', 'sleepy', 'slot_machine', - 'small_blue_diamond', 'small_orange_diamond', 'small_red_triangle', - 'small_red_triangle_down', 'smile', 'smile_cat', 'smiley', 'smiley_cat', - 'smiling_imp', 'smirk', 'smirk_cat', 'smoking', 'snail', 'snake', 'snowboarder', - 'snowflake', 'snowman', 'sob', 'soccer', 'soon', 'sos', 'sound', 'space_invader', - 'spades', 'spaghetti', 'sparkle', 'sparkler', 'sparkles', 'sparkling_heart', - 'speak_no_evil', 'speaker', 'speech_balloon', 'speedboat', 'squirrel', 'star', - 'star2', 'stars', 'station', 'statue_of_liberty', 'steam_locomotive', 'stew', - 'straight_ruler', 'strawberry', 'stuck_out_tongue', 'stuck_out_tongue_closed_eyes', - 'stuck_out_tongue_winking_eye', 'sun_with_face', 'sunflower', 'sunglasses', - 'sunny', 'sunrise', 'sunrise_over_mountains', 'surfer', 'sushi', 'suspect', - 'suspension_railway', 'sweat', 'sweat_drops', 'sweat_smile', 'sweet_potato', - 'swimmer', 'symbols', 'syringe', 'tada', 'tanabata_tree', 'tangerine', 'taurus', - 'taxi', 'tea', 'telephone', 'telephone_receiver', 'telescope', 'tennis', 'tent', - 'thought_balloon', 'three', 'thumbsdown', 'thumbsup', 'ticket', 'tiger', 'tiger2', - 'tired_face', 'tm', 'toilet', 'tokyo_tower', 'tomato', 'tongue', 'top', 'tophat', - 'tractor', 'traffic_light', 'train', 'train2', 'tram', 'triangular_flag_on_post', - 'triangular_ruler', 'trident', 'triumph', 'trolleybus', 'trollface', 'trophy', - 'tropical_drink', 'tropical_fish', 'truck', 'trumpet', 'tshirt', 'tulip', - 'turtle', 'tv', 'twisted_rightwards_arrows', 'two', 'two_hearts', 'two_men_holding_hands', - 'two_women_holding_hands', 'u5272', 'u5408', 'u55b6', 'u6307', 'u6708', 'u6709', - 'u6e80', 'u7121', 'u7533', 'u7981', 'u7a7a', 'uk', 'umbrella', 'unamused', - 'underage', 'unlock', 'up', 'us', 'v', 'vertical_traffic_light', 'vhs', - 'vibration_mode', 'video_camera', 'video_game', 'violin', 'virgo', 'volcano', - 'vs', 'walking', 'waning_crescent_moon', 'waning_gibbous_moon', 'warning', - 'watch', 'water_buffalo', 'watermelon', 'wave', 'wavy_dash', 'waxing_crescent_moon', - 'waxing_gibbous_moon', 'wc', 'weary', 'wedding', 'whale', 'whale2', 'wheelchair', - 'white_check_mark', 'white_circle', 'white_flower', 'white_large_square', - 'white_medium_small_square', 'white_medium_square', 'white_small_square', - 'white_square_button', 'wind_chime', 'wine_glass', 'wink', 'wolf', 'woman', - 'womans_clothes', 'womans_hat', 'womens', 'worried', 'wrench', 'x', 'yellow_heart', - 'yen', 'yum', 'zap', 'zero', 'zzz'] +const AllGithubEmoji = [ + '+1', + '100', + '1234', + '8ball', + 'a', + 'ab', + 'abc', + 'abcd', + 'accept', + 'aerial_tramway', + 'airplane', + 'alarm_clock', + 'alien', + 'ambulance', + 'anchor', + 'angel', + 'anger', + 'angry', + 'anguished', + 'ant', + 'apple', + 'aquarius', + 'aries', + 'arrow_backward', + 'arrow_double_down', + 'arrow_double_up', + 'arrow_down', + 'arrow_down_small', + 'arrow_forward', + 'arrow_heading_down', + 'arrow_heading_up', + 'arrow_left', + 'arrow_lower_left', + 'arrow_lower_right', + 'arrow_right', + 'arrow_right_hook', + 'arrow_up', + 'arrow_up_down', + 'arrow_up_small', + 'arrow_upper_left', + 'arrow_upper_right', + 'arrows_clockwise', + 'arrows_counterclockwise', + 'art', + 'articulated_lorry', + 'astonished', + 'athletic_shoe', + 'atm', + 'b', + 'baby', + 'baby_bottle', + 'baby_chick', + 'baby_symbol', + 'back', + 'baggage_claim', + 'balloon', + 'ballot_box_with_check', + 'bamboo', + 'banana', + 'bangbang', + 'bank', + 'bar_chart', + 'barber', + 'baseball', + 'basketball', + 'bath', + 'bathtub', + 'battery', + 'bear', + 'bee', + 'beer', + 'beers', + 'beetle', + 'beginner', + 'bell', + 'bento', + 'bicyclist', + 'bike', + 'bikini', + 'bird', + 'birthday', + 'black_circle', + 'black_joker', + 'black_large_square', + 'black_medium_small_square', + 'black_medium_square', + 'black_nib', + 'black_small_square', + 'black_square_button', + 'blossom', + 'blowfish', + 'blue_book', + 'blue_car', + 'blue_heart', + 'blush', + 'boar', + 'boat', + 'bomb', + 'book', + 'bookmark', + 'bookmark_tabs', + 'books', + 'boom', + 'boot', + 'bouquet', + 'bow', + 'bowling', + 'bowtie', + 'boy', + 'bread', + 'bride_with_veil', + 'bridge_at_night', + 'briefcase', + 'broken_heart', + 'bug', + 'bulb', + 'bullettrain_front', + 'bullettrain_side', + 'bus', + 'busstop', + 'bust_in_silhouette', + 'busts_in_silhouette', + 'cactus', + 'cake', + 'calendar', + 'calling', + 'camel', + 'camera', + 'cancer', + 'candy', + 'capital_abcd', + 'capricorn', + 'car', + 'card_index', + 'carousel_horse', + 'cat', + 'cat2', + 'cd', + 'chart', + 'chart_with_downwards_trend', + 'chart_with_upwards_trend', + 'checkered_flag', + 'cherries', + 'cherry_blossom', + 'chestnut', + 'chicken', + 'children_crossing', + 'chocolate_bar', + 'christmas_tree', + 'church', + 'cinema', + 'circus_tent', + 'city_sunrise', + 'city_sunset', + 'cl', + 'clap', + 'clapper', + 'clipboard', + 'clock1', + 'clock10', + 'clock1030', + 'clock11', + 'clock1130', + 'clock12', + 'clock1230', + 'clock130', + 'clock2', + 'clock230', + 'clock3', + 'clock330', + 'clock4', + 'clock430', + 'clock5', + 'clock530', + 'clock6', + 'clock630', + 'clock7', + 'clock730', + 'clock8', + 'clock830', + 'clock9', + 'clock930', + 'closed_book', + 'closed_lock_with_key', + 'closed_umbrella', + 'cloud', + 'clubs', + 'cn', + 'cocktail', + 'coffee', + 'cold_sweat', + 'collision', + 'computer', + 'confetti_ball', + 'confounded', + 'confused', + 'congratulations', + 'construction', + 'construction_worker', + 'convenience_store', + 'cookie', + 'cool', + 'cop', + 'copyright', + 'corn', + 'couple', + 'couple_with_heart', + 'couplekiss', + 'cow', + 'cow2', + 'credit_card', + 'crescent_moon', + 'crocodile', + 'crossed_flags', + 'crown', + 'cry', + 'crying_cat_face', + 'crystal_ball', + 'cupid', + 'curly_loop', + 'currency_exchange', + 'curry', + 'custard', + 'customs', + 'cyclone', + 'dancer', + 'dancers', + 'dango', + 'dart', + 'dash', + 'date', + 'de', + 'deciduous_tree', + 'department_store', + 'diamond_shape_with_a_dot_inside', + 'diamonds', + 'disappointed', + 'disappointed_relieved', + 'dizzy', + 'dizzy_face', + 'do_not_litter', + 'dog', + 'dog2', + 'dollar', + 'dolls', + 'dolphin', + 'door', + 'doughnut', + 'dragon', + 'dragon_face', + 'dress', + 'dromedary_camel', + 'droplet', + 'dvd', + 'e-mail', + 'ear', + 'ear_of_rice', + 'earth_africa', + 'earth_americas', + 'earth_asia', + 'egg', + 'eggplant', + 'eight', + 'eight_pointed_black_star', + 'eight_spoked_asterisk', + 'electric_plug', + 'elephant', + 'email', + 'end', + 'envelope', + 'envelope_with_arrow', + 'es', + 'euro', + 'european_castle', + 'european_post_office', + 'evergreen_tree', + 'exclamation', + 'expressionless', + 'eyeglasses', + 'eyes', + 'facepunch', + 'factory', + 'fallen_leaf', + 'family', + 'fast_forward', + 'fax', + 'fearful', + 'feelsgood', + 'feet', + 'ferris_wheel', + 'file_folder', + 'finnadie', + 'fire', + 'fire_engine', + 'fireworks', + 'first_quarter_moon', + 'first_quarter_moon_with_face', + 'fish', + 'fish_cake', + 'fishing_pole_and_fish', + 'fist', + 'five', + 'flags', + 'flashlight', + 'flipper', + 'floppy_disk', + 'flower_playing_cards', + 'flushed', + 'foggy', + 'football', + 'footprints', + 'fork_and_knife', + 'fountain', + 'four', + 'four_leaf_clover', + 'fr', + 'free', + 'fried_shrimp', + 'fries', + 'frog', + 'frowning', + 'fu', + 'fuelpump', + 'full_moon', + 'full_moon_with_face', + 'game_die', + 'gb', + 'gem', + 'gemini', + 'ghost', + 'gift', + 'gift_heart', + 'girl', + 'globe_with_meridians', + 'goat', + 'goberserk', + 'godmode', + 'golf', + 'grapes', + 'green_apple', + 'green_book', + 'green_heart', + 'grey_exclamation', + 'grey_question', + 'grimacing', + 'grin', + 'grinning', + 'guardsman', + 'guitar', + 'gun', + 'haircut', + 'hamburger', + 'hammer', + 'hamster', + 'hand', + 'handbag', + 'hankey', + 'hash', + 'hatched_chick', + 'hatching_chick', + 'headphones', + 'hear_no_evil', + 'heart', + 'heart_decoration', + 'heart_eyes', + 'heart_eyes_cat', + 'heartbeat', + 'heartpulse', + 'hearts', + 'heavy_check_mark', + 'heavy_division_sign', + 'heavy_dollar_sign', + 'heavy_exclamation_mark', + 'heavy_minus_sign', + 'heavy_multiplication_x', + 'heavy_plus_sign', + 'helicopter', + 'herb', + 'hibiscus', + 'high_brightness', + 'high_heel', + 'hocho', + 'honey_pot', + 'honeybee', + 'horse', + 'horse_racing', + 'hospital', + 'hotel', + 'hotsprings', + 'hourglass', + 'hourglass_flowing_sand', + 'house', + 'house_with_garden', + 'hurtrealbad', + 'hushed', + 'ice_cream', + 'icecream', + 'id', + 'ideograph_advantage', + 'imp', + 'inbox_tray', + 'incoming_envelope', + 'information_desk_person', + 'information_source', + 'innocent', + 'interrobang', + 'iphone', + 'it', + 'izakaya_lantern', + 'jack_o_lantern', + 'japan', + 'japanese_castle', + 'japanese_goblin', + 'japanese_ogre', + 'jeans', + 'joy', + 'joy_cat', + 'jp', + 'key', + 'keycap_ten', + 'kimono', + 'kiss', + 'kissing', + 'kissing_cat', + 'kissing_closed_eyes', + 'kissing_heart', + 'kissing_smiling_eyes', + 'koala', + 'koko', + 'kr', + 'lantern', + 'large_blue_circle', + 'large_blue_diamond', + 'large_orange_diamond', + 'last_quarter_moon', + 'last_quarter_moon_with_face', + 'laughing', + 'leaves', + 'ledger', + 'left_luggage', + 'left_right_arrow', + 'leftwards_arrow_with_hook', + 'lemon', + 'leo', + 'leopard', + 'libra', + 'light_rail', + 'link', + 'lips', + 'lipstick', + 'lock', + 'lock_with_ink_pen', + 'lollipop', + 'loop', + 'loud_sound', + 'loudspeaker', + 'love_hotel', + 'love_letter', + 'low_brightness', + 'm', + 'mag', + 'mag_right', + 'mahjong', + 'mailbox', + 'mailbox_closed', + 'mailbox_with_mail', + 'mailbox_with_no_mail', + 'man', + 'man_with_gua_pi_mao', + 'man_with_turban', + 'mans_shoe', + 'maple_leaf', + 'mask', + 'massage', + 'meat_on_bone', + 'mega', + 'melon', + 'memo', + 'mens', + 'metal', + 'metro', + 'microphone', + 'microscope', + 'milky_way', + 'minibus', + 'minidisc', + 'mobile_phone_off', + 'money_with_wings', + 'moneybag', + 'monkey', + 'monkey_face', + 'monorail', + 'moon', + 'mortar_board', + 'mount_fuji', + 'mountain_bicyclist', + 'mountain_cableway', + 'mountain_railway', + 'mouse', + 'mouse2', + 'movie_camera', + 'moyai', + 'muscle', + 'mushroom', + 'musical_keyboard', + 'musical_note', + 'musical_score', + 'mute', + 'nail_care', + 'name_badge', + 'neckbeard', + 'necktie', + 'negative_squared_cross_mark', + 'neutral_face', + 'new', + 'new_moon', + 'new_moon_with_face', + 'newspaper', + 'ng', + 'night_with_stars', + 'nine', + 'no_bell', + 'no_bicycles', + 'no_entry', + 'no_entry_sign', + 'no_good', + 'no_mobile_phones', + 'no_mouth', + 'no_pedestrians', + 'no_smoking', + 'non-potable_water', + 'nose', + 'notebook', + 'notebook_with_decorative_cover', + 'notes', + 'nut_and_bolt', + 'o', + 'o2', + 'ocean', + 'octocat', + 'octopus', + 'oden', + 'office', + 'ok', + 'ok_hand', + 'ok_woman', + 'older_man', + 'older_woman', + 'on', + 'oncoming_automobile', + 'oncoming_bus', + 'oncoming_police_car', + 'oncoming_taxi', + 'one', + 'open_book', + 'open_file_folder', + 'open_hands', + 'open_mouth', + 'ophiuchus', + 'orange_book', + 'outbox_tray', + 'ox', + 'package', + 'page_facing_up', + 'page_with_curl', + 'pager', + 'palm_tree', + 'panda_face', + 'paperclip', + 'parking', + 'part_alternation_mark', + 'partly_sunny', + 'passport_control', + 'paw_prints', + 'peach', + 'pear', + 'pencil', + 'pencil2', + 'penguin', + 'pensive', + 'performing_arts', + 'persevere', + 'person_frowning', + 'person_with_blond_hair', + 'person_with_pouting_face', + 'phone', + 'pig', + 'pig2', + 'pig_nose', + 'pill', + 'pineapple', + 'pisces', + 'pizza', + 'point_down', + 'point_left', + 'point_right', + 'point_up', + 'point_up_2', + 'police_car', + 'poodle', + 'poop', + 'post_office', + 'postal_horn', + 'postbox', + 'potable_water', + 'pouch', + 'poultry_leg', + 'pound', + 'pouting_cat', + 'pray', + 'princess', + 'punch', + 'purple_heart', + 'purse', + 'pushpin', + 'put_litter_in_its_place', + 'question', + 'rabbit', + 'rabbit2', + 'racehorse', + 'radio', + 'radio_button', + 'rage', + 'rage1', + 'rage2', + 'rage3', + 'rage4', + 'railway_car', + 'rainbow', + 'raised_hand', + 'raised_hands', + 'raising_hand', + 'ram', + 'ramen', + 'rat', + 'recycle', + 'red_car', + 'red_circle', + 'registered', + 'relaxed', + 'relieved', + 'repeat', + 'repeat_one', + 'restroom', + 'revolving_hearts', + 'rewind', + 'ribbon', + 'rice', + 'rice_ball', + 'rice_cracker', + 'rice_scene', + 'ring', + 'rocket', + 'roller_coaster', + 'rooster', + 'rose', + 'rotating_light', + 'round_pushpin', + 'rowboat', + 'ru', + 'rugby_football', + 'runner', + 'running', + 'running_shirt_with_sash', + 'sa', + 'sagittarius', + 'sailboat', + 'sake', + 'sandal', + 'santa', + 'satellite', + 'satisfied', + 'saxophone', + 'school', + 'school_satchel', + 'scissors', + 'scorpius', + 'scream', + 'scream_cat', + 'scroll', + 'seat', + 'secret', + 'see_no_evil', + 'seedling', + 'seven', + 'shaved_ice', + 'sheep', + 'shell', + 'ship', + 'shipit', + 'shirt', + 'shit', + 'shoe', + 'shower', + 'signal_strength', + 'six', + 'six_pointed_star', + 'ski', + 'skull', + 'sleeping', + 'sleepy', + 'slot_machine', + 'small_blue_diamond', + 'small_orange_diamond', + 'small_red_triangle', + 'small_red_triangle_down', + 'smile', + 'smile_cat', + 'smiley', + 'smiley_cat', + 'smiling_imp', + 'smirk', + 'smirk_cat', + 'smoking', + 'snail', + 'snake', + 'snowboarder', + 'snowflake', + 'snowman', + 'sob', + 'soccer', + 'soon', + 'sos', + 'sound', + 'space_invader', + 'spades', + 'spaghetti', + 'sparkle', + 'sparkler', + 'sparkles', + 'sparkling_heart', + 'speak_no_evil', + 'speaker', + 'speech_balloon', + 'speedboat', + 'squirrel', + 'star', + 'star2', + 'stars', + 'station', + 'statue_of_liberty', + 'steam_locomotive', + 'stew', + 'straight_ruler', + 'strawberry', + 'stuck_out_tongue', + 'stuck_out_tongue_closed_eyes', + 'stuck_out_tongue_winking_eye', + 'sun_with_face', + 'sunflower', + 'sunglasses', + 'sunny', + 'sunrise', + 'sunrise_over_mountains', + 'surfer', + 'sushi', + 'suspect', + 'suspension_railway', + 'sweat', + 'sweat_drops', + 'sweat_smile', + 'sweet_potato', + 'swimmer', + 'symbols', + 'syringe', + 'tada', + 'tanabata_tree', + 'tangerine', + 'taurus', + 'taxi', + 'tea', + 'telephone', + 'telephone_receiver', + 'telescope', + 'tennis', + 'tent', + 'thought_balloon', + 'three', + 'thumbsdown', + 'thumbsup', + 'ticket', + 'tiger', + 'tiger2', + 'tired_face', + 'tm', + 'toilet', + 'tokyo_tower', + 'tomato', + 'tongue', + 'top', + 'tophat', + 'tractor', + 'traffic_light', + 'train', + 'train2', + 'tram', + 'triangular_flag_on_post', + 'triangular_ruler', + 'trident', + 'triumph', + 'trolleybus', + 'trollface', + 'trophy', + 'tropical_drink', + 'tropical_fish', + 'truck', + 'trumpet', + 'tshirt', + 'tulip', + 'turtle', + 'tv', + 'twisted_rightwards_arrows', + 'two', + 'two_hearts', + 'two_men_holding_hands', + 'two_women_holding_hands', + 'u5272', + 'u5408', + 'u55b6', + 'u6307', + 'u6708', + 'u6709', + 'u6e80', + 'u7121', + 'u7533', + 'u7981', + 'u7a7a', + 'uk', + 'umbrella', + 'unamused', + 'underage', + 'unlock', + 'up', + 'us', + 'v', + 'vertical_traffic_light', + 'vhs', + 'vibration_mode', + 'video_camera', + 'video_game', + 'violin', + 'virgo', + 'volcano', + 'vs', + 'walking', + 'waning_crescent_moon', + 'waning_gibbous_moon', + 'warning', + 'watch', + 'water_buffalo', + 'watermelon', + 'wave', + 'wavy_dash', + 'waxing_crescent_moon', + 'waxing_gibbous_moon', + 'wc', + 'weary', + 'wedding', + 'whale', + 'whale2', + 'wheelchair', + 'white_check_mark', + 'white_circle', + 'white_flower', + 'white_large_square', + 'white_medium_small_square', + 'white_medium_square', + 'white_small_square', + 'white_square_button', + 'wind_chime', + 'wine_glass', + 'wink', + 'wolf', + 'woman', + 'womans_clothes', + 'womans_hat', + 'womens', + 'worried', + 'wrench', + 'x', + 'yellow_heart', + 'yen', + 'yum', + 'zap', + 'zero', + 'zzz' +] // emoji from All-Github-Emoji-Icons // https://github.com/scotch-io/All-Github-Emoji-Icons window.emojify = function (match, $1) { return AllGithubEmoji.indexOf($1) === -1 ? match - : '' + $1 + '' + : '' +
+      $1 +
+      '' } diff --git a/src/plugins/front-matter/parser.js b/src/plugins/front-matter/parser.js index 23aabdd1..f0ae3777 100644 --- a/src/plugins/front-matter/parser.js +++ b/src/plugins/front-matter/parser.js @@ -5,7 +5,8 @@ import parser from './yaml' var optionalByteOrderMark = '\\ufeff?' -var pattern = '^(' + +var pattern = + '^(' + optionalByteOrderMark + '(= yaml =|---)' + '$([\\s\\S]*?)' + @@ -17,7 +18,7 @@ var pattern = '^(' + // need to be moved down into the functions that use it. var regex = new RegExp(pattern, 'm') -function extractor (string) { +function extractor(string) { string = string || '' var lines = string.split(/(\r?\n)/) @@ -28,7 +29,7 @@ function extractor (string) { } } -function parse (string) { +function parse(string) { var match = regex.exec(string) if (!match) { @@ -45,10 +46,10 @@ function parse (string) { return { attributes: attributes, body: body, frontmatter: yaml } } -function test (string) { +function test(string) { string = string || '' return regex.test(string) } -export default extractor \ No newline at end of file +export default extractor diff --git a/src/plugins/front-matter/yaml.js b/src/plugins/front-matter/yaml.js index ae00a95a..b9474634 100644 --- a/src/plugins/front-matter/yaml.js +++ b/src/plugins/front-matter/yaml.js @@ -29,415 +29,412 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * @namespace */ - var errors = [], - reference_blocks = [], - processing_time = 0, - regex = - { - "regLevel" : new RegExp("^([\\s\\-]+)"), - "invalidLine" : new RegExp("^\\-\\-\\-|^\\.\\.\\.|^\\s*#.*|^\\s*$"), - "dashesString" : new RegExp("^\\s*\\\"([^\\\"]*)\\\"\\s*$"), - "quotesString" : new RegExp("^\\s*\\\'([^\\\']*)\\\'\\s*$"), - "float" : new RegExp("^[+-]?[0-9]+\\.[0-9]+(e[+-]?[0-9]+(\\.[0-9]+)?)?$"), - "integer" : new RegExp("^[+-]?[0-9]+$"), - "array" : new RegExp("\\[\\s*(.*)\\s*\\]"), - "map" : new RegExp("\\{\\s*(.*)\\s*\\}"), - "key_value" : new RegExp("([a-z0-9_-][ a-z0-9_-]*):( .+)", "i"), - "single_key_value" : new RegExp("^([a-z0-9_-][ a-z0-9_-]*):( .+?)$", "i"), - "key" : new RegExp("([a-z0-9_-][ a-z0-9_-]+):( .+)?", "i"), - "item" : new RegExp("^-\\s+"), - "trim" : new RegExp("^\\s+|\\s+$"), - "comment" : new RegExp("([^\\\'\\\"#]+([\\\'\\\"][^\\\'\\\"]*[\\\'\\\"])*)*(#.*)?") - }; + reference_blocks = [], + processing_time = 0, + regex = { + regLevel: new RegExp('^([\\s\\-]+)'), + invalidLine: new RegExp('^\\-\\-\\-|^\\.\\.\\.|^\\s*#.*|^\\s*$'), + dashesString: new RegExp('^\\s*\\"([^\\"]*)\\"\\s*$'), + quotesString: new RegExp("^\\s*\\'([^\\']*)\\'\\s*$"), + float: new RegExp('^[+-]?[0-9]+\\.[0-9]+(e[+-]?[0-9]+(\\.[0-9]+)?)?$'), + integer: new RegExp('^[+-]?[0-9]+$'), + array: new RegExp('\\[\\s*(.*)\\s*\\]'), + map: new RegExp('\\{\\s*(.*)\\s*\\}'), + key_value: new RegExp('([a-z0-9_-][ a-z0-9_-]*):( .+)', 'i'), + single_key_value: new RegExp('^([a-z0-9_-][ a-z0-9_-]*):( .+?)$', 'i'), + key: new RegExp('([a-z0-9_-][ a-z0-9_-]+):( .+)?', 'i'), + item: new RegExp('^-\\s+'), + trim: new RegExp('^\\s+|\\s+$'), + comment: new RegExp('([^\\\'\\"#]+([\\\'\\"][^\\\'\\"]*[\\\'\\"])*)*(#.*)?') + } - /** +/** * @class A block of lines of a given level. * @param {int} lvl The block's level. * @private */ function Block(lvl) { - return { - /* The block's parent */ - parent: null, - /* Number of children */ - length: 0, - /* Block's level */ - level: lvl, - /* Lines of code to process */ - lines: [], - /* Blocks with greater level */ - children : [], - /* Add a block to the children collection */ - addChild : function(obj) { - this.children.push(obj); - obj.parent = this; - ++this.length; - } - }; + return { + /* The block's parent */ + parent: null, + /* Number of children */ + length: 0, + /* Block's level */ + level: lvl, + /* Lines of code to process */ + lines: [], + /* Blocks with greater level */ + children: [], + /* Add a block to the children collection */ + addChild: function(obj) { + this.children.push(obj) + obj.parent = this + ++this.length + } + } } // function to create an XMLHttpClient in a cross-browser manner function createXMLHTTPRequest() { - var xmlhttp; + var xmlhttp - try { - // Mozilla / Safari / IE7 - xmlhttp = new XMLHttpRequest(); - } catch (e) { - // IE - var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0', - 'MSXML2.XMLHTTP.4.0', - 'MSXML2.XMLHTTP.3.0', - 'MSXML2.XMLHTTP', - 'Microsoft.XMLHTTP' ); - var success = false; - for (var i=0;i < XMLHTTP_IDS.length && !success; i++) { - try { - xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]); - success = true; - } catch (e) {} - } - if (!success) { - throw new Error('Unable to create XMLHttpRequest.'); - } + try { + // Mozilla / Safari / IE7 + xmlhttp = new XMLHttpRequest() + } catch (e) { + // IE + var XMLHTTP_IDS = new Array( + 'MSXML2.XMLHTTP.5.0', + 'MSXML2.XMLHTTP.4.0', + 'MSXML2.XMLHTTP.3.0', + 'MSXML2.XMLHTTP', + 'Microsoft.XMLHTTP' + ) + var success = false + for (var i = 0; i < XMLHTTP_IDS.length && !success; i++) { + try { + xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]) + success = true + } catch (e) {} } + if (!success) { + throw new Error('Unable to create XMLHttpRequest.') + } + } - return xmlhttp; + return xmlhttp } function parser(str) { - var regLevel = regex["regLevel"]; - var invalidLine = regex["invalidLine"]; - var lines = str.split("\n"); - var m; - var level = 0, curLevel = 0; + var regLevel = regex['regLevel'] + var invalidLine = regex['invalidLine'] + var lines = str.split('\n') + var m + var level = 0, + curLevel = 0 - var blocks = []; + var blocks = [] - var result = new Block(-1); - var currentBlock = new Block(0); - result.addChild(currentBlock); - var levels = []; - var line = ""; + var result = new Block(-1) + var currentBlock = new Block(0) + result.addChild(currentBlock) + var levels = [] + var line = '' - blocks.push(currentBlock); - levels.push(level); + blocks.push(currentBlock) + levels.push(level) - for(var i = 0, len = lines.length; i < len; ++i) { - line = lines[i]; + for (var i = 0, len = lines.length; i < len; ++i) { + line = lines[i] - if(line.match(invalidLine)) { - continue; - } - - if(m = regLevel.exec(line)) { - level = m[1].length; - } else - level = 0; - - if(level > curLevel) { - var oldBlock = currentBlock; - currentBlock = new Block(level); - oldBlock.addChild(currentBlock); - blocks.push(currentBlock); - levels.push(level); - } else if(level < curLevel) { - var added = false; - - var k = levels.length - 1; - for(; k >= 0; --k) { - if(levels[k] == level) { - currentBlock = new Block(level); - blocks.push(currentBlock); - levels.push(level); - if(blocks[k].parent!= null) - blocks[k].parent.addChild(currentBlock); - added = true; - break; - } - } - - if(!added) { - errors.push("Error: Invalid indentation at line " + i + ": " + line); - return; - } - } - - currentBlock.lines.push(line.replace(regex["trim"], "")); - curLevel = level; + if (line.match(invalidLine)) { + continue } - return result; + if ((m = regLevel.exec(line))) { + level = m[1].length + } else level = 0 + + if (level > curLevel) { + var oldBlock = currentBlock + currentBlock = new Block(level) + oldBlock.addChild(currentBlock) + blocks.push(currentBlock) + levels.push(level) + } else if (level < curLevel) { + var added = false + + var k = levels.length - 1 + for (; k >= 0; --k) { + if (levels[k] == level) { + currentBlock = new Block(level) + blocks.push(currentBlock) + levels.push(level) + if (blocks[k].parent != null) blocks[k].parent.addChild(currentBlock) + added = true + break + } + } + + if (!added) { + errors.push('Error: Invalid indentation at line ' + i + ': ' + line) + return + } + } + + currentBlock.lines.push(line.replace(regex['trim'], '')) + curLevel = level + } + + return result } function processValue(val) { - val = val.replace(regex["trim"], ""); - var m = null; + val = val.replace(regex['trim'], '') + var m = null - if(val == 'true') { - return true; - } else if(val == 'false') { - return false; - } else if(val == '.NaN') { - return Number.NaN; - } else if(val == 'null') { - return null; - } else if(val == '.inf') { - return Number.POSITIVE_INFINITY; - } else if(val == '-.inf') { - return Number.NEGATIVE_INFINITY; - } else if(m = val.match(regex["dashesString"])) { - return m[1]; - } else if(m = val.match(regex["quotesString"])) { - return m[1]; - } else if(m = val.match(regex["float"])) { - return parseFloat(m[0]); - } else if(m = val.match(regex["integer"])) { - return parseInt(m[0]); - } else if( !isNaN(m = Date.parse(val))) { - return new Date(m); - } else if(m = val.match(regex["single_key_value"])) { - var res = {}; - res[m[1]] = processValue(m[2]); - return res; - } else if(m = val.match(regex["array"])){ - var count = 0, c = ' '; - var res = []; - var content = ""; - var str = false; - for(var j = 0, lenJ = m[1].length; j < lenJ; ++j) { - c = m[1][j]; - if(c == '\'' || c == '"') { - if(str === false) { - str = c; - content += c; - continue; - } else if((c == '\'' && str == '\'') || (c == '"' && str == '"')) { - str = false; - content += c; - continue; - } - } else if(str === false && (c == '[' || c == '{')) { - ++count; - } else if(str === false && (c == ']' || c == '}')) { - --count; - } else if(str === false && count == 0 && c == ',') { - res.push(processValue(content)); - content = ""; - continue; - } - - content += c; + if (val == 'true') { + return true + } else if (val == 'false') { + return false + } else if (val == '.NaN') { + return Number.NaN + } else if (val == 'null') { + return null + } else if (val == '.inf') { + return Number.POSITIVE_INFINITY + } else if (val == '-.inf') { + return Number.NEGATIVE_INFINITY + } else if ((m = val.match(regex['dashesString']))) { + return m[1] + } else if ((m = val.match(regex['quotesString']))) { + return m[1] + } else if ((m = val.match(regex['float']))) { + return parseFloat(m[0]) + } else if ((m = val.match(regex['integer']))) { + return parseInt(m[0]) + } else if (!isNaN((m = Date.parse(val)))) { + return new Date(m) + } else if ((m = val.match(regex['single_key_value']))) { + var res = {} + res[m[1]] = processValue(m[2]) + return res + } else if ((m = val.match(regex['array']))) { + var count = 0, + c = ' ' + var res = [] + var content = '' + var str = false + for (var j = 0, lenJ = m[1].length; j < lenJ; ++j) { + c = m[1][j] + if (c == "'" || c == '"') { + if (str === false) { + str = c + content += c + continue + } else if ((c == "'" && str == "'") || (c == '"' && str == '"')) { + str = false + content += c + continue } + } else if (str === false && (c == '[' || c == '{')) { + ++count + } else if (str === false && (c == ']' || c == '}')) { + --count + } else if (str === false && count == 0 && c == ',') { + res.push(processValue(content)) + content = '' + continue + } - if(content.length > 0) - res.push(processValue(content)); - return res; - } else if(m = val.match(regex["map"])){ - var count = 0, c = ' '; - var res = []; - var content = ""; - var str = false; - for(var j = 0, lenJ = m[1].length; j < lenJ; ++j) { - c = m[1][j]; - if(c == '\'' || c == '"') { - if(str === false) { - str = c; - content += c; - continue; - } else if((c == '\'' && str == '\'') || (c == '"' && str == '"')) { - str = false; - content += c; - continue; - } - } else if(str === false && (c == '[' || c == '{')) { - ++count; - } else if(str === false && (c == ']' || c == '}')) { - --count; - } else if(str === false && count == 0 && c == ',') { - res.push(content); - content = ""; - continue; - } + content += c + } - content += c; + if (content.length > 0) res.push(processValue(content)) + return res + } else if ((m = val.match(regex['map']))) { + var count = 0, + c = ' ' + var res = [] + var content = '' + var str = false + for (var j = 0, lenJ = m[1].length; j < lenJ; ++j) { + c = m[1][j] + if (c == "'" || c == '"') { + if (str === false) { + str = c + content += c + continue + } else if ((c == "'" && str == "'") || (c == '"' && str == '"')) { + str = false + content += c + continue } + } else if (str === false && (c == '[' || c == '{')) { + ++count + } else if (str === false && (c == ']' || c == '}')) { + --count + } else if (str === false && count == 0 && c == ',') { + res.push(content) + content = '' + continue + } - if(content.length > 0) - res.push(content); + content += c + } - var newRes = {}; - for(var j = 0, lenJ = res.length; j < lenJ; ++j) { - if(m = res[j].match(regex["key_value"])) { - newRes[m[1]] = processValue(m[2]); - } - } + if (content.length > 0) res.push(content) - return newRes; - } else - return val; + var newRes = {} + for (var j = 0, lenJ = res.length; j < lenJ; ++j) { + if ((m = res[j].match(regex['key_value']))) { + newRes[m[1]] = processValue(m[2]) + } + } + + return newRes + } else return val } function processFoldedBlock(block) { - var lines = block.lines; - var children = block.children; - var str = lines.join(" "); - var chunks = [str]; - for(var i = 0, len = children.length; i < len; ++i) { - chunks.push(processFoldedBlock(children[i])); - } - return chunks.join("\n"); + var lines = block.lines + var children = block.children + var str = lines.join(' ') + var chunks = [str] + for (var i = 0, len = children.length; i < len; ++i) { + chunks.push(processFoldedBlock(children[i])) + } + return chunks.join('\n') } function processLiteralBlock(block) { - var lines = block.lines; - var children = block.children; - var str = lines.join("\n"); - for(var i = 0, len = children.length; i < len; ++i) { - str += processLiteralBlock(children[i]); - } - return str; + var lines = block.lines + var children = block.children + var str = lines.join('\n') + for (var i = 0, len = children.length; i < len; ++i) { + str += processLiteralBlock(children[i]) + } + return str } function processBlock(blocks) { - var m = null; - var res = {}; - var lines = null; - var children = null; - var currentObj = null; + var m = null + var res = {} + var lines = null + var children = null + var currentObj = null - var level = -1; + var level = -1 - var processedBlocks = []; + var processedBlocks = [] - var isMap = true; + var isMap = true - for(var j = 0, lenJ = blocks.length; j < lenJ; ++j) { + for (var j = 0, lenJ = blocks.length; j < lenJ; ++j) { + if (level != -1 && level != blocks[j].level) continue - if(level != -1 && level != blocks[j].level) - continue; + processedBlocks.push(j) - processedBlocks.push(j); + level = blocks[j].level + lines = blocks[j].lines + children = blocks[j].children + currentObj = null - level = blocks[j].level; - lines = blocks[j].lines; - children = blocks[j].children; - currentObj = null; + for (var i = 0, len = lines.length; i < len; ++i) { + var line = lines[i] - for(var i = 0, len = lines.length; i < len; ++i) { - var line = lines[i]; + if ((m = line.match(regex['key']))) { + var key = m[1] - if(m = line.match(regex["key"])) { - var key = m[1]; - - if(key[0] == '-') { - key = key.replace(regex["item"], ""); - if (isMap) { - isMap = false; - if (typeof(res.length) === "undefined") { - res = []; - } - } - if(currentObj != null) res.push(currentObj); - currentObj = {}; - isMap = true; - } - - if(typeof m[2] != "undefined") { - var value = m[2].replace(regex["trim"], ""); - if(value[0] == '&') { - var nb = processBlock(children); - if(currentObj != null) currentObj[key] = nb; - else res[key] = nb; - reference_blocks[value.substr(1)] = nb; - } else if(value[0] == '|') { - if(currentObj != null) currentObj[key] = processLiteralBlock(children.shift()); - else res[key] = processLiteralBlock(children.shift()); - } else if(value[0] == '*') { - var v = value.substr(1); - var no = {}; - - if(typeof reference_blocks[v] == "undefined") { - errors.push("Reference '" + v + "' not found!"); - } else { - for(var k in reference_blocks[v]) { - no[k] = reference_blocks[v][k]; - } - - if(currentObj != null) currentObj[key] = no; - else res[key] = no; - } - } else if(value[0] == '>') { - if(currentObj != null) currentObj[key] = processFoldedBlock(children.shift()); - else res[key] = processFoldedBlock(children.shift()); - } else { - if(currentObj != null) currentObj[key] = processValue(value); - else res[key] = processValue(value); - } - } else { - if(currentObj != null) currentObj[key] = processBlock(children); - else res[key] = processBlock(children); - } - } else if(line.match(/^-\s*$/)) { - if (isMap) { - isMap = false; - if (typeof(res.length) === "undefined") { - res = []; - } - } - if(currentObj != null) res.push(currentObj); - currentObj = {}; - isMap = true; - continue; - } else if(m = line.match(/^-\s*(.*)/)) { - if(currentObj != null) - currentObj.push(processValue(m[1])); - else { - if (isMap) { - isMap = false; - if (typeof(res.length) === "undefined") { - res = []; - } - } - res.push(processValue(m[1])); - } - continue; + if (key[0] == '-') { + key = key.replace(regex['item'], '') + if (isMap) { + isMap = false + if (typeof res.length === 'undefined') { + res = [] } + } + if (currentObj != null) res.push(currentObj) + currentObj = {} + isMap = true } - if(currentObj != null) { - if (isMap) { - isMap = false; - if (typeof(res.length) === "undefined") { - res = []; - } + if (typeof m[2] != 'undefined') { + var value = m[2].replace(regex['trim'], '') + if (value[0] == '&') { + var nb = processBlock(children) + if (currentObj != null) currentObj[key] = nb + else res[key] = nb + reference_blocks[value.substr(1)] = nb + } else if (value[0] == '|') { + if (currentObj != null) + currentObj[key] = processLiteralBlock(children.shift()) + else res[key] = processLiteralBlock(children.shift()) + } else if (value[0] == '*') { + var v = value.substr(1) + var no = {} + + if (typeof reference_blocks[v] == 'undefined') { + errors.push("Reference '" + v + "' not found!") + } else { + for (var k in reference_blocks[v]) { + no[k] = reference_blocks[v][k] + } + + if (currentObj != null) currentObj[key] = no + else res[key] = no } - res.push(currentObj); + } else if (value[0] == '>') { + if (currentObj != null) + currentObj[key] = processFoldedBlock(children.shift()) + else res[key] = processFoldedBlock(children.shift()) + } else { + if (currentObj != null) currentObj[key] = processValue(value) + else res[key] = processValue(value) + } + } else { + if (currentObj != null) currentObj[key] = processBlock(children) + else res[key] = processBlock(children) } + } else if (line.match(/^-\s*$/)) { + if (isMap) { + isMap = false + if (typeof res.length === 'undefined') { + res = [] + } + } + if (currentObj != null) res.push(currentObj) + currentObj = {} + isMap = true + continue + } else if ((m = line.match(/^-\s*(.*)/))) { + if (currentObj != null) currentObj.push(processValue(m[1])) + else { + if (isMap) { + isMap = false + if (typeof res.length === 'undefined') { + res = [] + } + } + res.push(processValue(m[1])) + } + continue + } } - for(var j = processedBlocks.length - 1; j >= 0; --j) { - blocks.splice.call(blocks, processedBlocks[j], 1); + if (currentObj != null) { + if (isMap) { + isMap = false + if (typeof res.length === 'undefined') { + res = [] + } + } + res.push(currentObj) } + } - return res; + for (var j = processedBlocks.length - 1; j >= 0; --j) { + blocks.splice.call(blocks, processedBlocks[j], 1) + } + + return res } function semanticAnalysis(blocks) { - var res = processBlock(blocks.children); - return res; + var res = processBlock(blocks.children) + return res } function preProcess(src) { - var m; - var lines = src.split("\n"); + var m + var lines = src.split('\n') - var r = regex["comment"]; + var r = regex['comment'] - for(var i in lines) { - if(m = lines[i].match(r)) { -/* var cmt = ""; + for (var i in lines) { + if ((m = lines[i].match(r))) { + /* var cmt = ""; if(typeof m[3] != "undefined") lines[i] = m[1]; else if(typeof m[3] != "undefined") @@ -445,25 +442,25 @@ function preProcess(src) { else lines[i] = ""; */ - if(typeof m[3] !== "undefined") { - lines[i] = m[0].substr(0, m[0].length - m[3].length); - } - } + if (typeof m[3] !== 'undefined') { + lines[i] = m[0].substr(0, m[0].length - m[3].length) + } } + } - return lines.join("\n"); + return lines.join('\n') } function load(str) { - errors = []; - reference_blocks = []; - processing_time = (new Date()).getTime(); - var pre = preProcess(str) - var doc = parser(pre); - var res = semanticAnalysis(doc); - processing_time = (new Date()).getTime() - processing_time; + errors = [] + reference_blocks = [] + processing_time = new Date().getTime() + var pre = preProcess(str) + var doc = parser(pre) + var res = semanticAnalysis(doc) + processing_time = new Date().getTime() - processing_time - return res; + return res } -export default load \ No newline at end of file +export default load diff --git a/src/plugins/ga.js b/src/plugins/ga.js index b016f28b..2d87b4a2 100644 --- a/src/plugins/ga.js +++ b/src/plugins/ga.js @@ -8,9 +8,11 @@ function appendScript () { function init (id) { appendScript() - window.ga = window.ga || function () { - (window.ga.q = window.ga.q || []).push(arguments) - } + window.ga = + window.ga || + function () { + ;(window.ga.q = window.ga.q || []).push(arguments) + } window.ga.l = Number(new Date()) window.ga('create', id, 'auto') } diff --git a/src/plugins/search/component.js b/src/plugins/search/component.js index aab0c502..35e5dee2 100644 --- a/src/plugins/search/component.js +++ b/src/plugins/search/component.js @@ -71,7 +71,7 @@ function style () { function tpl (opts, defaultValue = '') { const html = `` + - '
' + + '
' + '' const el = Docsify.dom.create('div', html) const aside = Docsify.dom.find('aside') @@ -109,8 +109,11 @@ function bindEvents () { let timeId // Prevent to Fold sidebar - Docsify.dom.on($search, 'click', - e => e.target.tagName !== 'A' && e.stopPropagation()) + Docsify.dom.on( + $search, + 'click', + e => e.target.tagName !== 'A' && e.stopPropagation() + ) Docsify.dom.on($input, 'input', e => { clearTimeout(timeId) timeId = setTimeout(_ => doSearch(e.target.value.trim()), 100) @@ -151,4 +154,3 @@ export function update (opts, vm) { updatePlaceholder(opts.placeholder, vm.route.path) updateNoData(opts.noData, vm.route.path) } - diff --git a/src/themes/basic/_coverpage.css b/src/themes/basic/_coverpage.css index a5f4b061..397f3aa2 100644 --- a/src/themes/basic/_coverpage.css +++ b/src/themes/basic/_coverpage.css @@ -12,7 +12,7 @@ section.cover { &.has-mask .mask { background-color: $color-bg; - opacity: .8; + opacity: 0.8; position: absolute; size: 100%; } @@ -42,7 +42,7 @@ section.cover { color: inherit; font-size: 2.5rem; font-weight: 300; - margin: .625rem 0 2.5rem; + margin: 0.625rem 0 2.5rem; position: relative; text-align: center; @@ -92,7 +92,7 @@ section.cover { &:hover { color: inherit; - opacity: .8; + opacity: 0.8; } } @@ -103,7 +103,7 @@ section.cover { blockquote > p > a { border-bottom: 2px solid var(--theme-color, $color-primary); - transition: color .3s; + transition: color 0.3s; &:hover { color: var(--theme-color, $color-primary); diff --git a/src/themes/basic/_layout.css b/src/themes/basic/_layout.css index 222249a0..d05e7457 100644 --- a/src/themes/basic/_layout.css +++ b/src/themes/basic/_layout.css @@ -10,7 +10,9 @@ body:not(.ready) { overflow: hidden; - [data-cloak], .app-nav, > nav { + [data-cloak], + .app-nav, + > nav { display: none; } } @@ -22,7 +24,7 @@ div#app { text-align: center; &:empty::before { - content: "Loading..."; + content: 'Loading...'; } } @@ -52,7 +54,8 @@ div#app { font-style: normal; } -html, body { +html, +body { height: 100%; } @@ -77,7 +80,7 @@ kbd { display: inline-block; font-size: 12px !important; line-height: 12px; - margin-bottom : 3px; + margin-bottom: 3px; padding: 3px 5px; vertical-align: middle; } @@ -99,12 +102,13 @@ kbd { margin: 0; } - >a { + > a { margin: 0 1rem; padding: 5px 0; } - ul, li { + ul, + li { display: inline-block; list-style: none; margin: 0; @@ -114,7 +118,7 @@ kbd { color: inherit; font-size: 16px; text-decoration: none; - transition: color .3s; + transition: color 0.3s; &:hover { color: var(--theme-color, $color-primary); @@ -186,7 +190,7 @@ kbd { z-index: 1; &:hover .octo-arm { - animation:octocat-wave 560ms ease-in-out; + animation: octocat-wave 560ms ease-in-out; } svg { @@ -207,7 +211,7 @@ main { .anchor { display: inline-block; text-decoration: none; - transition: all .3s; + transition: all 0.3s; span { color: $color-text; @@ -220,7 +224,7 @@ main { /* sidebar */ .sidebar { - border-right: 1px solid rgba(0, 0, 0, .07); + border-right: 1px solid rgba(0, 0, 0, 0.07); overflow-y: auto; padding: 40px 0; position: absolute 0 * 0 0; @@ -254,12 +258,13 @@ main { padding: 0; } - li>p { + li > p { font-weight: 700; margin: 0; } - ul, ul li { + ul, + ul li { list-style: none; } @@ -293,20 +298,20 @@ main { /* sidebar toggle */ .sidebar-toggle { background-color: transparent; - background-color: rgba($color-bg, .8); + background-color: rgba($color-bg, 0.8); border: 0; outline: none; outline: none; padding: 10px; position: absolute * * 0 0; text-align: center; - transition: opacity .3s; + transition: opacity 0.3s; width: 30px; width: calc($sidebar-width - 16px); z-index: 30; .sidebar-toggle-button:hover { - opacity: .4; + opacity: 0.4; } span { @@ -318,7 +323,8 @@ main { } body.sticky { - .sidebar, .sidebar-toggle { + .sidebar, + .sidebar-toggle { position: fixed; } } @@ -342,8 +348,8 @@ body.sticky { font-size: inherit; } - >:first-child { - margin-top: 0!important; + > :first-child { + margin-top: 0 !important; } } @@ -393,7 +399,7 @@ body.sticky { background-color: #f66; border-radius: 100%; color: $color-bg; - content: "!"; + content: '!'; font-family: 'Dosis', 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif; font-size: 14px; font-weight: bold; @@ -435,7 +441,9 @@ body.close { } @media print { - .github-corner, .sidebar-toggle, .sidebar { + .github-corner, + .sidebar-toggle, + .sidebar { display: none; } @@ -445,7 +453,9 @@ body.close { } @media screen and (max-width: 768px) { - .github-corner, .sidebar-toggle, .sidebar { + .github-corner, + .sidebar-toggle, + .sidebar { position: fixed; } @@ -475,7 +485,8 @@ body.close { transition: transform 250ms ease; } - .app-nav, .github-corner { + .app-nav, + .github-corner { transition: transform 250ms ease-out; } @@ -490,7 +501,7 @@ body.close { } .sidebar-toggle { - background-color: rgba($color-bg, .8); + background-color: rgba($color-bg, 0.8); transition: 1s background-color; width: calc($sidebar-width - 16px); } @@ -499,7 +510,8 @@ body.close { transform: translateX($sidebar-width); } - .app-nav, .github-corner { + .app-nav, + .github-corner { display: none; } } @@ -515,7 +527,16 @@ body.close { } @keyframes octocat-wave { - 0%,100% { transform: rotate(0); } - 20%,60% { transform: rotate(-25deg); } - 40%,80% { transform: rotate(10deg); } + 0%, + 100% { + transform: rotate(0); + } + 20%, + 60% { + transform: rotate(-25deg); + } + 40%, + 80% { + transform: rotate(10deg); + } } diff --git a/src/themes/buble.css b/src/themes/buble.css index 56becf3e..c27c0948 100644 --- a/src/themes/buble.css +++ b/src/themes/buble.css @@ -1,12 +1,12 @@ @import url('https://fonts.googleapis.com/css?family=Inconsolata|Inconsolata-Bold'); -$color-primary: #0074D9; +$color-primary: #0074d9; $color-bg: #fff; $color-text: #34495e; $sidebar-width: 16rem; -@import "basic/layout"; -@import "basic/coverpage"; +@import 'basic/layout'; +@import 'basic/coverpage'; /* sidebar */ .sidebar { @@ -160,7 +160,7 @@ $sidebar-width: 16rem; } .namespace { - opacity: .7; + opacity: 0.7; } .token.property, @@ -216,7 +216,7 @@ $sidebar-width: 16rem; cursor: help; } -.markdown-section pre>code { +.markdown-section pre > code { background-color: #f8f8f8; border-radius: 2px; display: block; @@ -229,7 +229,8 @@ $sidebar-width: 16rem; white-space: inherit; } -.markdown-section code::after, .markdown-section code::before { +.markdown-section code::after, +.markdown-section code::before { letter-spacing: 0.05rem; } diff --git a/src/themes/dark.css b/src/themes/dark.css index ed8afc47..0301271b 100644 --- a/src/themes/dark.css +++ b/src/themes/dark.css @@ -5,8 +5,8 @@ $color-bg: #3f3f3f; $color-text: #c8c8c8; $sidebar-width: 300px; -@import "basic/layout"; -@import "basic/coverpage"; +@import 'basic/layout'; +@import 'basic/coverpage'; body { background-color: $color-bg; @@ -38,7 +38,7 @@ body { padding: 0; } - ul li.active>a { + ul li.active > a { color: var(--theme-color, $color-primary); font-weight: 600; } @@ -71,7 +71,7 @@ body { .markdown-section h3 { font-size: 1.5rem; - margin: 40px 0 .6rem; + margin: 40px 0 0.6rem; } .markdown-section h4 { @@ -159,7 +159,7 @@ body { } .token.namespace { - opacity: .7; + opacity: 0.7; } .token.boolean, @@ -246,7 +246,7 @@ body { cursor: help; } -.markdown-section pre>code { +.markdown-section pre > code { -moz-osx-font-smoothing: initial; -webkit-font-smoothing: initial; background-color: #282828; @@ -263,7 +263,8 @@ body { white-space: inherit; } -.markdown-section code::after, .markdown-section code::before { +.markdown-section code::after, +.markdown-section code::before { letter-spacing: 0.05rem; } @@ -292,7 +293,7 @@ pre::after { color: #657b83; } -input[type="search"] { +input[type='search'] { background: #4f4f4f; border-color: #4f4f4f; color: #c8c8c8; diff --git a/src/themes/pure.css b/src/themes/pure.css index 60350e86..503b412e 100644 --- a/src/themes/pure.css +++ b/src/themes/pure.css @@ -2,5 +2,5 @@ $color-primary: #000; $color-bg: #fff; $color-text: #000; $sidebar-width: 300px; -@import "basic/layout"; -@import "basic/coverpage"; +@import 'basic/layout'; +@import 'basic/coverpage'; diff --git a/src/themes/vue.css b/src/themes/vue.css index 704317da..56b0485c 100644 --- a/src/themes/vue.css +++ b/src/themes/vue.css @@ -5,8 +5,8 @@ $color-bg: #fff; $color-text: #34495e; $sidebar-width: 300px; -@import "basic/layout"; -@import "basic/coverpage"; +@import 'basic/layout'; +@import 'basic/coverpage'; body { background-color: $color-bg; @@ -39,7 +39,7 @@ body { padding: 0; } - ul li.active>a { + ul li.active > a { border-right: 2px solid; color: var(--theme-color, $color-primary); font-weight: 600; @@ -82,7 +82,7 @@ body { .markdown-section h3 { font-size: 1.5rem; - margin: 40px 0 .6rem; + margin: 40px 0 0.6rem; } .markdown-section h4 { @@ -170,7 +170,7 @@ body { } .token.namespace { - opacity: .7; + opacity: 0.7; } .token.boolean, @@ -257,7 +257,7 @@ body { cursor: help; } -.markdown-section pre>code { +.markdown-section pre > code { -moz-osx-font-smoothing: initial; -webkit-font-smoothing: initial; background-color: #f8f8f8; @@ -274,7 +274,8 @@ body { white-space: inherit; } -.markdown-section code::after, .markdown-section code::before { +.markdown-section code::after, +.markdown-section code::before { letter-spacing: 0.05rem; }