Skip to content

Commit

Permalink
Fixed caption docx tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Toliak committed May 1, 2023
1 parent cca90a2 commit c38afdf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions printers/docx/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,17 @@ export async function createWordPicture(

export function createWordPictureLabel(
index: number,
text: string,
text: docx.XmlComponent[],
): PrinterFunctionResult {
return {
result: [
new Paragraph({
style: 'picture-caption',
children: [
new docx.TextRun({
text: `Рисунок ${index}${text}`,
text: `Рисунок ${index} – `,
}),
...text,
],
}),
],
Expand Down
11 changes: 8 additions & 3 deletions printers/docx/src/visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ export const processingVisitors: ProcessingVisitors = {

[NodeType.Code]: internalUnparsableNodeType,
[ProcessedNodeType.CodeProcessed]: async (printer, node) => {
const resultName = await printer.processNodeList(printer, node.name);

const resultCaption = createWordPictureLabel(
node.index + 1,
node.label.text,
resultName.result,
);

return {
Expand Down Expand Up @@ -167,7 +169,7 @@ export const processingVisitors: ProcessingVisitors = {
}),
...resultCaption.result,
],
diagnostic: [...resultCaption.diagnostic],
diagnostic: [...resultName.diagnostic, ...resultCaption.diagnostic],
};
},
[NodeType.Heading]: async (printer, node) => {
Expand Down Expand Up @@ -322,10 +324,12 @@ export const processingVisitors: ProcessingVisitors = {
[NodeType.Link]: internalTODO,
[NodeType.Image]: internalUnparsableNodeType,
[ProcessedNodeType.PictureProcessed]: async (printer, node) => {
const resultName = await printer.processNodeList(printer, node.name);

const resultPicture = await createWordPicture(node);
const resultCaption = createWordPictureLabel(
node.index + 1,
node.label.text,
resultName.result,
);

return {
Expand All @@ -338,6 +342,7 @@ export const processingVisitors: ProcessingVisitors = {
...resultCaption.result,
],
diagnostic: [
...resultName.diagnostic,
...resultPicture.diagnostic,
...resultCaption.diagnostic,
],
Expand Down

0 comments on commit c38afdf

Please sign in to comment.