-
Notifications
You must be signed in to change notification settings - Fork 3
/
articleGroup.tsx
197 lines (159 loc) · 7.04 KB
/
articleGroup.tsx
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import React from "react";
import * as std from "../../law/std";
import { assertNever } from "../../util";
import { HTMLComponentProps, wrapHTMLComponent, HTMLMarginSpan, elProps } from "../common/html";
import { DOCXSentenceChildrenRun, HTMLSentenceChildrenRun } from "./sentenceChildrenRun";
import { DOCXComponentProps, w, wrapDOCXComponent, DOCXMargin } from "../common/docx";
import { DOCXParagraphItem, HTMLParagraphItem } from "./paragraphItem";
import { DOCXArticle, HTMLArticle } from "./article";
import { DOCXAppdxItem, HTMLAppdxItem } from "./appdxItem";
import EmptyParagraph from "../common/docx/EmptyParagraph";
import { withKey } from "../common";
export interface ArticleGroupProps {
el: std.ArticleGroup | std.MainProvision | std.SupplProvision,
indent: number,
}
export const HTMLArticleGroupCSS = /*css*/`
.main-provision {
clear: both;
}
.article-group {
clear: both;
}
.article-group-title {
clear: both;
font-weight: bold;
}
.suppl-provision {
clear: both;
}
.suppl-provision-label {
clear: both;
font-weight: bold;
}
`;
export const HTMLArticleGroup = wrapHTMLComponent("HTMLArticleGroup", ((props: HTMLComponentProps & ArticleGroupProps) => {
const { el, htmlOptions, indent } = props;
const blocks: JSX.Element[] = [];
const ArticleGroupTitle = (el.children as (typeof el.children)[number][]).find(std.isArticleGroupTitle);
const SupplProvisionLabel = (el.children as (typeof el.children)[number][]).find(std.isSupplProvisionLabel);
if (ArticleGroupTitle) {
const titleIndent = std.articleGroupTitleTags.indexOf(ArticleGroupTitle.tag) + 2;
if (blocks.length > 0) blocks.push(<div className="empty"><br/></div>);
blocks.push((
<div className={`article-group-title indent-${indent + titleIndent}`} {...elProps(ArticleGroupTitle, htmlOptions)}>
<HTMLSentenceChildrenRun els={ArticleGroupTitle.children} {...{ htmlOptions }} />
</div>
));
}
if (SupplProvisionLabel && std.isSupplProvision(el)) {
const Extract = el.attr.Extract === "true" ? <><HTMLMarginSpan/>抄</> : "";
const AmendLawNum = el.attr.AmendLawNum ? `(${el.attr.AmendLawNum})` : "";
if (blocks.length > 0) blocks.push(<div className="empty"><br/></div>);
blocks.push((
<div className={`suppl-provision-label indent-${indent + 3}`} {...elProps(SupplProvisionLabel, htmlOptions)}>
<HTMLSentenceChildrenRun els={SupplProvisionLabel.children} {...{ htmlOptions }} />{AmendLawNum}
{Extract}
</div>
));
}
const bodyBlocks: JSX.Element[] = [];
for (const child of el.children) {
if (
std.isArticleGroupTitle(child)
|| std.isSupplProvisionLabel(child)
) {
continue;
} else if (std.isArticle(child)) {
if (bodyBlocks.length > 0) bodyBlocks.push(<div className="empty"><br/></div>);
bodyBlocks.push(<HTMLArticle el={child} indent={indent} {...{ htmlOptions }} />);
} else if (std.isParagraph(child)) {
if (bodyBlocks.length > 0) bodyBlocks.push(<div className="empty"><br/></div>);
bodyBlocks.push(<HTMLParagraphItem el={child} indent={indent} {...{ htmlOptions }} />);
} else if (std.isArticleGroup(child)) {
if (bodyBlocks.length > 0) bodyBlocks.push(<div className="empty"><br/></div>);
bodyBlocks.push(<HTMLArticleGroup el={child} indent={indent} {...{ htmlOptions }} />);
} else if (std.isSupplProvisionAppdxItem(child)) {
if (bodyBlocks.length > 0) bodyBlocks.push(<div className="empty"><br/></div>);
bodyBlocks.push(<HTMLAppdxItem el={child} indent={indent} {...{ htmlOptions }} />);
}
else { assertNever(child); }
}
const classNameBase = (
std.isMainProvision(el)
? "main-provision"
: std.isSupplProvision(el)
? "suppl-provision"
: "article-group"
);
if (bodyBlocks.length > 0) {
if (blocks.length > 0) blocks.push(<div className="empty"><br/></div>);
blocks.push((
<div className={`${classNameBase}-body`}>
{withKey(bodyBlocks)}
</div>
));
}
return (
<div className={classNameBase} {...elProps(el, htmlOptions)}>
{withKey(blocks)}
</div>
);
}));
export const DOCXArticleGroup = wrapDOCXComponent("DOCXArticleGroup", ((props: DOCXComponentProps & ArticleGroupProps) => {
const { el, docxOptions, indent } = props;
const blocks: JSX.Element[] = [];
const ArticleGroupTitle = (el.children as (typeof el.children)[number][]).find(std.isArticleGroupTitle);
const SupplProvisionLabel = (el.children as (typeof el.children)[number][]).find(std.isSupplProvisionLabel);
if (ArticleGroupTitle) {
const titleIndent = std.articleGroupTitleTags.indexOf(ArticleGroupTitle.tag) + 2;
if (blocks.length > 0) blocks.push(<EmptyParagraph/>);
blocks.push((
<w.p>
<w.pPr>
<w.pStyle w:val={`IndentHanging${indent + titleIndent}`}/>
</w.pPr>
<DOCXSentenceChildrenRun els={ArticleGroupTitle.children} emphasis={true} {...{ docxOptions }} />
</w.p>
));
}
if (SupplProvisionLabel && std.isSupplProvision(el)) {
const Extract = el.attr.Extract === "true" ? <>${DOCXMargin}抄</> : "";
const AmendLawNum = el.attr.AmendLawNum ? `(${el.attr.AmendLawNum})` : "";
if (blocks.length > 0) blocks.push(<EmptyParagraph/>);
blocks.push((
<w.p>
<w.pPr>
<w.pStyle w:val={`IndentHanging${indent + 3}`}/>
</w.pPr>
<DOCXSentenceChildrenRun els={SupplProvisionLabel.children} emphasis={true} {...{ docxOptions }} />
{AmendLawNum}
{Extract}
</w.p>
));
}
for (const child of el.children) {
if (
std.isArticleGroupTitle(child)
|| std.isSupplProvisionLabel(child)
) {
continue;
} else if (std.isArticle(child)) {
if (blocks.length > 0) blocks.push(<EmptyParagraph/>);
blocks.push(<DOCXArticle el={child} indent={indent} {...{ docxOptions }} />);
} else if (std.isParagraph(child)) {
if (blocks.length > 0) blocks.push(<EmptyParagraph/>);
blocks.push(<DOCXParagraphItem el={child} indent={indent} {...{ docxOptions }} />);
} else if (std.isArticleGroup(child)) {
if (blocks.length > 0) blocks.push(<EmptyParagraph/>);
blocks.push(<DOCXArticleGroup el={child} indent={indent} {...{ docxOptions }} />);
} else if (std.isSupplProvisionAppdxItem(child)) {
if (blocks.length > 0) blocks.push(<EmptyParagraph/>);
blocks.push(<DOCXAppdxItem el={child} indent={indent} {...{ docxOptions }} />);
}
else { assertNever(child); }
}
return (<>
{withKey(blocks)}
</>);
}));