Skip to content

Commit

Permalink
[8.1][CDE] ApiParaPr.ToJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
askonev committed Jun 14, 2024
1 parent b0936b1 commit 6a9f574
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions js/docx/smoke/api_para_pr/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oMyStyle = oDocument.CreateStyle("My document style");
var oParaPr = oMyStyle.GetParaPr();
oParaPr.SetLeftBorder("single", 24, 0, 0, 255, 0);
var json = oParaPr.ToJSON(true);
var oParaPrFromJSON = Api.FromJSON(json);
var sType = oParaPrFromJSON.GetClassType();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText(sType);
oParagraph = Api.CreateParagraph();
oParagraph.AddText(json);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
8 changes: 8 additions & 0 deletions spec/docx/smoke/api_paragraph_properties_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,12 @@
docx = builder.build_and_parse('js/docx/smoke/api_para_pr/set_widow_control.js')
expect(docx.elements[5].orphan_control).to be_truthy
end

it 'ApiParaPr | ToJSON method' do
docx = builder.build_and_parse('js/docx/smoke/api_para_pr/to_json.js')
json = JSON.parse(docx.elements[1].nonempty_runs.first.text)
expect(docx.elements[0].nonempty_runs[0].text).to eq(json['type'])
expect(json['pBdr']['left']['value']).to eq('single')
expect(json['pBdr']['left']['color']['g']).to eq(255)
end
end

0 comments on commit 6a9f574

Please sign in to comment.