Nymbo commited on
Commit
3cf27bd
·
verified ·
1 Parent(s): ef5091e

adding basic markdown live previeww

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import markdown
3
+ from markdown.extensions.tables import TableExtension
4
+ from markdown.extensions.fenced_code import FencedCodeExtension
5
+ from markdown.extensions.toc import TocExtension
6
+ from markdown.extensions.attr_list import AttrListExtension
7
+ from markdown.extensions.codehilite import CodeHiliteExtension
8
+
9
+ # Function to render markdown to HTML with extensions
10
+ def render_markdown(md_text):
11
+ return markdown.markdown(
12
+ md_text,
13
+ extensions=[
14
+ TableExtension(),
15
+ FencedCodeExtension(),
16
+ TocExtension(baselevel=2),
17
+ AttrListExtension(),
18
+ CodeHiliteExtension(linenums=False, css_class="highlight"),
19
+ ],
20
+ )
21
+
22
+ # Creating the Gradio Interface
23
+ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
24
+ gr.Markdown("# Markdown Suite")
25
+
26
+ with gr.Row():
27
+ with gr.Column():
28
+ md_input = gr.Textbox(
29
+ lines=20,
30
+ placeholder="Write your markdown here...",
31
+ label="Markdown Input",
32
+ elem_classes=["gr-textbox"]
33
+ )
34
+ with gr.Column():
35
+ md_output = gr.HTML(label="Rendered Output", elem_classes=["gr-html"])
36
+
37
+ md_input.change(render_markdown, inputs=md_input, outputs=md_output)
38
+
39
+ # Launch the app
40
+ demo.launch()