Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5c9f86

Browse filesBrowse files
committed
fix loading language
1 parent 43a5534 commit c5c9f86
Copy full SHA for c5c9f86

File tree

Expand file treeCollapse file tree

12 files changed

+788
-25
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+788
-25
lines changed

‎src/App.vue

Copy file name to clipboardExpand all lines: src/App.vue
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
</template>
1414

1515
<script setup lang="ts">
16-
import { CodeBlock } from '../dist';
16+
import { CodeBlock } from './components/code-block';
1717
const code = `console.log('Hello');
1818
const name = 'World';
19+
def greet(name) {
20+
console.log('Hello, ' + name);
21+
}
1922
`;
2023
</script>
2124

‎src/components/code/Code.vue

Copy file name to clipboardExpand all lines: src/components/code/Code.vue
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
1919
const props = defineProps(codeProps());
2020
21-
// Create a computed property for userCode
22-
// const userCode = computed(() => {
23-
// return highlightedCode(props.value.code, props.value.language);
24-
// });
25-
2621
defineComponent<codeInstance>({
2722
name: 'Code',
2823
props: codeProps(),
+108Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// // This code is from prism-react-renderer:
2+
// // https://github.com/FormidableLabs/prism-react-renderer/blob/master/packages/generate-prism-languages/index.ts
3+
// // Thanks @FormidableLabs.
4+
5+
// // @ts-ignore
6+
// import flowRight from 'lodash.flowright';
7+
// import * as pc from 'picocolors';
8+
// import { readFile, writeFile, access } from 'node:fs/promises';
9+
// import { constants } from 'node:fs';
10+
// import { join, dirname } from 'node:path';
11+
// import { languages as prismLanguages } from 'prismjs/components';
12+
// import * as uglify from 'uglify-js';
13+
14+
// export const languagesToBundle = <const>[
15+
// 'markup',
16+
// 'jsx',
17+
// 'tsx',
18+
// 'swift',
19+
// 'kotlin',
20+
// 'objectivec',
21+
// 'js-extras',
22+
// 'reason',
23+
// 'rust',
24+
// 'graphql',
25+
// 'yaml',
26+
// 'go',
27+
// 'cpp',
28+
// 'markdown',
29+
// 'python',
30+
// 'json'
31+
// ];
32+
33+
// /**
34+
// * We need to disable typechecking on this generated file as it's just concatenating JS code
35+
// * that starts off assuming Prism lives in global scope. We also need to provide Prism as that
36+
// * gets passed into an iffe preventing us from needing to use global scope.
37+
// */
38+
// const header = `// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\nimport * as Prism from "prismjs";\nexport { Prism };`;
39+
// const prismPath = dirname(require.resolve('prismjs'));
40+
41+
// const readLanguageFile = async (language: string): Promise<string> => {
42+
// const pathToLanguage = join(prismPath, `components/prism-${language}.js`);
43+
// await access(pathToLanguage, constants.R_OK);
44+
// const buffer = await readFile(pathToLanguage, { encoding: 'utf-8' });
45+
// return buffer.toString();
46+
// };
47+
48+
// const strArrayFromUnknown = (input: unknown) => (array: string[]) => {
49+
// if (typeof input === 'string') array.push(input);
50+
// else if (Array.isArray(input)) array = array.concat(input);
51+
// return array;
52+
// };
53+
54+
// const main = async () => {
55+
// let output = '';
56+
// const bundledLanguages = new Set<keyof typeof prismLanguages>();
57+
// const orderBundled = new Set<keyof typeof prismLanguages>();
58+
// const outputPath = join(__dirname, '../prism-langs.ts');
59+
60+
// const addLanguageToOutput = async (language?: string) => {
61+
// if (bundledLanguages.has(language)) {
62+
// return;
63+
// }
64+
// if (language == null || prismLanguages[language] == null) {
65+
// return;
66+
// }
67+
// bundledLanguages.add(language);
68+
69+
// /**
70+
// * We need to ensure any language dependencies are bundled first
71+
// */
72+
// const prismLang = prismLanguages[language];
73+
// const deps = flowRight(
74+
// strArrayFromUnknown(prismLang.require),
75+
// strArrayFromUnknown(prismLang.optional)
76+
// )([]);
77+
// const peerDeps = strArrayFromUnknown(prismLang.peerDependencies)([]);
78+
79+
// for await (const language of deps) {
80+
// await addLanguageToOutput(language);
81+
// }
82+
83+
// output += await readLanguageFile(language);
84+
// orderBundled.add(language);
85+
86+
// for await (const language of peerDeps) {
87+
// await addLanguageToOutput(language);
88+
// }
89+
// };
90+
91+
// for await (const language of languagesToBundle) {
92+
// await addLanguageToOutput(language);
93+
// }
94+
95+
// console.info(pc.bold(pc.bgYellow(pc.black('Prism Renderer'))), '\n');
96+
// console.info(
97+
// pc.bgBlue(`Generated TypeScript output at:`),
98+
// pc.cyan(outputPath)
99+
// );
100+
// console.info(
101+
// pc.bgGreen(`Included language definitions in the following order:`),
102+
// Array.from(orderBundled.values()).join(', ')
103+
// );
104+
105+
// await writeFile(outputPath, header + uglify.minify(output).code);
106+
// };
107+
108+
// main();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.