Skip to content

Commit 1e271e9

Browse files
authored
Merge pull request #98 from Financial-Times/support-text-nodes
Support text nodes
2 parents e8b8d17 + 001cba8 commit 1e271e9

File tree

14 files changed

+27
-22
lines changed

14 files changed

+27
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type BodyBlock =
105105
| Tweet
106106
| Video
107107
| YoutubeVideo
108+
| Text
108109
```
109110
110111
`BodyBlock` nodes are the only things that are valid as the top level of a `Body`.

content-tree.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export declare namespace ContentTree {
2-
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo;
2+
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo | Text;
33
type LayoutWidth = "auto" | "in-line" | "inset-left" | "inset-right" | "full-bleed" | "full-grid" | "mid-grid" | "full-width";
44
type Phrasing = Text | Break | Strong | Emphasis | Strikethrough | Link;
55
interface Node {
@@ -274,7 +274,7 @@ export declare namespace ContentTree {
274274
attributes: CustomCodeComponentAttributes;
275275
}
276276
namespace full {
277-
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo;
277+
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo | Text;
278278
type LayoutWidth = "auto" | "in-line" | "inset-left" | "inset-right" | "full-bleed" | "full-grid" | "mid-grid" | "full-width";
279279
type Phrasing = Text | Break | Strong | Emphasis | Strikethrough | Link;
280280
interface Node {
@@ -550,7 +550,7 @@ export declare namespace ContentTree {
550550
}
551551
}
552552
namespace transit {
553-
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo;
553+
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo | Text;
554554
type LayoutWidth = "auto" | "in-line" | "inset-left" | "inset-right" | "full-bleed" | "full-grid" | "mid-grid" | "full-width";
555555
type Phrasing = Text | Break | Strong | Emphasis | Strikethrough | Link;
556556
interface Node {
@@ -811,7 +811,7 @@ export declare namespace ContentTree {
811811
}
812812
}
813813
namespace loose {
814-
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo;
814+
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo | Text;
815815
type LayoutWidth = "auto" | "in-line" | "inset-left" | "inset-right" | "full-bleed" | "full-grid" | "mid-grid" | "full-width";
816816
type Phrasing = Text | Break | Strong | Emphasis | Strikethrough | Link;
817817
interface Node {

libraries/from-bodyxml/index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,11 @@ export function fromXast(bodyxast, transformers = defaultTransformers) {
448448
})(bodyxast);
449449
}
450450

451-
/**
452-
* Turns e.g. </p> </body> into </p></body>, which a lot of our content has
453-
* This prevents random strat text nodes being created in bodyTree
454-
* @param {string} xml
455-
* @returns {string}
456-
*/
457-
function removeWhitespaceBeforeBodyTag(xml) {
458-
return xml.replace(/<\/p>\s+<\/body>/gi, '</p></body>');
459-
}
451+
460452

461453
/** @param {string} bodyxml */
462454
export function fromXML(bodyxml) {
463-
return fromXast(xastFromXml(removeWhitespaceBeforeBodyTag(bodyxml)));
455+
return fromXast(xastFromXml(bodyxml));
464456
}
465457

466458
export default fromXML;

libraries/to-string/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import assert from "node:assert"
33
import stringify from "@content-tree/to-string"
44
import fs from "fs/promises"
55

6-
let testBase = "../../tests/content-tree-to-string"
6+
let testBase = "../../tests/transit-tree-to-string"
77
let inputNames = await fs.readdir(`${testBase}/input/`)
88

99
for (let inputName of inputNames) {

schemas/body-tree.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
},
120120
{
121121
"$ref": "#/definitions/ContentTree.transit.YoutubeVideo"
122+
},
123+
{
124+
"$ref": "#/definitions/ContentTree.transit.Text"
122125
}
123126
]
124127
},

schemas/content-tree.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144
},
145145
{
146146
"$ref": "#/definitions/ContentTree.full.YoutubeVideo"
147+
},
148+
{
149+
"$ref": "#/definitions/ContentTree.full.Text"
147150
}
148151
]
149152
},

schemas/transit-tree.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144
},
145145
{
146146
"$ref": "#/definitions/ContentTree.transit.YoutubeVideo"
147+
},
148+
{
149+
"$ref": "#/definitions/ContentTree.transit.Text"
147150
}
148151
]
149152
},

tests/body-tree-to-string/output/kitchen-snippet-full.text

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/body-tree-to-string/output/kitchen-snippet.text

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/bodyxml-to-content-tree/input/simple-old-post.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
<pull-quote-text><p>Maecenas ac ipsum in elit aliquam consectetur. Proin felis metus, efficitur et nulla eu, interdum malesuada diam.</p></pull-quote-text><pull-quote-image><ft-content data-embedded="true" url="http://api-t.ft.com/content/77c8a5b5-c9e3-4df2-ad5f-3ef35fe1d9d4" type="http://www.ft.com/ontology/content/ImageSet"></ft-content></pull-quote-image><pull-quote-source>Pellentesque habitant, morbi tristique</pull-quote-source>
99
</pull-quote>
1010
<p>Donec id faucibus erat. Suspendisse tempor laoreet lorem, sit amet vehicula massa facilisis at. Nulla quis feugiat massa. Praesent viverra non lectus ut ullamcorper. Phasellus <ft-content url="http://api-t.ft.com/content/c71efed9-fe5a-488d-9f47-20c15d177153" type="http://www.ft.com/ontology/content/Article">porttitor neque</ft-content> at volutpat pulvinar.</p>
11-
<p>“Curabitur fermentum, dolor vel interdum varius, tellus justo dapibus velit, interdum sollicitudin dolor nibh varius velit.”</p>
11+
<p>“Curabitur fermentum, dolor vel interdum varius, tellus justo dapibus velit, interdum sollicitudin dolor nibh varius velit.”</p>
1212
</body>

0 commit comments

Comments
 (0)