diff --git a/README.md b/README.md index c3a9eac..43c312b 100644 --- a/README.md +++ b/README.md @@ -245,6 +245,7 @@ interface Heading extends Parent { type: "heading" children: Text[] level: "chapter" | "subheading" | "label" + blockIdentifier?: string } ``` @@ -354,6 +355,7 @@ interface ImageSet extends Node { type: "image-set" id: string external picture: ImageSetPicture + blockIdentifier?: string } ``` @@ -512,6 +514,7 @@ interface Flourish extends Node { description?: string timestamp?: string external fallbackImage?: Image + blockIdentifier?: string } ``` diff --git a/content-tree.d.ts b/content-tree.d.ts index c6c6a3c..f300dd9 100644 --- a/content-tree.d.ts +++ b/content-tree.d.ts @@ -36,6 +36,7 @@ export declare namespace ContentTree { type: "heading"; children: Text[]; level: "chapter" | "subheading" | "label"; + blockIdentifier?: string; } interface Strong extends Parent { type: "strong"; @@ -77,6 +78,7 @@ export declare namespace ContentTree { type: "image-set"; id: string; picture: ImageSetPicture; + blockIdentifier?: string; } type ImageSetPicture = { layoutWidth: string; @@ -156,6 +158,7 @@ export declare namespace ContentTree { description?: string; timestamp?: string; fallbackImage?: Image; + blockIdentifier?: string; } interface BigNumber extends Node { type: "big-number"; @@ -309,6 +312,7 @@ export declare namespace ContentTree { type: "heading"; children: Text[]; level: "chapter" | "subheading" | "label"; + blockIdentifier?: string; } interface Strong extends Parent { type: "strong"; @@ -350,6 +354,7 @@ export declare namespace ContentTree { type: "image-set"; id: string; picture: ImageSetPicture; + blockIdentifier?: string; } type ImageSetPicture = { layoutWidth: string; @@ -429,6 +434,7 @@ export declare namespace ContentTree { description?: string; timestamp?: string; fallbackImage?: Image; + blockIdentifier?: string; } interface BigNumber extends Node { type: "big-number"; @@ -583,6 +589,7 @@ export declare namespace ContentTree { type: "heading"; children: Text[]; level: "chapter" | "subheading" | "label"; + blockIdentifier?: string; } interface Strong extends Parent { type: "strong"; @@ -623,6 +630,7 @@ export declare namespace ContentTree { interface ImageSet extends Node { type: "image-set"; id: string; + blockIdentifier?: string; } type ImageSetPicture = { layoutWidth: string; @@ -699,6 +707,7 @@ export declare namespace ContentTree { flourishType: string; description?: string; timestamp?: string; + blockIdentifier?: string; } interface BigNumber extends Node { type: "big-number"; @@ -842,6 +851,7 @@ export declare namespace ContentTree { type: "heading"; children: Text[]; level: "chapter" | "subheading" | "label"; + blockIdentifier?: string; } interface Strong extends Parent { type: "strong"; @@ -883,6 +893,7 @@ export declare namespace ContentTree { type: "image-set"; id: string; picture?: ImageSetPicture; + blockIdentifier?: string; } type ImageSetPicture = { layoutWidth: string; @@ -962,6 +973,7 @@ export declare namespace ContentTree { description?: string; timestamp?: string; fallbackImage?: Image; + blockIdentifier?: string; } interface BigNumber extends Node { type: "big-number"; diff --git a/content_tree.go b/content_tree.go index abd6b3d..f568158 100644 --- a/content_tree.go +++ b/content_tree.go @@ -103,7 +103,7 @@ type ColumnSettingsItems struct { type BigNumber struct { Type string `json:"type"` - Data interface{} `json:"data,omitempty"` + Data interface{} `json:"data,omitempty"` Description string `json:"description,omitempty"` Number string `json:"number,omitempty"` } @@ -586,14 +586,15 @@ func (n *Emphasis) GetChildren() []Node { } type Flourish struct { - Type string `json:"type"` - Data interface{} `json:"data,omitempty"` - Description string `json:"description,omitempty"` - FallbackImage *FlourishFallbackImage `json:"fallbackImage,omitempty"` - FlourishType string `json:"flourishType,omitempty"` - Id string `json:"id,omitempty"` - LayoutWidth string `json:"layoutWidth,omitempty"` - Timestamp string `json:"timestamp,omitempty"` + Type string `json:"type"` + Data interface{} `json:"data,omitempty"` + Description string `json:"description,omitempty"` + FallbackImage *FlourishFallbackImage `json:"fallbackImage,omitempty"` + FlourishType string `json:"flourishType,omitempty"` + Id string `json:"id,omitempty"` + LayoutWidth string `json:"layoutWidth,omitempty"` + Timestamp string `json:"timestamp,omitempty"` + BlockIdentifier string `json:"blockIdentifier,omitempty"` } func (n *Flourish) GetType() string { @@ -628,6 +629,7 @@ type Heading struct { Children []*Text `json:"children,omitempty"` Data interface{} `json:"data,omitempty"` Level string `json:"level,omitempty"` + BlockIdentifier string `json:"blockIdentifier,omitempty"` } func (n *Heading) GetType() string { @@ -647,10 +649,11 @@ func (n *Heading) GetChildren() []Node { } type ImageSet struct { - Type string `json:"type"` - Data interface{} `json:"data,omitempty"` - ID string `json:"id,omitempty"` - Picture *Picture `json:"picture,omitempty"` + Type string `json:"type"` + Data interface{} `json:"data,omitempty"` + ID string `json:"id,omitempty"` + Picture *Picture `json:"picture,omitempty"` + BlockIdentifier string `json:"blockIdentifier,omitempty"` } func (n *ImageSet) GetType() string { diff --git a/libraries/from-bodyxml/index.js b/libraries/from-bodyxml/index.js index 344ecc5..488f75e 100644 --- a/libraries/from-bodyxml/index.js +++ b/libraries/from-bodyxml/index.js @@ -56,36 +56,44 @@ export let defaultTransformers = { * @type {Transformer} */ h1(h1) { + const blockId = h1.attributes["data-fragment-id"] || h1.attributes["id"]; return { type: "heading", level: "chapter", + ...(blockId && { blockIdentifier: blockId }), }; }, /** * @type {Transformer} */ h2(h2) { + const blockId = h2.attributes["data-fragment-id"] || h2.attributes["id"]; return { type: "heading", level: "subheading", + ...(blockId && { blockIdentifier: blockId }), }; }, /** * @type {Transformer} */ h3(h3) { + const blockId = h3.attributes["data-fragment-id"] || h3.attributes["id"]; return { type: "heading", level: "subheading", + ...(blockId && { blockIdentifier: blockId }), }; }, /** * @type {Transformer} */ h4(h4) { + const blockId = h4.attributes["data-fragment-id"] || h4.attributes["id"]; return { type: "heading", level: "label", + ...(blockId && { blockIdentifier: blockId }), }; }, /** @@ -237,9 +245,11 @@ export let defaultTransformers = { * @type {Transformer} */ [ContentType.imageset](content) { + const blockId = content.attributes["data-fragment-id"] || content.attributes["id"]; return { type: "image-set", id: content.attributes.url ?? "", + ...(blockId && { blockIdentifier: blockId }), children: null, }; }, @@ -260,6 +270,7 @@ export let defaultTransformers = { [ContentType.content](content) { const id = content.attributes.url ?? ""; const uuid = id.split("/").pop(); + const blockId = content.attributes["data-fragment-id"] || content.attributes["id"]; if (content.attributes["data-asset-type"] == "flourish") { return /** @type {ContentTree.transit.Flourish} */ ({ @@ -271,6 +282,7 @@ export let defaultTransformers = { ), description: content.attributes["alt"] || "", timestamp: content.attributes["data-time-stamp"] || "", + ...(blockId && { blockIdentifier: blockId }), children: null, }); } diff --git a/schemas/body-tree.schema.json b/schemas/body-tree.schema.json index 5f2a150..0f6baad 100644 --- a/schemas/body-tree.schema.json +++ b/schemas/body-tree.schema.json @@ -185,6 +185,9 @@ "ContentTree.transit.Flourish": { "additionalProperties": false, "properties": { + "blockIdentifier": { + "type": "string" + }, "data": {}, "description": { "type": "string" @@ -217,6 +220,9 @@ "ContentTree.transit.Heading": { "additionalProperties": false, "properties": { + "blockIdentifier": { + "type": "string" + }, "children": { "items": { "$ref": "#/definitions/ContentTree.transit.Text" @@ -247,6 +253,9 @@ "ContentTree.transit.ImageSet": { "additionalProperties": false, "properties": { + "blockIdentifier": { + "type": "string" + }, "data": {}, "id": { "type": "string" diff --git a/schemas/content-tree.schema.json b/schemas/content-tree.schema.json index 4a1114a..a4df50d 100644 --- a/schemas/content-tree.schema.json +++ b/schemas/content-tree.schema.json @@ -236,6 +236,9 @@ "ContentTree.full.Flourish": { "additionalProperties": false, "properties": { + "blockIdentifier": { + "type": "string" + }, "data": {}, "description": { "type": "string" @@ -328,6 +331,9 @@ "ContentTree.full.Heading": { "additionalProperties": false, "properties": { + "blockIdentifier": { + "type": "string" + }, "children": { "items": { "$ref": "#/definitions/ContentTree.full.Text" @@ -358,6 +364,9 @@ "ContentTree.full.ImageSet": { "additionalProperties": false, "properties": { + "blockIdentifier": { + "type": "string" + }, "data": {}, "id": { "type": "string" diff --git a/schemas/transit-tree.schema.json b/schemas/transit-tree.schema.json index 9864746..aec260d 100644 --- a/schemas/transit-tree.schema.json +++ b/schemas/transit-tree.schema.json @@ -210,6 +210,9 @@ "ContentTree.transit.Flourish": { "additionalProperties": false, "properties": { + "blockIdentifier": { + "type": "string" + }, "data": {}, "description": { "type": "string" @@ -242,6 +245,9 @@ "ContentTree.transit.Heading": { "additionalProperties": false, "properties": { + "blockIdentifier": { + "type": "string" + }, "children": { "items": { "$ref": "#/definitions/ContentTree.transit.Text" @@ -272,6 +278,9 @@ "ContentTree.transit.ImageSet": { "additionalProperties": false, "properties": { + "blockIdentifier": { + "type": "string" + }, "data": {}, "id": { "type": "string"