Skip to content

Commit 1018e4d

Browse files
authored
Read sdt (#546)
* feat: Add StructuredDataTagJSON * spec: Add test * 0.0.276-rc25 * fix: changelog
1 parent f267114 commit 1018e4d

File tree

11 files changed

+3237
-544
lines changed

11 files changed

+3237
-544
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## docx-wasm@0.0.276-rc26 (14. Oct, 2022)
9+
10+
- Support text direction (#545)
11+
- read `<sdt>`
12+
813
## docx-rs@0.4.5 (14. Oct, 2022)
914

1015
- Support text direction (#545)
@@ -13,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1318

1419
- Support rotate in pic
1520

21+
## docx-wasm@0.0.276-rc25 (21. Sep, 2022)
22+
23+
- [BugFix] Fixed a bug, hyperlink is broken with special characters.
24+
1625
## docx-wasm@0.0.276-rc20 (9. Sep, 2022)
1726

1827
- Support `sectionProperty` in pPr.

docx-core/src/reader/document.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ impl FromXML for Document {
6060
doc = doc.default_section_property(e);
6161
continue;
6262
}
63+
XMLElement::StructuredDataTag => {
64+
if let Ok(tag) = StructuredDataTag::read(&mut parser, &attributes) {
65+
doc = doc.add_structured_data_tag(tag);
66+
}
67+
continue;
68+
}
6369
_ => {}
6470
}
6571
}

docx-core/src/reader/structured_data_tag.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ impl ElementReader for StructuredDataTag {
7272
}
7373
XMLElement::Run => {
7474
if let Ok(run) = Run::read(r, attrs) {
75-
sdt.children.push(StructuredDataTagChild::Run(Box::new(run)));
75+
sdt.children
76+
.push(StructuredDataTagChild::Run(Box::new(run)));
7677
}
7778
continue;
7879
}
@@ -81,7 +82,7 @@ impl ElementReader for StructuredDataTag {
8182
}
8283
Ok(XmlEvent::EndElement { name, .. }) => {
8384
let e = XMLElement::from_str(&name.local_name).unwrap();
84-
if e == XMLElement::Paragraph {
85+
if e == XMLElement::StructuredDataTag {
8586
return Ok(sdt);
8687
}
8788
}

docx-core/src/reader/xml_element.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pub enum XMLElement {
149149
FooterReference,
150150
TitlePg,
151151
EvenAndOddHeaders,
152+
StructuredDataTag,
152153
Unsupported,
153154
}
154155

@@ -372,6 +373,7 @@ impl FromStr for XMLElement {
372373
"footerReference" => Ok(XMLElement::FooterReference),
373374
"titlePg" => Ok(XMLElement::TitlePg),
374375
"evenAndOddHeaders" => Ok(XMLElement::EvenAndOddHeaders),
376+
"sdt" => Ok(XMLElement::StructuredDataTag),
375377
_ => Ok(XMLElement::Unsupported),
376378
}
377379
}

docx-wasm/js/json/document.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { ParagraphJSON, BookmarkStartJSON, BookmarkEndJSON } from "./paragraph";
22
import { TableJSON } from "./table";
33
import { SectionPropertyJSON } from "./section-property";
44
import { CommentRangeStartJSON, CommentRangeEndJSON } from "..";
5+
import { StructuredTagJSON } from "./structured-data-tag";
56

67
export type DocumentChildJSON =
78
| ParagraphJSON
89
| TableJSON
910
| CommentRangeStartJSON
1011
| CommentRangeEndJSON
1112
| BookmarkStartJSON
12-
| BookmarkEndJSON;
13+
| BookmarkEndJSON
14+
| StructuredTagJSON;
1315

1416
export type DocumentJSON = {
1517
children: DocumentChildJSON[];
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {
2+
BookmarkEndJSON,
3+
BookmarkStartJSON,
4+
CommentRangeEndJSON,
5+
CommentRangeStartJSON,
6+
ParagraphJSON,
7+
TableJSON,
8+
} from "..";
9+
10+
export type StructuredTagJSON = {
11+
type: "structuredDataTag";
12+
data: {
13+
children: StructuredDataTagChildJSON[];
14+
};
15+
};
16+
17+
export type StructuredDataTagChildJSON =
18+
| ParagraphJSON
19+
| TableJSON
20+
| CommentRangeStartJSON
21+
| CommentRangeEndJSON
22+
| BookmarkStartJSON
23+
| BookmarkEndJSON;

docx-wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docx-wasm",
3-
"version": "0.0.276-rc24",
3+
"version": "0.0.276-rc26",
44
"main": "dist/node/index.js",
55
"browser": "dist/web/index.js",
66
"author": "bokuweb <bokuweb12@gmail.com>",

0 commit comments

Comments
 (0)