# 安裝必要的套件 !pip install python-pptx markdown beautifulsoup4 # 將Markdown轉換為PPT from pptx import Presentation from pptx.util import Inches import markdown from bs4 import BeautifulSoup # 你的Markdown內容 md_text = """ ## 課程大綱 ### 第一週:課程介紹與數位轉型概述 - 課程介紹與期望 - 數位轉型的定義與重要性 - 成功數位轉型案例分享 ### 第二週:數位技術基礎 - 雲端運算 - 大數據分析 - 物聯網(IoT) - 人工智慧(AI) """ # 將Markdown轉換為HTML html = markdown.markdown(md_text) # 使用BeautifulSoup解析HTML soup = BeautifulSoup(html, "html.parser") # 創建PPT prs = Presentation() # 添加標題幻燈片 title_slide_layout = prs.slide_layouts[0] slide = prs.slides.add_slide(title_slide_layout) title = slide.shapes.title subtitle = slide.placeholders[1] title.text = "課程綱要" subtitle.text = "" # 添加普通幻燈片 bullet_slide_layout = prs.slide_layouts[1] for elem in soup.find_all(['h1', 'h2', 'h3', 'ul']): if elem.name in ['h1', 'h2', 'h3']: slide = prs.slides.add_slide(bullet_slide_layout) shapes = slide.shapes title_shape = shapes.title body_shape = shapes.placeholders[1] title_shape.text = elem.text text_frame = body_shape.text_frame text_frame.text = "" if elem.name == 'ul': for li in elem.find_all('li'): p = text_frame.add_paragraph() p.text = li.text p.level = 1 # 保存PPT prs.save("/content/課程綱要.pptx") print("PPT已保存為課程綱要.pptx") # 下載PPT文件 from google.colab import files files.download('/content/課程綱要.pptx')