acecalisto3 commited on
Commit
d5fb735
·
verified ·
1 Parent(s): 6c6faf7

Update code_editor.py

Browse files
Files changed (1) hide show
  1. code_editor.py +9 -19
code_editor.py CHANGED
@@ -1,32 +1,22 @@
1
  import json
2
 
3
- def code_editor(value: str = "", issue_num: int = 0, label: str = "") -> str:
4
  """
5
  Returns an HTML snippet for a CodeMirror-based code editor.
6
 
7
  Args:
8
  value (str): Initial content for the code editor.
9
  issue_num (int): The issue number to identify the editor instance.
10
- label (str): Optional label for the editor.
 
11
 
12
  Returns:
13
  str: HTML string that embeds a CodeMirror editor.
14
  """
15
- # You can include the label in the HTML if needef code_editor(value: str = "", issue_num: int = 0, label: str = "") -> str:
16
- """
17
- Returns an HTML snippet for a CodeMirror-based code editor.
18
-
19
- Args:
20
- value (str): Initial content for the code editor.
21
- issue_num (int): The issue number to identify the editor instance.
22
- label (str): Optional label for the editor.
23
-
24
- Returns:
25
- str: HTML string that embeds a CodeMirror editor.
26
- """
27
- # You can include the label in the HTML if needed
28
  html = f"""
29
- <div>{label}</div> <!-- Display the label -->
30
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.3/codemirror.min.css">
31
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.3/theme/material-darker.min.css">
32
 
@@ -36,7 +26,7 @@ def code_editor(value: str = "", issue_num: int = 0, label: str = "") -> str:
36
 
37
  <style>
38
  /* Basic styling for the editor container */
39
- #code-editor-container-{issue_num} {{
40
  border: 1px solid #ccc;
41
  border-radius: 4px;
42
  overflow: hidden;
@@ -48,7 +38,7 @@ def code_editor(value: str = "", issue_num: int = 0, label: str = "") -> str:
48
  }}
49
  </style>
50
 
51
- <div id="code-editor-container-{issue_num}">
52
  <textarea id="code-editor-{issue_num}">{value}</textarea>
53
  </div>
54
 
@@ -56,7 +46,7 @@ def code_editor(value: str = "", issue_num: int = 0, label: str = "") -> str:
56
  // Initialize CodeMirror on the textarea after it is loaded
57
  document.addEventListener("DOMContentLoaded", function() {{
58
  var editor = CodeMirror.fromTextArea(document.getElementById("code-editor-{issue_num}"), {{
59
- lineNumbers: true,
60
  mode: "python", // Change this to "javascript" or any other mode as needed
61
  theme: "material-darker",
62
  tabSize: 4
 
1
  import json
2
 
3
+ def code_editor(value: str = "", issue_num: int = 0, elem_id: str = None, **kwargs) -> str:
4
  """
5
  Returns an HTML snippet for a CodeMirror-based code editor.
6
 
7
  Args:
8
  value (str): Initial content for the code editor.
9
  issue_num (int): The issue number to identify the editor instance.
10
+ elem_id (str, optional): ID for the HTML element.
11
+ **kwargs: Additional keyword arguments (ignored).
12
 
13
  Returns:
14
  str: HTML string that embeds a CodeMirror editor.
15
  """
16
+ # Use elem_id if provided, otherwise use issue_num for the container ID
17
+ container_id = elem_id if elem_id else f"code-editor-container-{issue_num}"
18
+
 
 
 
 
 
 
 
 
 
 
19
  html = f"""
 
20
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.3/codemirror.min.css">
21
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.3/theme/material-darker.min.css">
22
 
 
26
 
27
  <style>
28
  /* Basic styling for the editor container */
29
+ #{container_id} {{
30
  border: 1px solid #ccc;
31
  border-radius: 4px;
32
  overflow: hidden;
 
38
  }}
39
  </style>
40
 
41
+ <div id="{container_id}">
42
  <textarea id="code-editor-{issue_num}">{value}</textarea>
43
  </div>
44
 
 
46
  // Initialize CodeMirror on the textarea after it is loaded
47
  document.addEventListener("DOMContentLoaded", function() {{
48
  var editor = CodeMirror.fromTextArea(document.getElementById("code-editor-{issue_num}"), {{
49
+ lineNumbers : true,
50
  mode: "python", // Change this to "javascript" or any other mode as needed
51
  theme: "material-darker",
52
  tabSize: 4