From 98c3603f321deb96e44fb4c0d777042445fe3ba7 Mon Sep 17 00:00:00 2001 From: Ahad Birang Date: Mon, 12 Jul 2021 21:13:51 +0430 Subject: [PATCH] feat: use remark-github (#538) --- package.json | 1 + src/core/parser/markdown/index.ts | 12 ++++++++---- src/github/module.ts | 15 +++++++++++++++ yarn.lock | 11 ++++++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3673137ff..0cdb65470 100755 --- a/package.json +++ b/package.json @@ -106,6 +106,7 @@ "remark-external-links": "^8.0.0", "remark-footnotes": "^3.0.0", "remark-gfm": "^1.0.0", + "remark-github": "^10.1.0", "remark-parse": "^9.0.0", "remark-rehype": "^8.1.0", "remark-slug": "^6.0.0", diff --git a/src/core/parser/markdown/index.ts b/src/core/parser/markdown/index.ts index fe2d17b5d..8b9be76ab 100644 --- a/src/core/parser/markdown/index.ts +++ b/src/core/parser/markdown/index.ts @@ -66,10 +66,14 @@ async function parse(file, options) { } } -export function useMarkdownParser(options: Partial = {}) { - options = defu(options, DEFAULTS) - options.remarkPlugins.unshift([resolve(__dirname, './directive/remark-plugin'), { directives: options.directives }]) - processOptions(options) +let options: MarkdownParserOptions = DEFAULTS +export function useMarkdownParser(parserOptions?: Partial) { + if (parserOptions) { + options = defu(parserOptions, DEFAULTS) + + options.remarkPlugins.unshift([resolve(__dirname, './directive/remark-plugin'), { directives: options.directives }]) + processOptions(options) + } return { parseFrontMatter: (content: string) => parseFrontMatter(content), diff --git a/src/github/module.ts b/src/github/module.ts index 19fda8b07..aebdcd109 100644 --- a/src/github/module.ts +++ b/src/github/module.ts @@ -1,5 +1,6 @@ import { Module } from '@nuxt/types' import defu from 'defu' +import { ParserOptions } from '../types' import { useStorage } from '../core/storage' import { fetch } from './github' import githubDefaults from './settings' @@ -10,6 +11,20 @@ export default function docusGithubModule() { const settings = this.$docus.settings settings.github = defu(settings.github, githubDefaults) + const repository = typeof settings.github.releases === 'string' ? settings.github.releases : settings.github.repo + + hook('docus:parserOptions', (options: Partial) => { + if (!options.markdown.remarkPlugins) { + options.markdown.remarkPlugins = [] + } + + options.markdown.remarkPlugins.push([ + 'remark-github', + { + repository + } + ]) + }) hook('docus:storage:ready', () => { // Fetch releases diff --git a/yarn.lock b/yarn.lock index d9e8189fb..3f69799c8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8635,7 +8635,7 @@ mdast-util-directive@^1.0.0: stringify-entities "^3.1.0" unist-util-visit-parents "^3.0.0" -mdast-util-find-and-replace@^1.1.0: +mdast-util-find-and-replace@^1.0.0, mdast-util-find-and-replace@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/mdast-util-find-and-replace/-/mdast-util-find-and-replace-1.1.1.tgz#b7db1e873f96f66588c321f1363069abf607d1b5" integrity sha512-9cKl33Y21lyckGzpSmEQnIDjEfeeWelN5s1kUW1LwdB0Fkuq2u+4GdqcGEygYxJE8GVqCl0741bYXHgamfWAZA== @@ -11620,6 +11620,15 @@ remark-gfm@^1.0.0: mdast-util-gfm "^0.1.0" micromark-extension-gfm "^0.3.0" +remark-github@^10.1.0: + version "10.1.0" + resolved "https://registry.yarnpkg.com/remark-github/-/remark-github-10.1.0.tgz#1c2777c1d4082b56d7890af656a0a525e49cacfc" + integrity sha512-q0BTFb41N6/uXQVkxRwLRTFRfLFPYP+8li26Js5XC0GKritCSaxrftd+t+8sfN+1i9BtmJPUKoS7CZwtccj0Fg== + dependencies: + mdast-util-find-and-replace "^1.0.0" + mdast-util-to-string "^1.0.0" + unist-util-visit "^2.0.0" + remark-parse@^9.0.0: version "9.0.0" resolved "https://registry.yarnpkg.com/remark-parse/-/remark-parse-9.0.0.tgz#4d20a299665880e4f4af5d90b7c7b8a935853640"