Internal¶
Basic Structure¶
Internally, Plate have 3 steps :
- Get API Document
- Convert markdown to HTML
- Highlight code according to programming languages
1. Get API Document
- Read markdown from API Document based on markdown format using
API_DOC_PATH
andAPI_DOC_INDEX_PATH
inconfig.json
. - Sort by
index.json
ofAPI_DOC_INDEX_PATH
.
2. Convert markdown to HTML
- Convert markdown to HTML using markdown python module
- Use markdown extensions : - fence_codes : markdown code block to html pre tag - tables : markdown table syntax to html table tag
def conv_md_to_html(md_text):
import markdown
return markdown.markdown(md_text, extensions=["fenced_code", "tables"])
3. Highlight code according to programming languages
- Use pygemnts for highlighting codes
- Support various programming languages and markup.
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.lexers import JavaLexer
from pygments.formatters import HtmlFormatter
highlighted = highlight(code, PythonLexer(), HtmlFormatter())
highlighted = highlight(code, JavaLexer(), HtmlFormatter())
Realtime monitoring API Document¶
For monitoring the modification of API Documents, use wachdog .
After the server start, the watchdog start and monitor all documents in API_DOC_PATH
of config.json
.
When the server stop, also the watchdog stop. In this process, use method watchdocs.watch_api_doc.start_watch
and watchdocs.watch_api_doc.stop_watch
.
If raise any modification fo files, run watchdocs.document_trace_handler.on_modified
method.
In this method, enqueue a event about the modification of any file to document_trace_queue
.
It is a instance of DocumentTraceQueue
singleton class.
And then, receive new request from user, Plate check document_trace_queue
whether a event exist or not.
If any event in queue, Plate load all API Documents and convert to html.