Skip to content
This repository has been archived by the owner on Feb 12, 2020. It is now read-only.

Commit

Permalink
feat: Add indent to numberings
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuweb committed Aug 18, 2019
1 parent 6bb9fe1 commit 0de3d82
Show file tree
Hide file tree
Showing 5 changed files with 1,549 additions and 1,264 deletions.
26 changes: 15 additions & 11 deletions package.json
Expand Up @@ -5,26 +5,30 @@
"repository": "https://github.com/bokuweb/bounddoc.git",
"author": "bokuweb <bokuweb12@gmail.com>",
"license": "MIT",
"resolutions": {
"**/js-yaml": "3.13.1"
},
"devDependencies": {
"@babel/core": "7.4.0",
"@storybook/html": "5.0.6",
"@babel/core": "7.5.5",
"@storybook/html": "5.1.11",
"@types/lodash-es": "4.17.3",
"@types/node": "11.12.2",
"@typescript-eslint/eslint-plugin": "1.5.0",
"babel-loader": "8.0.5",
"babel-loader": "8.0.6",
"eslint": "5.16.0",
"eslint-config-prettier": "4.1.0",
"eslint-plugin-prettier": "3.0.1",
"prettier": "1.16.4",
"typescript": "3.4.1"
"eslint-plugin-prettier": "3.1.0",
"prettier": "1.18.2",
"typescript": "3.5.3"
},
"dependencies": {
"jszip": "3.2.1",
"lodash-es": "4.17.11",
"sax": "1.2.4",
"@types/jszip": "3.1.5",
"@types/sax": "1.0.1",
"@types/lodash-es": "4.17.3"
"@types/lodash-es": "4.17.3",
"@types/sax": "1.0.1",
"jszip": "3.2.2",
"lodash": "4.17.15",
"lodash-es": "4.17.15",
"sax": "1.2.4"
},
"scripts": {
"tsc": "tsc -p tsconfig.json",
Expand Down
11 changes: 3 additions & 8 deletions src/element-reader.ts
@@ -1,6 +1,8 @@
import _ from 'lodash';
import { OOElement } from './xml/nodes';

import { createParagraphIndent } from './models/indent';

import { Styles, Style } from './style';
import { Numberings, findLevel, NumberingLevel } from './numbering';

Expand Down Expand Up @@ -242,14 +244,7 @@ function readTextRunProperty(el: OOElement, styles: Styles | null) {
// ind (Paragraph Indentation)
// This element specifies the set of indentation properties applied to the current paragraph.
function readParagraphIndent(el: OOElement) {
const indent = el.first('w:ind');
if (!indent) return null;
return {
start: indent.attributes['w:start'] || indent.attributes['w:left'],
end: indent.attributes['w:end'] || indent.attributes['w:right'],
firstLine: indent.attributes['w:firstLine'],
hanging: indent.attributes['w:hanging'],
};
return createParagraphIndent(el);
}

function toBoolean(v: string | null) {
Expand Down
16 changes: 16 additions & 0 deletions src/models/indent.ts
@@ -0,0 +1,16 @@
import { OOElement } from '../xml/nodes';

export type Indent = Record<'start' | 'end' | 'firstLine' | 'hanging', string | null>;

// ind (Paragraph Indentation)
// This element specifies the set of indentation properties applied to the current paragraph.
export function createParagraphIndent(el: OOElement): Indent | null {
const indent = el.first('w:ind');
if (!indent) return null;
return {
start: indent.attributes['w:start'] || indent.attributes['w:left'] || null,
end: indent.attributes['w:end'] || indent.attributes['w:right'] || null,
firstLine: indent.attributes['w:firstLine'] || null,
hanging: indent.attributes['w:hanging'] || null,
};
}
6 changes: 5 additions & 1 deletion src/numbering.ts
@@ -1,6 +1,7 @@
import * as zip from './zip';
import { xmlFileReader } from './xml-reader';
import { OOElement } from './xml/nodes';
import { createParagraphIndent, Indent } from './models/indent';
import { Styles } from './style';

export async function readNumberings(file: zip.Zip, path: string): Promise<Numberings | null> {
Expand Down Expand Up @@ -45,6 +46,7 @@ export type NumberingLevel = {
lvlJc: string;
pStyle: string;
level: string;
indent: Indent | null;
};

export type Levels = {
Expand Down Expand Up @@ -78,7 +80,9 @@ function readAbstractNum(el: OOElement) {
const lvlJc = el.findValueOf('w:lvlJc') || '';
const pStyle = el.findValueOf('w:pStyle') || '';
const level = el.attributes['w:ilvl'];
acc[level] = { numFmt, lvlText, pStyle, level, lvlJc };
const pPr = el.first('w:pPr');
const indent = pPr ? createParagraphIndent(pPr) : null;
acc[level] = { numFmt, lvlText, pStyle, level, lvlJc, indent };
return acc;
},
{} as Levels,
Expand Down

0 comments on commit 0de3d82

Please sign in to comment.