Skip to content

Commit

Permalink
More styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Toliak committed Mar 21, 2023
1 parent 8698043 commit 658e82b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions printers/docx/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export function getWordTable(info: WordTableInfo): PrinterFunctionResult {
size: 100,
},
rows: [info.header, ...info.content],
alignment: AlignmentType.CENTER,
style: 'table',
}),
],
Expand Down
25 changes: 23 additions & 2 deletions printers/docx/src/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as docx from 'docx';
import { AlignmentType } from 'docx';
import { AlignmentType, BorderStyle } from 'docx';

function fontSizeToDocxFontSize(size: number): number {
return size * 2;
Expand Down Expand Up @@ -70,13 +70,33 @@ export function getDocumentGlobalStyles(): docx.IStylesOptions {
},
},
paragraphStyles: [
{
id: 'code',
name: 'code',
paragraph: {
spacing: {
before: docx.convertMillimetersToTwip(
defaultTableSpacingMm,
),
},
keepLines: true,
keepNext: true,
indent: {
firstLine: 0,
},
},
run: {
size: fontSizeToDocxFontSize(12),
font: 'Fira Code',
},
},
{
id: 'table-caption',
name: 'table-caption',
run: {},
paragraph: {
spacing: {
after: docx.convertMillimetersToTwip(
before: docx.convertMillimetersToTwip(
defaultPictureSpacingMm,
),
},
Expand All @@ -103,6 +123,7 @@ export function getDocumentGlobalStyles(): docx.IStylesOptions {
id: 'table-cell',
name: 'table-cell',
paragraph: {
alignment: AlignmentType.CENTER,
indent: {
firstLine: 0,
},
Expand Down
29 changes: 22 additions & 7 deletions printers/docx/src/visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import {
nodeToDiagnose,
} from '@md-to-latex/converter/dist/diagnostic';
import * as docx from 'docx';
import { AlignmentType, Paragraph, TextRun, UnderlineType } from 'docx';
import {
BorderStyle,
Paragraph,
TextRun,
UnderlineType,
VerticalAlign,
} from 'docx';
import {
createTextRunExt,
createWordPicture,
Expand All @@ -29,9 +35,6 @@ import {
printKeyNode,
printLazyNumberNode,
} from './printer';
import * as fs from 'fs';
import path from 'path';
import sizeOf from 'image-size';

// Editing

Expand Down Expand Up @@ -141,11 +144,22 @@ export const processingVisitors: ProcessingVisitors = {
children: [
new docx.TextRun({
text: node.code.text,
font: {
name: 'Courier New',
},
}),
],
border: {
top: {
style: BorderStyle.SINGLE,
},
right: {
style: BorderStyle.SINGLE,
},
bottom: {
style: BorderStyle.SINGLE,
},
left: {
style: BorderStyle.SINGLE,
},
},
keepNext: true,
}),
...resultCaption.result,
Expand Down Expand Up @@ -462,6 +476,7 @@ export const processingVisitors: ProcessingVisitors = {
style: 'table-cell',
}),
],
verticalAlign: VerticalAlign.CENTER,
}),
],
diagnostic: [...result.diagnostic],
Expand Down

0 comments on commit 658e82b

Please sign in to comment.