Skip to content

Commit

Permalink
Version 1.0.0-beta.0
Browse files Browse the repository at this point in the history
Changelog:
- encapsulate list generation
- add unordered list
- add double-dash auto-replace
- add Keep Next option for headings
- add TOC styles
- fixed alignment in a CodeProcessed block
- fixed line breaking in a CodeProcessing block
  • Loading branch information
Toliak committed Apr 25, 2023
1 parent 658e82b commit cca90a2
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 120 deletions.
2 changes: 1 addition & 1 deletion printers/docx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@md-to-latex/yaxm-printer-docx",
"version": "0.0.0-beta.9",
"version": "1.0.0-beta.0",
"description": "DOCX Printer for Yet Another eXtended Markdown",
"main": "dist/index.js",
"scripts": {
Expand Down
126 changes: 19 additions & 107 deletions printers/docx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { ListNode, Node, RawNode } from '@md-to-latex/converter/dist/ast/node';
import * as docx from 'docx';
import { XmlComponent } from 'docx';
import { validateDocxRootNode } from './validation';
import { getDocumentGlobalStyles } from './styles';
import {
getDocumentGlobalStyles,
getNumberingHeading,
getOrderedNumberingLevels,
getUnorderedNumberingLevels,
INumberingOptionsConfig,
} from './styles';

const processNode: DocxPrinterVisitor<NodeProcessed | RawNode | Node> =
function (printer, node) {
Expand Down Expand Up @@ -83,112 +89,18 @@ export async function printerResultToBuffer(
styles: getDocumentGlobalStyles(),
numbering: {
config: [
...printer.wordListRefStore.map<
docx.INumberingOptions['config'][0]
>(n => ({
// TODO: fully prepare the list styles for ordered and unordered list
reference: n.ref,
levels: [
{
level: 0,
format: docx.LevelFormat.RUSSIAN_UPPER,
text: '%1)',
alignment: docx.AlignmentType.START,
style: {
paragraph: {
leftTabStop: docx.convertMillimetersToTwip(
15 + 10,
),
indent: {
firstLine:
docx.convertMillimetersToTwip(15),
},
},
},
},
{
level: 1,
format: docx.LevelFormat.DECIMAL,
text: '%2)',
alignment: docx.AlignmentType.START,
style: {
paragraph: {
leftTabStop: docx.convertMillimetersToTwip(
15 + 15 + 10,
),
indent: {
firstLine:
docx.convertMillimetersToTwip(
15 + 15,
),
},
},
},
},
{
level: 2,
format: docx.LevelFormat.UPPER_ROMAN,
text: '%3)',
alignment: docx.AlignmentType.START,
style: {
paragraph: {
leftTabStop: docx.convertMillimetersToTwip(
15 + 15 + 15 + 10,
),
indent: {
firstLine:
docx.convertMillimetersToTwip(
15 + 15 + 15,
),
},
},
},
},
],
})),
{
reference: 'heading-ref',
levels: [
{
level: 0,
format: docx.LevelFormat.DECIMAL,
text: '%1',
alignment: docx.AlignmentType.START,
style: {
paragraph: {
leftTabStop:
docx.convertMillimetersToTwip(10),
},
},
},
{
level: 1,
format: docx.LevelFormat.DECIMAL,
text: '%1.%2',
alignment: docx.AlignmentType.START,
style: {
paragraph: {
leftTabStop: docx.convertMillimetersToTwip(
20 + 15,
),
},
},
},
{
level: 2,
format: docx.LevelFormat.DECIMAL,
text: '%1.%2.%3',
alignment: docx.AlignmentType.START,
style: {
paragraph: {
leftTabStop: docx.convertMillimetersToTwip(
20 + 15,
),
},
},
},
],
},
...printer.wordListRefStore.map<INumberingOptionsConfig>(n =>
n.isOrdered
? {
reference: n.ref,
levels: getOrderedNumberingLevels(),
}
: {
reference: n.ref,
levels: getUnorderedNumberingLevels(),
},
),
getNumberingHeading(),
],
},
features: {
Expand Down
7 changes: 7 additions & 0 deletions printers/docx/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export interface PrinterFunctionResult {
diagnostic: DiagnoseList;
}

export function prepareRawText(text: string): string {
text = text.replace(/ +/g, ' ');
text = text.replace(/ --/g, ' –');

return text;
}

function getOrCreateWordListRef(
printer: DocxPrinter,
node: ListNode,
Expand Down
Loading

0 comments on commit cca90a2

Please sign in to comment.