--- /dev/null
+import argparse
+import re
+import lxml.html as html
+import markdown
+
+class Section:
+ def __init__(self, name: str):
+ self._name = name
+ self._buffer = []
+ self._html = None
+
+ def append(self, line: str):
+ self._buffer.append(line)
+
+ @property
+ def buffer(self) -> str:
+ if not self._html:
+ buf = "\n".join(self._buffer)
+ self._html = markdown.markdown(buf)
+
+ return self._html
+
+ @property
+ def name(self) -> str:
+ return self._name
+
+class Document:
+ def __init__(self):
+ self._props = {}
+ self._items = {}
+
+ @property
+ def property(self) -> dict:
+ return self._props
+
+ def __getitem__(self, key: str) -> dict:
+ return self._items[key]
+
+ def __setitem__(self, key: str, value: str):
+ self._items[key] = value
+
+ def __str__(self) -> str:
+ d = dict({'property': self._props}, **self._items)
+ return str(d)
+
+class Parser:
+ def __init__(self, clazz, rules = {}):
+ self._item_class = clazz
+ self._doc = Document()
+ self._item = None
+ self.rules = {
+ re.compile(v): getattr(self, k) for k, v in rules.items()
+ }
+
+ def parse(self, lines):
+ for line in lines:
+ self._parse_line(line)
+ self.flash()
+
+ return self._doc
+
+ def flash(self):
+ if self._item:
+ self._doc[self._item.name] = self._item.buffer
+
+ def on_property(self, buf: tuple):
+ key, value = buf
+ self._doc.property[key] = value
+
+ def on_section_title(self, value: tuple):
+ title = value[0]
+ self.flash()
+ self._item = self._item_class(title)
+
+ def on_content(self, value: tuple):
+ content = value[0]
+ if self._item:
+ self._item.append(content)
+
+ def _parse_line(self, line: str):
+ def apply(k: str, v: str):
+ m = k.fullmatch(line)
+ return v(m.groups()) if m else None
+
+ for k, v in self.rules.items():
+ apply(k, v)
+
+rules = {
+ 'on_section_title': r'%\s*(.+?)\s*%*\n?',
+ 'on_property': r'=\((.+?)\)\s*(.+?)\s*=*\n?',
+ 'on_content': r'([^%=].*)\n?',
+}
+
+def convert_sections(lines: list):
+ p = Parser(Section).parse(lines)
+ sections = p.buffer
+ return sections
+
+def parse_args():
+ ps = argparse.ArgumentParser()
+ ps.add_argument("source")
+ ps.add_argument("-o", dest="out_path", default="out.html")
+ ps.add_argument("-t", dest="template_path", default="template.html")
+
+ return ps.parse_args()
+
+if __name__ == "__main__":
+ args = parse_args()
+ print(args.source)
+ print(args.out_path)
+ print(args.template_path)
+
+ with open(args.source) as f:
+ lines = f.readlines()
+ doc = Parser(Section, rules).parse(lines)
+
+ print(doc)
+
+ temp = html.parse(args.template_path)
+ temp.getroot().attrib['lang'] = doc.property['lang']
+ temp.xpath('//title')[0].text = doc.property['title']
+ img = temp.xpath('//div[contains(@class, "logo")]/img')[0]
+ img.attrib['src'] = f"/img/logo-{doc.property['lang']}"
+ img.attrib['alt'] = doc.property['title']
+
+ for sec in temp.xpath('//section'):
+ id = sec.attrib['id']
+ fg = html.fromstring(doc[id])
+ sec.append(fg)
+
+ with open(args.out_path, 'w') as f:
+ f.write(html.tostring(temp, encoding='utf-8').decode())
background-color: #fff;
margin: 0;
}
-header .container { width: 100%; }
-header .container div#navbar {
+nav .container { width: 100%; }
+nav .container div#navbar {
width: 680px;
height: 66px;
margin: 0 auto;
background-color: #fff;
}
-header .container div#navbar div { float: left; }
-header .container div#navbar div.logo {
+nav .container div#navbar div { float: left; }
+nav .container div#navbar div.logo {
padding-top: 7px;
}
-header .container div#navbar div#lang {
+nav .container div#navbar div#lang {
float: right;
}
-header .container div#navbar div#lang div.container {
+nav .container div#navbar div#lang div.container {
position: absolute;
top: 66px;
width: 110px;
display: none;
box-shadow: 1px 2px 2px #000;
}
-header .container div#navbar div#lang div.item {
+nav .container div#navbar div#lang div.item {
padding: 26px 1em 0 1em;
width: 80px;
height: 40px;
background-color: #fff;
font-size: 90%;
}
-header .container div#navbar div#lang div.item:hover {
+nav .container div#navbar div#lang div.item:hover {
background-color: #c8c8c8;
}
-header .container div#navbar div#lang div#current-lang {
+nav .container div#navbar div#lang div#current-lang {
text-align: center;
}
-div#docs-header {
+header {
background-color: #084;
width: 100%;
height: 300px;
}
-div#docs-header .container {
+header .container {
width: 680px;
height: 300px;
margin: 0 auto;
background-color: #0a4;
}
-div#docs-header .container .buttons-container {
+header .container .buttons-container {
position: absolute;
}
-div#docs-header .container .buttons-container .inner-container {
+header .container .buttons-container .inner-container {
position: relative;
left: 600px;
top: 15px;
}
-div#docs-header .container .buttons-container .button {
+header .container .buttons-container .button {
padding: .25em .55em;
background-color: #fff;
border-radius: 0.55em;
margin: 1px 2px;
cursor: pointer;
}
-div#docs-header .container .buttons-container .pressed {
+header .container .buttons-container .pressed {
background-color: #c8c8c8;
}
-div#docs .container {
+article .container {
width: 650px;
margin: 0 auto;
padding: 10px 15px;
background-color: #fff;
font-size: 90%;
}
-article h2 {
+section h2 {
color: #094;
padding-top: 1em;
font-size: 125%;
--- /dev/null
+=(title) Sawarabi Fonts =
+=(language) English =
+=(lang) en =
+
+% about
+## About Sawarabi Fonts
+
+Sawarabi Fonts are Japanese font families which are make up of two fonts,
+gothic and mincho. Sawarabi Gothic is a ‘Japanese gothic’ font, which is
+similar to sans-serif. Sawarabi Mincho is a ‘mincho’ font. ‘Mincho’ means a
+Ming typeface and is used like a serif font in Japan.
+
+Sawarabi Gothic and Mincho are normal ordinary fonts and have not notable
+features. But it can be said that their design concept might be a little
+traditional (or old fashioned), if compared with
+[VL Gothic](http://dicey.org/vlgothic/) (or [M+ FONTS](https://mplus-fonts.osdn.jp/))
+which have already been popular as free Japanese fonts.
+
+Though both of fonts are available, they have not yet enough characters for
+daily use, such as standard kanji, for being under developing now.
+
+% license
+## License
+
+The license of Sawarabi Fonts is Creative Commons Attribution 3.0. You can see
+the content of this license on the following site:
+
+- [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/)
+
+% samples
+## Samples
+
+Sawarabi Gothic (ver.20161015).
+
+<img src="/img/sample-gothic.png" alt="Sample (Gothic)" /><br />
+
+Sawarabi Mincho (ver.20140815).
+
+<img src="../img/sample-mincho.png" alt="Sample (Mincho)" /><br />
+
+% download
+## Download
+
+You can download the latest Sawarabi Fonts from the following links:
+
+<div id="download-box">
+<script charset="utf-8" type="text/javascript" src="https://osdn.net/projects/sawarabi-fonts/files/compact.js"></script>
+<noscript>
+<p style="border: 1px solid black">
+(The download links cannot be shown because your browser disable JavaScript.
+Please download them from <a href="https://osdn.net/projects/sawarabi-fonts/">Sawarabi Fonts Project site</a>.)</p>
+</noscript>
+</div>
+
+% links
+## Links
+
+<dl>
+<dt><a href="https://osdn.net/projects/sawarabi-fonts/">Sawarabi Fonts Project Top Page</a></dt>
+<dd>
+The project site in OSDN. In wiki pages of it, you can get a little more
+information, but these might be written in Japanese.
+</dd>
+</dl>
--- /dev/null
+=(title) さわらびフォント =
+=(language) 日本語 =
+=(lang) ja =
+
+% about
+## 概要
+
+ さわらびフォントは、フリーなライセンスで提供している日本語フォントです。
+現在、ゴシック体のさわらびゴシックと明朝体のさわらび明朝の 2 種類のフォントを
+公開しています。
+
+ なお、公開しているとはいえ、現在のところどちらのフォントも開発中という段階
+です。残念ながら、現状では通常用途に必要な漢字なども十分には揃っていません
+(ない文字は、ご利用の OS によっては自動補完が働き、別フォントで表示されるか
+と思います)。ご利用の際はあらかじめご了承ください。
+
+% license
+## ライセンス
+
+ さわらびフォントのライセンスは、Creative Commons Attribution 3.0 です。
+このライセンスの内容は、以下のリンクからご覧いただけます。
+
+- [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/deed.ja)
+
+% samples
+## 書体見本
+
+ さわらびゴシック(ver.20161015)の書体見本です。
+
+<img src="/img/sample-gothic.png" alt="書体見本(ゴシック)" /><br />
+
+ さわらび明朝(ver.20140815)の書体見本です。
+
+<img src="/img/sample-mincho.png" alt="書体見本(明朝)" /><br />
+
+% download
+## ダウンロード
+
+ 下のリンクから各フォントをダウンロードすることができます。なお、さわらび
+ゴシックが sawarabi-gothic、さわらび明朝が sawarabi-mincho に対応しています。
+
+<div id="download-box">
+<script charset="utf-8" type="text/javascript" src="https://osdn.net/projects/sawarabi-fonts/files/compact.js"></script>
+<noscript>
+<p style="border: 1px solid black"> (JavaScript が有効になっていない場合は、
+ここにリンクは現れません。
+ダウンロードは <a href="https://osdn.net/projects/sawarabi-fonts/">OSDN
+のプロジェクトページ</a>から行ってください。)</p>
+</noscript>
+</div>
+
+% links
+## Links
+
+<dl>
+<dt><a href="https://osdn.net/projects/sawarabi-fonts/">さわらびフォントの
+プロジェクトページ</a></dt>
+<dd>
+OSDN 内に設置させていただいているプロジェクトページです。こちらの Wiki 文書など
+に、さわらびフォントに関する、その他の情報が若干掲載されています。また、
+フォーラムもございますので、何かございましたらお寄せください。
+</dd>
+</dl>
--- /dev/null
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <title></title>
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
+ <script src="js/mobile.js" type="text/javascript"></script>
+ <script src="js/jquery-2.1.0.min.js" type="text/javascript"></script>
+ <script src="js/lang.js" type="text/javascript"></script>
+ <script src="js/doc-header/ja.js" type="text/javascript"></script>
+ <script src="js/doc-header.js" type="text/javascript"></script>
+ </head>
+ <body>
+ <nav>
+ <div class="container">
+ <div id="navbar">
+ <div class="logo"><img src="img/logo-en.png" alt="Sawarabi Fonts" /></div>
+ <div id="lang">
+ <div id="current-lang" class="item" title="Select your language">English</div>
+ <div id="lang-menu-container" class="container">
+ </div>
+ </div>
+ </div>
+ <div style="clear: both;"></div>
+ </div>
+ </nav>
+
+ <header>
+ <div class="container">
+ <div class="buttons-container"><div class="inner-container"></div></div>
+ <canvas id="header-canvas" width="680" height="300"></canvas>
+ </div>
+ </header>
+
+ <article id="docs">
+ <div class="container">
+
+ <section id="about">
+ </section>
+
+ <section id="license">
+ </section>
+
+ <section id="samples">
+ </section>
+
+ <section id="download">
+ </section>
+
+ <section id="links">
+ </section>
+ </div>
+ </article>
+
+ <footer>
+ <div class="container">
+ <a href="https://osdn.net/"><img src="//osdn.net/sflogo.php?group_id=3896&type=1" width="96" height="31" alt="OSDN" /></a>
+ </div>
+ </footer>
+ </body>
+</html>