Skip to content

Commit

Permalink
feat: use remark-github (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz authored Jul 12, 2021
1 parent 734fdca commit 98c3603
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions src/core/parser/markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ async function parse(file, options) {
}
}

export function useMarkdownParser(options: Partial<MarkdownParserOptions> = {}) {
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<MarkdownParserOptions>) {
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),
Expand Down
15 changes: 15 additions & 0 deletions src/github/module.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -10,6 +11,20 @@ export default <Module>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<ParserOptions>) => {
if (!options.markdown.remarkPlugins) {
options.markdown.remarkPlugins = []
}

options.markdown.remarkPlugins.push([
'remark-github',
{
repository
}
])
})

hook('docus:storage:ready', () => {
// Fetch releases
Expand Down
11 changes: 10 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 98c3603

Please sign in to comment.