Add files via upload

This commit is contained in:
Crizomb 2023-04-07 15:20:38 +02:00 committed by GitHub
parent d70528cb6e
commit ac119effe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 381 additions and 0 deletions

View 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