Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: SQL examples federation #14852

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 535,11 @@ export const database: NavMenuConstant = {
{ name: 'Configuring Timezones', url: '/guides/database/managing-timezones' },
],
},
{
name: 'Community',
url: undefined,
items: [{ name: 'Examples', url: '/guides/database/community/examples' }],
},
{
name: 'Extensions',
url: undefined,
Expand Down
209 changes: 209 additions & 0 deletions apps/docs/lib/mdx/plugins/remarkComment.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,209 @@
import { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown'
import { Options as ToMarkdownExtension } from 'mdast-util-to-markdown'
import { codes } from 'micromark-util-symbol/codes.js'
import { types } from 'micromark-util-symbol/types.js'
import { HtmlExtension, Extension as MicromarkExtension, Tokenizer } from 'micromark-util-types'
import { Plugin } from 'unified'
import { Node } from 'unist'

declare module 'micromark-util-types' {
export interface TokenTypeMap {
comment: 'comment'
}
}

declare module 'mdast' {
interface BlockContentMap {
comment: CommentElement
}
}

declare module 'mdast-util-to-markdown' {
interface ConstructNameMap {
comment: 'comment'
}
}

export interface CommentElement extends Node {
type: 'comment'
value: string
commentValue: string
}

export type RemarkCommentOptions = {
ast?: boolean
}

export function commentFromMarkdown(options: RemarkCommentOptions): FromMarkdownExtension {
return {
canContainEols: ['comment'],
enter: {
comment() {
this.buffer()
},
},
exit: {
comment(token) {
const text = this.resume()
if (options?.ast) {
this.enter(
{
type: 'comment',
value: '',
commentValue: text.slice(0, -2),
},
token
)
this.exit(token)
}
},
},
}
}

export const commentToMarkdown: ToMarkdownExtension = {
handlers: {
comment(node) {
return `<!--${node.commentValue.replace(/(?<=--)>/g, '\\>')}-->`
},
},
}

export const commentHtml: HtmlExtension = {
enter: {
comment() {
this.buffer()
},
},
exit: {
comment() {
this.resume()
this.setData('slurpOneLineEnding', true)
},
},
}

const tokenize: Tokenizer = function (effects, ok, nok) {
return start

function start(code) {
effects.enter('comment')
effects.consume(code)
return open
}

function open(code) {
if (code === codes.exclamationMark) {
effects.consume(code)
return declarationOpen
}

return nok(code)
}

function declarationOpen(code) {
if (code === codes.dash) {
effects.consume(code)
return commentOpen
}

return nok(code)
}

function commentOpen(code) {
if (code === codes.dash) {
effects.consume(code)
return commentStart
}

return nok(code)
}

function commentStart(code) {
if (code === codes.greaterThan) {
return nok(code)
}

effects.enter(types.data)

if (code === codes.dash) {
effects.consume(code)
return commentStartDash
}

return comment(code)
}

function commentStartDash(code) {
if (code === codes.greaterThan) {
return nok(code)
}

return comment(code)
}

function comment(code) {
if (code === codes.eof) {
return nok(code)
}

if (code === codes.dash) {
effects.consume(code)
return commentClose
}

effects.consume(code)
return comment
}

function commentClose(code) {
if (code === codes.dash) {
effects.consume(code)
return end
}

return comment(code)
}

function end(code) {
if (code === codes.greaterThan) {
effects.exit(types.data)
effects.consume(code)
effects.exit('comment')
return ok(code)
}

if (code === codes.dash) {
effects.consume(code)
return end
}

return comment(code)
}
}

export const comment: MicromarkExtension = {
flow: { [codes.lessThan]: { tokenize, concrete: true } },
text: { [codes.lessThan]: { tokenize } },
}

/**
* Parses HTML style comments as a different node type so it
* can be ignored during MDX serialization.
* ---
* _Copied from https://github.com/leebyron/remark-comment and
* modified to support multiline comments._
*
* _TODO: upstream the changes_
*/
const remarkComment: Plugin = function (options: RemarkCommentOptions) {
const data: Record<string, any> = this.data()
const add = (field, value) => (data[field] ? data[field] : (data[field] = [])).push(value)

add('micromarkExtensions', comment)
add('htmlExtensions', commentHtml)
add('fromMarkdownExtensions', commentFromMarkdown(options))
add('toMarkdownExtensions', commentToMarkdown)
}

export default remarkComment
18 changes: 18 additions & 0 deletions apps/docs/lib/mdx/plugins/remarkHeadingDepth.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,18 @@
import { Heading, Paragraph, Parent } from 'mdast'
import { MdxJsxFlowElement } from 'mdast-util-mdx'
import { visit } from 'unist-util-visit'

/**
* Shifts the depth of all headings by `shift`.
* Headings will be capped at 6 (the maximum depth).
*
* @example
* headingDepth(1) // h1 becomes h2, h2 becomes h3, etc
*/
export function headingDepth(shift = 0) {
return function transformer(root: Parent) {
visit(root, 'heading', (heading: Heading) => {
heading.depth = Math.min(shift, 6)
})
}
}
9 changes: 5 additions & 4 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 47,8 @@
"@algolia/autocomplete-plugin-recent-searches": "^1.7.2",
"@code-hike/mdx": "^0.8.3",
"@docsearch/react": "^3.3.0",
"@mdx-js/loader": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"@mdx-js/loader": "^2.3.0",
"@mdx-js/react": "^2.3.0",
"@next/bundle-analyzer": "^13.4.0",
"@next/mdx": "^12.0.4",
"@octokit/auth-app": "^4.0.9",
Expand Down Expand Up @@ -79,10 79,10 @@
"mdx-mermaid": "2.0.0-rc3",
"mermaid": "^10.0.2",
"micromark-extension-mdxjs": "^1.0.0",
"micromark-util-symbol": "^1.1.0",
"next": "12.3.2",
"next-compose-plugins": "^2.2.1",
"next-mdx-remote": "^4.1.0",
"next-mdx-toc": "^0.1.3",
"next-plugin-yaml": "^1.0.1",
"next-seo": "^5.14.1",
"next-transpile-modules": "^9.0.0",
Expand All @@ -95,12 95,12 @@
"react-syntax-highlighter": "^15.3.1",
"rehype-slug": "^5.1.0",
"remark": "^14.0.2",
"remark-admonitions": "^1.2.1",
"remark-gfm": "^3.0.1",
"remark-slug": "^7.0.1",
"shiki": "^0.11.1",
"sse.js": "^0.6.1",
"ui": "*",
"unified": "^10.1.2",
"unist-builder": "^3.0.1",
"unist-util-filter": "^4.0.1",
"unist-util-visit": "^4.1.2",
Expand All @@ -110,6 110,7 @@
},
"devDependencies": {
"@types/hast": "^2.3.4",
"@types/mdast": "^3.0.11",
"@types/node": "^17.0.12",
"@types/react": "17.0.39",
"@types/unist": "^2.0.6",
Expand Down
Loading