{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# RBPU16 Data Sheet", "\n\nRun All -> self-contained HTML." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sys,os,re,base64,mimetypes,subprocess\n", "from datetime import datetime as dt; from pathlib import Path; from html import escape as eh\n", "try: import markdown\n", "except: subprocess.check_call([sys.executable,'-m','pip','install','markdown','-q']); import markdown\n", "B=Path(os.getcwd()).resolve(); os.chdir(str(B)); sys.path.insert(0,str(B))\n", "from doc_builder import import_handler, image_extension, codeblock_extension\n", "print(f' {B.name}')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Build" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def pc(md_text):\n", " md_text = import_handler.process_imports(md_text,B,pc)\n", " md_text = codeblock_extension.render_code_blocks(md_text,B)\n", " return markdown.markdown(md_text,extensions=[\n", " 'tables','fenced_code','codehilite','nl2br','sane_lists',\n", " image_extension.ImageRowProcessor(),\n", " ],extension_configs={'codehilite':{'css_class':'highlight','guess_lang':False}})\n", "\n", "cn=[]\n", "with open(B/'project.yaml',encoding='utf-8') as f:\n", " ic=False\n", " for line in f:\n", " line=line.rstrip()\n", " if line.startswith('chapters:'): ic=True; continue\n", " if ic:\n", " mx=re.match(r'^\\s*-\\s+(.+)$',line)\n", " if mx: cn.append(mx.group(1).strip())\n", " elif line and not line.startswith(' '): ic=False\n", "\n", "print('Processing...')\n", "chapters=[]\n", "for i,n in enumerate(cn):\n", " fp=B/'chapters'/n\n", " if not fp.exists(): continue\n", " print(f' [{i+1}] {n}')\n", " c=pc(fp.read_text(encoding='utf-8'))\n", " mx=re.search(r']*>(.*?)',c)\n", " chapters.append(dict(id=f'ch{i+1}',number=str(i+1),title=mx.group(1) if mx else fp.stem,content=c))\n", "apd=B/'chapters'/'appendix'\n", "if apd.exists():\n", " for j,fp in enumerate(sorted(apd.glob('*.md'),key=lambda p:p.name)):\n", " lb=chr(65+j)\n", " c=pc(fp.read_text(encoding='utf-8'))\n", " mx=re.search(r']*>(.*?)',c)\n", " chapters.append(dict(id=f'app{lb}',number=f'Appendix {lb}',title=mx.group(1) if mx else fp.stem,content=c))\n", "\n", "CSS=(B/'doc_builder'/'themes'/'datasheet.css').read_text(encoding='utf-8')\n", "TITLE='RBPU16'; AU='Guo Cheng'; DATE=dt.now().strftime('%Y-%m-%d')\n", "COVER=''.join([\n", " '
',\n", " '
READOUT BASEBAND PROCESSOR
',\n", " '

RBPU16
',chr(35835),chr(20986),chr(22522),chr(24102),chr(22788),chr(29702),chr(33455),chr(29255),'

',\n", " '
Data Sheet · User Manual
',\n", " f'

Rev 1.0 · {DATE}

{AU}

',\n", " '
',\n", "])\n", "ch_html=chr(10).join(f'
{c[\"content\"]}
' for c in chapters)\n", "FULL=chr(10).join([\n", " '','','',\n", " '','',\n", " f'{TITLE} Data Sheet',f'',\n", " '','','',\n", " COVER,ch_html,\n", " '
','

Revision History

',\n", " '',\n", " '',\n", " f'','
RevDateChangesAuthor
1.0{DATE}Initial{AU}
',\n", " '','',\n", "])\n", "SR=re.compile(r'src=\"(assets/[^\"]+)\"'); mimetypes.init()\n", "def em(m):\n", " r=m.group(1); ip=(B/r).resolve()\n", " if not ip.exists(): return m.group(0)\n", " mt,_=mimetypes.guess_type(str(ip))\n", " if not mt: mt='image/png'\n", " with open(ip,'rb') as f: b64=base64.b64encode(f.read()).decode()\n", " return f'src=\"data:{mt};base64,{b64}\"'\n", "FULL=SR.sub(em,FULL)\n", "out=B/'output'; out.mkdir(exist_ok=True)\n", "hp=out/f'{TITLE}_Data_Sheet.html'; hp.write_text(FULL,encoding='utf-8')\n", "print(f'\\n {hp.name} ({hp.stat().st_size/1024:.0f} KB) OK')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Done", "\n\nSelf-contained HTML in `output/`." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.9.0" } }, "nbformat": 4, "nbformat_minor": 4 }