-
Notifications
You must be signed in to change notification settings - Fork 0
/
de_render.py
155 lines (123 loc) · 4.32 KB
/
de_render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# encoding: utf-8
import os
import sys
import unittest
import dobu
class TestRenderer(unittest.TestCase):
def setUp(self):
self._scb = """scb page sample
line
line1
line1
line2
やっぱり[趣味]は[プログラミング]に限りますな。`print(f"hello world! {array[i]=}");` とか `import os` みたいな[リテラル記法]はよく使いますよね
url系も使いましょう
[前にsta https://scrapbox.io/sta/]
[https://scrapbox.io/sta/ 後ろにsta]
[https://scrapbox.io/sta/ 後ろに スペース区切りで sta]
[前に スペース区切りで sta https://scrapbox.io/sta/]
[URLなしで スペース区切りの リンクは ただのページ内リンク]
引用忘れてましたね
>引用
>引用の中で`リテラル`や[link]
リテラル
`リテラル`
not-lite`lite`not-lite`lite``lite`not-lite
block
code:codeblock1
aaa
あいうえお
:c
line1
code:codeblock2.scb
not line1
not line2
not line3
:c
line2
code:rootcodeblock
not line1
:c"""
def tearDown(self):
pass
@staticmethod
def to_file(filename, lines):
return dobu.list2file(filename, lines)
def test_print_with_debugrenderer(self):
scb = self._scb
lines = scb.split('\n')
linepasser = dobu.LinePasser(lines)
pageparser = dobu.PageParser(linepasser)
page = pageparser.parse()
renderer = dobu.DebugRenderer(page)
lines = renderer.render()
self.to_file('debugout_debug.txt', lines)
def test_print_with_htmlrenderer(self):
scb = self._scb
lines = scb.split('\n')
linepasser = dobu.LinePasser(lines)
pageparser = dobu.PageParser(linepasser)
page = pageparser.parse()
page.name = 'scb page sample'
renderer = dobu.HTMLRenderer(page)
renderer.use_line_flattening()
lines = renderer.render()
self.to_file('debugout_html.html', lines)
class TestConverter(unittest.TestCase):
def setUp(self):
self.MYFULLPATH = os.path.abspath(sys.argv[0])
self.MYDIR = os.path.dirname(self.MYFULLPATH)
def tearDown(self):
pass
def xtest_onepass(self):
sourcedir = os.path.join(self.MYDIR, 'scb')
outputdir = os.path.join(self.MYDIR, 'html_debugout')
try:
os.mkdir(outputdir)
except FileExistsError:
pass
converter = dobu.Converter(output_directory=outputdir)
filepathes = converter.directory2filepathes(sourcedir)
print(f'sourcedir: {sourcedir}')
print(f'outputdir: {outputdir}')
print(f'the count of sourcefiles is: {len(filepathes)}')
testee_filepath = filepathes[0]
page = converter.filepath2page(testee_filepath)
converter.page2file(page)
def xtest_all_generate(self):
sourcedir = os.path.join(self.MYDIR, 'scb')
outputdir = os.path.join(self.MYDIR, 'html_debugout')
try:
os.mkdir(outputdir)
except FileExistsError:
pass
converter = dobu.Converter(output_directory=outputdir)
filepathes = converter.directory2filepathes(sourcedir)
print(f'sourcedir: {sourcedir}')
print(f'outputdir: {outputdir}')
print(f'the count of sourcefiles is: {len(filepathes)}')
for target_filepath in filepathes:
page = converter.filepath2page(target_filepath)
converter.page2file(page)
def test_all_generate_with_relationlinks(self):
sourcedir = os.path.join(self.MYDIR, 'scb')
outputdir = os.path.join(self.MYDIR, 'html_debugout')
try:
os.mkdir(outputdir)
except FileExistsError:
pass
converter = dobu.Converter(output_directory=outputdir)
filepathes = converter.directory2filepathes(sourcedir)
print(f'sourcedir: {sourcedir}')
print(f'outputdir: {outputdir}')
print(f'the count of sourcefiles is: {len(filepathes)}')
physical_pages = []
for target_filepath in filepathes:
page = converter.filepath2page(target_filepath)
physical_pages.append(page)
network = dobu.Network(physical_pages)
for pagename in network.page_dict:
page = network.page_dict[pagename]
converter.page2file(page)
if __name__ == '__main__':
unittest.main()