Skip to content

Commit eb13410

Browse files
committed
一番上のsecの見出しをh2に変換して目次に対応
1 parent 6eeceb2 commit eb13410

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

jats2html/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>Article Theme HTML to JATS Converter</title>
6+
<title>JATS to HTML Converter</title>
77
<link rel="stylesheet" href="./index.css" type="text/css" />
88
<script type="module" src="./j2h.js"></script>
99
</head>

jats2html/lib/convert.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@
33
*** */
44

55
export const Convert = (document) => {
6-
// jatsTitle(document);
6+
articleTitle2Title(document);
77
wrapLabelTitle(document);
8+
title2h(document);
89
img(document);
910
// jatsBody(document);
1011
}
1112

12-
const jatsTitle = (document) => {
13-
document.querySelectorAll('title').forEach((title) => {
14-
// console.log(title);
15-
const jatsTitle = document.createElement('jats-title');
16-
title.after(jatsTitle);
17-
jatsTitle.append(...title.childNodes);
13+
const articleTitle2Title = (document) => {
14+
const articleTitle = document.querySelector('article-title');
15+
if (articleTitle) {
16+
const title = document.createElement('title');
17+
title.textContent = articleTitle.textContent;
18+
document.head.append(title);
19+
}
20+
}
21+
22+
const title2h = (document) => {
23+
document.querySelectorAll('jats-body > sec > jats-title-wrap').forEach((title) => {
24+
const h2 = document.createElement('h2');
25+
title.after(h2);
26+
h2.append(...title.childNodes);
1827
for (const attr of title.attributes) {
19-
jatsTitle.setAttribute(attr.name, attr.value);
28+
h2.setAttribute(attr.name, attr.value);
2029
}
2130
title.remove();
2231
});

0 commit comments

Comments
 (0)