From 49af65f162fbe3bd95db5fb4802e14ce046ed5a5 Mon Sep 17 00:00:00 2001 From: Zhenghao Zhang Date: Tue, 5 Nov 2024 21:27:10 +0800 Subject: [PATCH] support AsciiDoc README --- app.py | 10 ++++++++++ requirements.txt | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 29509db..f469e25 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ import concurrent.futures +import io import json import logging import os @@ -6,9 +7,11 @@ from datetime import datetime from typing import List, Optional +import asciidoc3 import emoji import gorse import mistune +from asciidoc3.asciidoc3api import AsciiDoc3API from bs4 import BeautifulSoup from docutils.core import publish_parts from flask import Flask, Response, session, redirect, request, flash @@ -178,6 +181,13 @@ def get_repo(category: str = ""): content = repo.get_readme().decoded_content.decode("utf-8") if download_url.endswith(".rst"): html = publish_parts(content, writer_name="html")["html_body"] + elif download_url.endswith(".asciidoc"): + infile = io.StringIO(content) + outfile = io.StringIO() + asciidoc3api = AsciiDoc3API(asciidoc3.__path__[0] + '/asciidoc3.py') + asciidoc3api.options('--no-header-footer') + asciidoc3api.execute(infile, outfile, backend='html4') + html = outfile.getvalue() else: html = mistune.html(content) soup = BeautifulSoup(html, "html.parser") diff --git a/requirements.txt b/requirements.txt index 52a4c05..8a4a94a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +asciidoc3==3.2.3 beautifulsoup4==4.9.3 celery==5.2.7 docutils==0.17.1 @@ -5,7 +6,7 @@ emoji==1.6.1 Flask==2.3.2 flask-cors==4.0.2 Flask-Dance[sqla]==6.2.0 -flask-login==0.6.0 +flask-login==0.6.3 Flask-SQLAlchemy==2.5.1 gevent==23.9.1 gunicorn==22.0.0