Skip to content

Commit

Permalink
[8.1][CDE] BlockLvlSdt.ToJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
askonev committed Jun 11, 2024
1 parent 747e241 commit 0a7b30c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
38 changes: 38 additions & 0 deletions js/docx/smoke/api_block_lvl_sdt/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
CustomDefaultStyle(oDocument)
var oBlockLvlSdt = Api.CreateBlockLvlSdt();
oBlockLvlSdt.SetAlias("№1");
var oBlockContent = oBlockLvlSdt.GetContent()
oBlockContent.GetElement(0).AddText("blockLvlSdt");
var oNumbering = oDocument.CreateNumbering("bullet");
for (let nLvl = 0; nLvl < 8; ++nLvl) {
var oNumLvl = oNumbering.GetLevel(nLvl);
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Default bullet lvl " + (nLvl + 1));
oParagraph.SetNumbering(oNumLvl);
oParagraph.SetContextualSpacing(true);
oBlockContent.Push(oParagraph);
}
var json = oBlockLvlSdt.ToJSON(true, true);
function CustomDefaultStyle(oDocument){
var oNormalStyle = oDocument.GetDefaultStyle("paragraph");
var oTextPr = oNormalStyle.GetTextPr();
oTextPr.SetColor(0x26, 0x26, 0x26, false);
oTextPr.SetFontFamily("Calibri Light");
oTextPr.SetFontSize(32);
}
GlobalVariable["JSON"] = json;
builder.CloseFile();

////////////////////////

builder.CreateFile("docx");
var json = GlobalVariable["JSON"];
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddText(json)
var oBlockSdtFromJSON = Api.FromJSON(json);
oDocument.AddElement(0, oBlockSdtFromJSON);
builder.SaveFile("docx", "ToJSON.docx");
builder.CloseFile();
14 changes: 14 additions & 0 deletions spec/docx/smoke/api_block_lvl_sdt_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'ApiBlockLvlSdt section tests' do
it 'ApiBlockLvlSdt | ToJSON method' do
docx = builder.build_and_parse('js/docx/smoke/api_block_lvl_sdt/to_json.js')
expect(docx.elements[0].sdt_content.elements[0].character_style_array[1].text).to eq('blockLvlSdt')
expect(docx.elements[0].sdt_content.elements[8].numbering.i_level.value).to eq(7)
json = JSON.parse(docx.elements[1].nonempty_runs.first.text)
expect(json['type']).to eq('blockLvlSdt')
expect(json['numbering']['type']).to eq('numbering')
end
end

0 comments on commit 0a7b30c

Please sign in to comment.