Skip to content

Commit

Permalink
syntax highlithing
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltorio committed Oct 21, 2024
1 parent 88e1b68 commit 41d7695
Show file tree
Hide file tree
Showing 4 changed files with 725 additions and 494 deletions.
30 changes: 28 additions & 2 deletions rapidoc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { OpenAPISnippets } from '@sctg/openapi-snippet';
import type { paths, components } from 'openapi3';

import 'rapidoc';
import '@sctg/rapidoc';
type OpenAPI3 = {
openapi: string;
info: {
Expand All @@ -19,6 +19,31 @@ type OpenAPI3 = {
basePath?: string;
}

function getPrismLanguage(lang: string): string {
if (lang === 'shell_curl') {
return 'bash';
}
if (lang === 'javascript_fetch') {
return 'javascript';
}
if (lang === 'c') {
return 'c';
}
if (lang === 'php') {
return 'php';
}
if (lang === 'go') {
return 'go';
}
if (lang === 'rust') {
return 'rust';
}
if (lang === 'python') {
return 'python';
}
return lang;
}

window.addEventListener('DOMContentLoaded', (event) => {
const rapidocEl = document.getElementById('rapidoc') as any;
const spec_url = (window as any).SPEC_URL;
Expand All @@ -40,10 +65,11 @@ window.addEventListener('DOMContentLoaded', (event) => {
const code_samples = [];
for (let snippet of snippets.snippets) {
code_samples.push({
lang: snippet.id,
lang: getPrismLanguage(snippet.id),
label: snippet.title,
source: snippet.content
});
console.log(JSON.stringify(code_samples[code_samples.length - 1], null, 2));
}
if (pathItem !== undefined && pathItem['x-code-samples' as keyof typeof pathItem] === undefined) {
(pathItem as any)['x-code-samples'] = code_samples;
Expand Down
Loading

0 comments on commit 41d7695

Please sign in to comment.