diff --git a/js/docx/smoke/api_document_content/to_json.js b/js/docx/smoke/api_document_content/to_json.js index 5b7f36a88..2a9796630 100644 --- a/js/docx/smoke/api_document_content/to_json.js +++ b/js/docx/smoke/api_document_content/to_json.js @@ -6,8 +6,22 @@ builder.CreateFile("docx"); var oDrawing = Api.CreateShape("rect", 3212465, 963295, oFill, oStroke); oParagraph.AddDrawing(oDrawing); var oDocContent = oDrawing.GetDocContent(); +// Add Hyperlink oParagraph = oDocContent.GetElement(0); - oParagraph.AddText("Simple text"); + oParagraph.AddText('Hyperlink'); + var oRange = oParagraph.GetRange(0, 8); + oRange.AddHyperlink('https://api.onlyoffice.com') +// Add BlockLvlSdt + var oBlockLvlSdt = Api.CreateBlockLvlSdt(); + oBlockLvlSdt.AddText('oBlockLvlSdt'); + oDocContent.Push(oBlockLvlSdt); +// Add Table + var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table"); + oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered - Accent 5")); + var oTable = Api.CreateTable(3, 3); + oTable.SetWidth("percent", 100); + oTable.SetStyle(oTableStyle); + oDocContent.Push(oTable); var json = oDocContent.ToJSON(true, true); GlobalVariable["JSON"] = json; builder.CloseFile(); @@ -17,10 +31,12 @@ builder.CloseFile(); builder.CreateFile("docx"); var json = GlobalVariable["JSON"] var oDocContentFromJSON = Api.FromJSON(json); - Api.ReplaceDocumentContent(oDocContentFromJSON); var oDocument = Api.GetDocument(); + for( let el = 0; el < oDocContentFromJSON.GetElementsCount(); el++ ) { + oDocument.Push(oDocContentFromJSON.GetElement(el)) + } var oParagraph = Api.CreateParagraph(); oParagraph.AddText(json); oDocument.Push(oParagraph); -builder.SaveFile("docx", "ParagraphToJSON.docx"); +builder.SaveFile("docx", "DocContentToJSON.docx"); builder.CloseFile(); diff --git a/spec/docx/smoke/api_document_content_spec.rb b/spec/docx/smoke/api_document_content_spec.rb index 14c0505f6..e65303fe7 100644 --- a/spec/docx/smoke/api_document_content_spec.rb +++ b/spec/docx/smoke/api_document_content_spec.rb @@ -56,8 +56,13 @@ it 'ApiDocumentContent | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_document_content/to_json.js') - expect(docx.elements[0].nonempty_runs.first.text).to eq('Simple text') - json = JSON.parse(docx.elements[1].nonempty_runs.first.text) + expect(docx.elements[1].hyperlink.action.to_s).to eq('external_link') + # TODO: add block content control checking + expect(docx.elements[4].number).to eq(3) + json = JSON.parse(docx.elements[7].nonempty_runs.first.text) expect(json['type']).to eq('docContent') + expect(json['content'][0]['content'][2]['type']).to eq('hyperlink') + expect(json['content'][1]['type']).to eq('blockLvlSdt') + expect(json['content'][2]['type']).to eq('table') end end