Skip to content

Commit

Permalink
Add c/cpp code support (#8665)
Browse files Browse the repository at this point in the history
* Add c/cpp code support

* lint

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
ginazhouhuiwu and gradio-pr-bot committed Jul 1, 2024
1 parent 2943d6d commit 3b8238c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/light-gifts-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/code": minor
"gradio": minor
---

feat:Add c/cpp code support
4 changes: 4 additions & 0 deletions gradio/components/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Code(Component):

languages = [
"python",
"c",
"cpp",
"markdown",
"json",
"html",
Expand Down Expand Up @@ -60,6 +62,8 @@ def __init__(
value: str | Callable | tuple[str] | None = None,
language: Literal[
"python",
"c",
"cpp",
"markdown",
"json",
"html",
Expand Down
4 changes: 3 additions & 1 deletion js/code/shared/Download.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
dockerfile: "dockerfile",
sh: "sh",
shell: "sh",
r: "r"
r: "r",
c: "c",
cpp: "cpp"
};
return exts[type] || "txt";
Expand Down
11 changes: 11 additions & 0 deletions js/code/shared/language.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { Extension } from "@codemirror/state";
import { StreamLanguage } from "@codemirror/language";
import { sql } from "@codemirror/legacy-modes/mode/sql";
import { _ } from "svelte-i18n";

const possible_langs = [
"python",
"c",
"cpp",
"markdown",
"json",
"html",
Expand Down Expand Up @@ -35,6 +38,14 @@ const sql_dialects = [

const lang_map: Record<string, (() => Promise<Extension>) | undefined> = {
python: () => import("@codemirror/lang-python").then((m) => m.python()),
c: () =>
import("@codemirror/legacy-modes/mode/clike").then((m) =>
StreamLanguage.define(m.c)
),
cpp: () =>
import("@codemirror/legacy-modes/mode/clike").then((m) =>
StreamLanguage.define(m.cpp)
),
markdown: async () => {
const [md, frontmatter] = await Promise.all([
import("@codemirror/lang-markdown"),
Expand Down

0 comments on commit 3b8238c

Please sign in to comment.