Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type BodyBlock =
| Tweet
| Video
| YoutubeVideo
| Text
```

`BodyBlock` nodes are the only things that are valid as the top level of a `Body`.
Expand Down
8 changes: 4 additions & 4 deletions content-tree.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export declare namespace ContentTree {
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo;
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo | Text;
type LayoutWidth = "auto" | "in-line" | "inset-left" | "inset-right" | "full-bleed" | "full-grid" | "mid-grid" | "full-width";
type Phrasing = Text | Break | Strong | Emphasis | Strikethrough | Link;
interface Node {
Expand Down Expand Up @@ -272,7 +272,7 @@ export declare namespace ContentTree {
attributes: CustomCodeComponentAttributes;
}
namespace full {
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo;
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo | Text;
type LayoutWidth = "auto" | "in-line" | "inset-left" | "inset-right" | "full-bleed" | "full-grid" | "mid-grid" | "full-width";
type Phrasing = Text | Break | Strong | Emphasis | Strikethrough | Link;
interface Node {
Expand Down Expand Up @@ -546,7 +546,7 @@ export declare namespace ContentTree {
}
}
namespace transit {
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo;
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo | Text;
type LayoutWidth = "auto" | "in-line" | "inset-left" | "inset-right" | "full-bleed" | "full-grid" | "mid-grid" | "full-width";
type Phrasing = Text | Break | Strong | Emphasis | Strikethrough | Link;
interface Node {
Expand Down Expand Up @@ -805,7 +805,7 @@ export declare namespace ContentTree {
}
}
namespace loose {
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo;
type BodyBlock = Paragraph | Heading | ImageSet | Flourish | BigNumber | CustomCodeComponent | Layout | List | Blockquote | Pullquote | ScrollyBlock | ThematicBreak | Table | Recommended | Tweet | Video | YoutubeVideo | Text;
type LayoutWidth = "auto" | "in-line" | "inset-left" | "inset-right" | "full-bleed" | "full-grid" | "mid-grid" | "full-width";
type Phrasing = Text | Break | Strong | Emphasis | Strikethrough | Link;
interface Node {
Expand Down
12 changes: 2 additions & 10 deletions libraries/from-bodyxml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,11 @@ export function fromXast(bodyxast, transformers = defaultTransformers) {
})(bodyxast);
}

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


/** @param {string} bodyxml */
export function fromXML(bodyxml) {
return fromXast(xastFromXml(removeWhitespaceBeforeBodyTag(bodyxml)));
return fromXast(xastFromXml(bodyxml));
}

export default fromXML;
2 changes: 1 addition & 1 deletion libraries/to-string/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import assert from "node:assert"
import stringify from "@content-tree/to-string"
import fs from "fs/promises"

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

for (let inputName of inputNames) {
Expand Down
3 changes: 3 additions & 0 deletions schemas/body-tree.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
},
{
"$ref": "#/definitions/ContentTree.transit.YoutubeVideo"
},
{
"$ref": "#/definitions/ContentTree.transit.Text"
}
]
},
Expand Down
3 changes: 3 additions & 0 deletions schemas/content-tree.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
},
{
"$ref": "#/definitions/ContentTree.full.YoutubeVideo"
},
{
"$ref": "#/definitions/ContentTree.full.Text"
}
]
},
Expand Down
3 changes: 3 additions & 0 deletions schemas/transit-tree.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
},
{
"$ref": "#/definitions/ContentTree.transit.YoutubeVideo"
},
{
"$ref": "#/definitions/ContentTree.transit.Text"
}
]
},
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/body-tree-to-string/output/kitchen-snippet.text

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/bodyxml-to-content-tree/input/simple-old-post.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<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>
</pull-quote>
<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>
<p>“Curabitur fermentum, dolor vel interdum varius, tellus justo dapibus velit, interdum sollicitudin dolor nibh varius velit.”</p>
<p>“Curabitur fermentum, dolor vel interdum varius, tellus justo dapibus velit, interdum sollicitudin dolor nibh varius velit.”</p>
</body>
3 changes: 1 addition & 2 deletions tests/bodyxml-to-content-tree/output/kitchen-snippet.json
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,7 @@
},
{
"type": "video",
"id": "http://api-t.ft.com/content/9eef331b-04f0-4774-b487-a5aef2995e4d",
"embedded": true
"id": "http://api-t.ft.com/content/9eef331b-04f0-4774-b487-a5aef2995e4d"
},
{
"type": "paragraph",
Expand Down
4 changes: 4 additions & 0 deletions tests/schema/body-tree/valid/kitchen-snippet.json
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,10 @@
"value": "If this sounds all-too-familiar, stick with me. I have a proven treatment for Kitchen Sink Syndrome."
}
]
},
{
"type": "text",
"value": "",
}
]
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/transit-tree-to-string/output/kitchen-snippet.text

Large diffs are not rendered by default.

Loading