Add files via upload
This commit is contained in:
parent
d70528cb6e
commit
ac119effe4
10 changed files with 381 additions and 0 deletions
24
chatgpt_code_interface/formating_tools.py
Normal file
24
chatgpt_code_interface/formating_tools.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import bs4
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
CodeBloc = namedtuple('CodeBloc', ['language', 'code'])
|
||||
|
||||
def remove_trailing_newline(s):
|
||||
if s.endswith('\n'):
|
||||
return s[:-1]
|
||||
return s
|
||||
def isolate_code_bloc(soup):
|
||||
pre_tab = soup.find_all("pre")
|
||||
code_bloc = []
|
||||
for code in pre_tab:
|
||||
#print(code.text)
|
||||
motif = "Copy code"
|
||||
finding = code.text.find(motif)
|
||||
code_content = code.text[finding+len(motif):]
|
||||
language = code.text[:finding]
|
||||
code_bloc.append(CodeBloc(language.strip(), remove_trailing_newline(code_content)))
|
||||
|
||||
print(code_bloc)
|
||||
return code_bloc
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue