From 0d48c70ad62622f85c21ebe7782b70214a33fa5c Mon Sep 17 00:00:00 2001 From: Francois Pelletier Date: Sat, 21 Jan 2023 19:02:35 -0500 Subject: [PATCH] =?UTF-8?q?ajout=20de=20formatage=20et=20de=20valeurs=20pa?= =?UTF-8?q?r=20d=C3=A9faut=20pour=20chacun=20des=20formats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 51 ++++++++++++++++++++++++++++++++++++++---------- requirements.txt | 3 ++- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 36451cc..c92cc70 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,8 @@ import datetime import streamlit as st import requests from pydantic import BaseModel +import mdformat +import os class DocumentSpecs(BaseModel): @@ -20,7 +22,8 @@ class DocumentSpecs(BaseModel): extension: str -import os +if 'options' not in st.session_state: + st.session_state['options'] = "" st.title("Fabrique à documents") @@ -29,7 +32,15 @@ fabriquedoc_endpoint = os.environ.get("FABRIQUEDOC_ENDPOINT", "http://0.0.0.0:80 tab1, tab2, tab3 = st.tabs(["Markdown", "Aperçu", "Paramètres"]) with tab1: - content = st.text_area("Enter Markdown text to send:", "# Titre\n## sous-titre\nContenu\n> Citation\n", height=450) + def button1_callback(): + st.session_state['markdown'] = mdformat.text(st.session_state['markdown'], + options={"number": True}) + + + content = st.text_area("Enter Markdown text to send:", "# Titre\n## sous-titre\nContenu\n> Citation\n", + height=450, + key='markdown') + st.button("Formater le texte", on_click=button1_callback) with tab2: st.write("Aperçu") @@ -45,15 +56,35 @@ with tab3: response_formats = requests.get(f"{fabriquedoc_endpoint}/formats/{selected_style}/") formats = response_formats.json()["formats"] selected_format = st.selectbox("Select a format:", formats) + # Autres paramètres - linkcolor = st.text_input("Link color:", value="blue") - tocdepth = st.number_input("Table of Contents depth:", value=2, min_value=1, max_value=5, step=1) - pdfengine = st.text_input("PDF engine:", value="lualatex") - fontsize = st.number_input("Font size:", value=14, step=1) - paperwidth = st.number_input("Paper width:", value=1080, step=30) - paperheight = st.number_input("Paper height:", value=1080, step=30) - margin = st.number_input("Margin:", value=180, step=10) - vmargin = st.number_input("Vertical margin:", value=180, step=10) + response_format_parameters = requests.get(f"{fabriquedoc_endpoint}/format_parameters/{selected_style}/{selected_format}") + format_parameters = response_format_parameters.json() + st.write(format_parameters) + linkcolor = st.text_input("Link color:", + value=format_parameters.get("linkcolor")) + tocdepth = st.number_input("Table of Contents depth:", + value=int(format_parameters.get("tocdepth")), + min_value=1, + max_value=5, + step=1) + pdfengine = st.text_input("PDF engine:", + value=format_parameters.get("pdfengine")) + fontsize = st.number_input("Font size:", + value=int(format_parameters.get("fontsize")), + step=1) + paperwidth = st.number_input("Paper width:", + value=int(format_parameters.get("paperwidth")), + step=30) + paperheight = st.number_input("Paper height:", + value=int(format_parameters.get("paperheight")), + step=30) + margin = st.number_input("Margin:", + value=int(format_parameters.get("margin")), + step=10) + vmargin = st.number_input("Vertical margin:", + value=int(format_parameters.get("vmargin")), + step=10) extension = st.selectbox("Extension:", ["png", "jpg", "pdf"]) # Envoi if st.button("Generate post"): diff --git a/requirements.txt b/requirements.txt index 31aedd3..c7a7d05 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ streamlit~=1.16.0 requests~=2.28.1 -pydantic~=1.10.2 \ No newline at end of file +pydantic~=1.10.2 +mdformat~=0.7.16 \ No newline at end of file