Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

feat(server): add more language - yml, gql, c#, jsonc, java #353

Merged
merged 2 commits into from
Nov 11, 2021
Merged
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
5 changes: 5 additions & 0 deletions .changeset/quick-goats-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guild-docs/server': patch
---

feat(server): add more language - yml,gql,c#,jsonc,java
12 changes: 12 additions & 0 deletions examples/basic/docs/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ const getEnveloped = envelop({
});
```

```gql
type Query {
hello: String!
}
```

```gql
query {
hello
}
```

#### Heading 4

Volutpat ac tincidunt vitae semper quis lectus. Risus viverra adipiscing at in. Et malesuada fames ac turpis egestas integer eget aliquet. Sed nisi lacus sed viverra tellus in hac habitasse platea. In iaculis nunc sed augue. Ornare massa eget egestas purus viverra accumsan in. Eu mi bibendum neque egestas congue quisque egestas diam. Placerat orci nulla pellentesque dignissim enim. Augue interdum velit euismod in pellentesque. Lobortis elementum nibh tellus molestie nunc non blandit massa enim. Pellentesque elit ullamcorper dignissim cras tincidunt lobortis. Non blandit massa enim nec. Placerat in egestas erat imperdiet. Nisl pretium fusce id velit ut. Urna molestie at elementum eu facilisis sed odio. Maecenas volutpat blandit aliquam etiam erat velit scelerisque. Curabitur vitae nunc sed velit dignissim sodales ut. A cras semper auctor neque vitae tempus quam. Diam volutpat commodo sed egestas egestas. Tempus iaculis urna id volutpat.
Expand Down
8 changes: 8 additions & 0 deletions packages/server/src/mdx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ const MdxDeps = LazyPromise(async () => {
'ts',
'graphql',
'swift',
'java',
'jsonc',
'diff',
'csharp',
'c#',
'vue',
'html',
'svelte',
],
}),
import('./remarkShiki').then(v => v.withShiki()),
Expand Down
7 changes: 6 additions & 1 deletion packages/server/src/remarkShiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export interface Options {
ignoreUnknownLanguage?: boolean;
}

const LANGUAGE_ALIASES: Record<string, string> = {
'gql': 'graphql',
'yml': 'yaml',
};

export async function withShiki(): Promise<(options: Options) => Transformer> {
const { visit } = await import('unist-util-visit');

Expand All @@ -22,7 +27,7 @@ export async function withShiki(): Promise<(options: Options) => Transformer> {
const node: { value: string; lang: Lang; type: string } = nodeArg;
const lang = ignoreUnknownLanguage && !loadedLanguages.includes(node.lang) ? undefined : node.lang;

const highlighted = highlighter.codeToHtml(node.value, lang);
const highlighted = highlighter.codeToHtml(node.value, lang || LANGUAGE_ALIASES[node.lang]);
node.type = 'html';
node.value = highlighted;
};
Expand Down